Skip to content

Commit

Permalink
Fix: frontend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xerbalind committed May 18, 2024
1 parent b719a11 commit a728ede
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frontend/src/queries/Submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)[] {
Expand Down Expand Up @@ -68,7 +68,7 @@ export function useUserProjectSubmissionsQuery(
): UseQueryReturnType<Submission[], Error> {
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...
Expand All @@ -79,7 +79,6 @@ export function useUserProjectSubmissionsQuery(
});
}


/**
* Query composable for fetching all latest submissions of each group from a project.
*/
Expand Down
19 changes: 19 additions & 0 deletions frontend/tests/views/ProjectView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
})
Expand All @@ -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()
Expand Down

0 comments on commit a728ede

Please sign in to comment.