From a728ede95d30989f9512d27304097f3f3bfef225 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Fri, 17 May 2024 13:13:01 +0200 Subject: [PATCH] Fix: frontend tests --- frontend/src/queries/Submission.ts | 9 ++++----- frontend/tests/views/ProjectView.spec.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/frontend/src/queries/Submission.ts b/frontend/src/queries/Submission.ts index 69ba066d..15aeb63a 100644 --- a/frontend/src/queries/Submission.ts +++ b/frontend/src/queries/Submission.ts @@ -21,12 +21,12 @@ function SUBMISSIONS_QUERY_KEY(groupId: number): (string | number)[] { return ["submissions", "group", groupId]; } -function PROJECT_SUBMISSIONS_QUERY_KEY(projectId: number): (string | number)[] { - return ["submissions", "project", projectId]; +function USER_PROJECT_SUBMISSIONS_QUERY_KEY(projectId: number): (string | number)[] { + return ["submissions", "project", "user", projectId]; } function PROJECT_SUBMISSIONS_QUERY_KEY(projectId: number): (string | number)[] { - return ["submissions_project", projectId]; + return ["submissions", "project", projectId]; } function FILES_QUERY_KEY(submissionId: number): (string | number)[] { @@ -68,7 +68,7 @@ export function useUserProjectSubmissionsQuery( ): UseQueryReturnType { const { data: group } = useProjectGroupQuery(projectId); return useQuery({ - queryKey: computed(() => PROJECT_SUBMISSIONS_QUERY_KEY(toValue(projectId)!)), + queryKey: computed(() => USER_PROJECT_SUBMISSIONS_QUERY_KEY(toValue(projectId)!)), queryFn: async () => { // HACK: Without this null-check, queries where there is no group will take a long time to resolve // also, this should be `!group.value`, but javascript... @@ -79,7 +79,6 @@ export function useUserProjectSubmissionsQuery( }); } - /** * Query composable for fetching all latest submissions of each group from a project. */ diff --git a/frontend/tests/views/ProjectView.spec.ts b/frontend/tests/views/ProjectView.spec.ts index 4f1359dc..1fe901e8 100644 --- a/frontend/tests/views/ProjectView.spec.ts +++ b/frontend/tests/views/ProjectView.spec.ts @@ -55,6 +55,22 @@ const testSubjectInstructorsQuery = { } }; +const testCurrentUserQuery = { + isLoading: ref(true), + isError: ref(true), + setIsError(value){ + this.isError.value = value; + }, + setIsLoading(value){ + this.isLoading.value = value; + } +}; + + +vi.mock('@/queries/User', () => ({ + useCurrentUserQuery: vi.fn(() => testCurrentUserQuery), +})); + vi.mock('@/queries/Subject', () => ({ useSubjectQuery: vi.fn(() => testSubjectQuery), useSubjectInstructorsQuery: vi.fn(() => testSubjectInstructorsQuery) @@ -105,6 +121,8 @@ describe("ProjectView", async () => { testSubjectQuery.setIsLoading(false) testProjectGroupsQuery.setIsLoading(false) testSubjectInstructorsQuery.setIsLoading(false) + testSubjectInstructorsQuery.setIsLoading(false) + testCurrentUserQuery.setIsLoading(false) await wrapper.vm.$nextTick(); expect(wrapper.text()).toContain("Project niet teruggevonden") }) @@ -113,6 +131,7 @@ describe("ProjectView", async () => { testSubjectQuery.setIsError(false) testProjectGroupsQuery.setIsError(false) testSubjectInstructorsQuery.setIsError(false) + testCurrentUserQuery.setIsError(false) await wrapper.vm.$nextTick(); expect(wrapper.findComponent('.projectInfoComponent').exists()).toBeTruthy() expect(wrapper.findComponent('.projectSideBar').exists()).toBeTruthy()