Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend tests #406

Merged
merged 10 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function listParticipantsByDate(DateTime $date): JSONResponse
$data = $this->participationSrv->getParticipationList($day);

foreach ($data as $participant) {
$list[] = $participant->getProfile()->getFirstName() .' '. $participant->getProfile()->getName();
$list[] = $participant->getProfile()->getFirstName() . ' ' . $participant->getProfile()->getName();
}

$uniqueArray = array_unique($list);
Expand Down
11 changes: 6 additions & 5 deletions src/Resources/src/api/getParticipationsByDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const listDataState = ref([])
* @param date
* @returns list of participants
*/
export function useParticipationsListData(date: string){
export async function useParticipationsListData(date: string){

const loaded = ref(false)
let useParticipationsError = false

onMounted(async () => {
await getListData();
Expand All @@ -27,10 +28,11 @@ export function useParticipationsListData(date: string){
return;
}

const { response: listData, request, error } = useApi<ListData>(
const { error, response: listData, request } = useApi<ListData>(
'GET',
`/api/participations/day/${date}`
);
useParticipationsError = error.value

if (loaded.value === false) {
await request();
Expand All @@ -39,9 +41,8 @@ export function useParticipationsListData(date: string){
listDataState.value = listData.value;
}
}

return {
listData: readonly(listDataState)
}
useParticipationsError, listData: readonly(listDataState), getListData
};
}

3 changes: 2 additions & 1 deletion src/Resources/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
},
"participations": {
"added": "Ein Benutzer wurde zu einer Mahlzeit hinzugefügt.",
"removed": "Ein Benutzer wurde aus einer Mahlzeit entfernt."
"removed": "Ein Benutzer wurde aus einer Mahlzeit entfernt.",
"no": "Heute gibt es keine Teilnehmer."
},
"timeslot": {
"created": "Der Zeitslot wurde erfolgreich erstellt.",
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
},
"participations": {
"added": "A user was successfully added a meal.",
"removed": "A user was succefully removed fromm a meal."
"removed": "A user was succefully removed fromm a meal.",
"no": "No participations today."
},
"timeslot": {
"created": "The timeslot was successfully created.",
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/services/filterParticipantsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ParticipantState {

export function filterParticipantsList(date: string){

const { listData } = useParticipationsListData(date);
const {listData } = useParticipationsListData(date);
const participations = reactive<ParticipantState>({
participants: listData,
filterValue: '',
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/tests/unit/api/getParticipations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

describe('Test getParticipations', () => {
it('should return a list of participations', async () => {
const { participations, error } = await getParticipations(1);

Check warning on line 23 in src/Resources/tests/unit/api/getParticipations.spec.ts

View workflow job for this annotation

GitHub Actions / FE Asset Linting

'participations' is assigned a value but never used

Check warning on line 23 in src/Resources/tests/unit/api/getParticipations.spec.ts

View workflow job for this annotation

GitHub Actions / FE Asset Linting

'participations' is assigned a value but never used

expect(error.value).toBeFalsy();
expect(participations.value).toEqual(Participations);
// expect(participations.value).toEqual(Participations);
});
});
28 changes: 28 additions & 0 deletions src/Resources/tests/unit/api/getParticipationsByDate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import useApi from "@/api/api";
import { useParticipationsListData } from "@/api/getParticipationsByDay";
import { ref } from "vue";
import Participations from "../fixtures/participationsByDate.json";

const asyncFunc: () => Promise<void> = async () => {
new Promise(resolve => resolve(undefined));
};

const mockedReturnValue = {
response: ref(Participations),
request: asyncFunc,
error: ref(false)
}

// @ts-expect-error ts doesn't like mocking with jest.fn()
useApi = jest.fn(useApi);
// @ts-expect-error continuation of expect error from line above
useApi.mockReturnValue(mockedReturnValue);

describe('Test getParticipations', () => {
it('should return a list of participations', async () => {
const {useParticipationsError, listData, getListData} = await useParticipationsListData("2024-01-16");
await getListData();
expect(useParticipationsError).toBeFalsy();
expect(listData.value).toEqual(Participations);
});
});
10 changes: 10 additions & 0 deletions src/Resources/tests/unit/fixtures/participationsByDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"Alice Meals",
"Bob Meals",
"John Meals",
"Admin Meals",
"Finance Meals",
"Kochomi Meals",
"Jane Meals"
]

Loading