diff --git a/frontend/src/components/home/cards/SubjectsCard.vue b/frontend/src/components/home/cards/SubjectsCard.vue index 4de370a5..a70af5ae 100644 --- a/frontend/src/components/home/cards/SubjectsCard.vue +++ b/frontend/src/components/home/cards/SubjectsCard.vue @@ -1,13 +1,8 @@ @@ -15,10 +10,21 @@ import HomeScreenCard from "@/components/home/cards/HomeScreenCard.vue"; import HomeScreenSkeletonCard from "@/components/home/cards/HomeScreenSkeletonCard.vue"; import SubjectItem from "@/components/home/listcontent/SubjectItem.vue"; +import useAcademicYear from "@/composables/useAcademicYear"; import { useSubjectsQuery } from "@/queries/Subject"; +import { computed } from "vue"; const { data: subjects, isLoading: isSubjectsLoading, isError: isSubjectsError, } = useSubjectsQuery(); + +const academicYear = useAcademicYear(); + +const filteredSubjects = computed(() => { + if (!subjects.value) return []; + return [...subjects.value!.as_student, ...subjects.value!.as_instructor].filter( + (subject) => subject.academic_year === academicYear + ); +}); diff --git a/frontend/tests/components/home/cards/SubjectsCard.spec.ts b/frontend/tests/components/home/cards/SubjectsCard.spec.ts index df505f72..1c966b0a 100644 --- a/frontend/tests/components/home/cards/SubjectsCard.spec.ts +++ b/frontend/tests/components/home/cards/SubjectsCard.spec.ts @@ -3,8 +3,10 @@ import {expect, describe, it, vi} from "vitest"; import SubjectsCard from "@/components/home/cards/SubjectsCard.vue" import {ref} from "vue"; +const academicYear = 23; + const testSubjectsQuery = { - data: ref({as_student: [{id: 1}], as_instructor: []}), + data: ref({as_student: [{id: 1, academic_year: academicYear}], as_instructor: []}), isLoading: ref(true), isError: ref(true), setLoading(value){ @@ -25,6 +27,10 @@ vi.mock("@/components/home/listcontent/SubjectItem.vue", () => ({ } })) +vi.mock("@/composables/useAcademicYear", () => ({ + default: vi.fn(() => academicYear) +})) + describe("SubjectsCard", () => { const wrapper = mount(SubjectsCard, {}) it("render if loading", () => {