diff --git a/client/src/components/__tests__/AttendanceStatus.spec.ts b/client/src/components/__tests__/AttendanceStatus.spec.ts new file mode 100644 index 00000000..c9c31a72 --- /dev/null +++ b/client/src/components/__tests__/AttendanceStatus.spec.ts @@ -0,0 +1,49 @@ +import { i18nextInit, loadI18nextLocaleMessages } from "@/i18nextWrapper"; +import AttendanceStatus from "@/pages/cockpit/cockpitPage/AttendanceStatus.vue"; +import { config, mount } from "@vue/test-utils"; +import i18next from "i18next"; +import I18NextVue from "i18next-vue"; +import { expect, vi } from "vitest"; + +describe("AttendanceStatus.vue", async () => { + beforeEach(async () => { + vi.useFakeTimers(); + const date = new Date(1999, 2, 31); + vi.setSystemTime(date); + await i18nextInit(); + await loadI18nextLocaleMessages("de"); + config.global.plugins = [[I18NextVue, { i18next }]]; + }); + + test("Attendance check complete", () => { + const wrapper = mount(AttendanceStatus, { + props: { + done: true, + date: "", + }, + }); + expect(wrapper.text()).toContain("Du hast die Anwesenheit bestätigt."); + }); + + test("Attendance check future", () => { + const future = "1999-04-02T06:30:00+00:00"; + const wrapper = mount(AttendanceStatus, { + props: { + done: false, + date: future, + }, + }); + expect(wrapper.text()).toContain("Der Präsenzkurs findet in 2 Tagen statt."); + }); + + test("Attendance check now", () => { + const yesterday = "1999-03-30T06:30:00+00:00"; + const wrapper = mount(AttendanceStatus, { + props: { + done: false, + date: yesterday, + }, + }); + expect(wrapper.text()).toContain("Überprüfe jetzt die Anwesenheit."); + }); +}); diff --git a/client/src/components/__tests__/dueDateUtils.spec.ts b/client/src/components/__tests__/dueDateUtils.spec.ts new file mode 100644 index 00000000..57422294 --- /dev/null +++ b/client/src/components/__tests__/dueDateUtils.spec.ts @@ -0,0 +1,16 @@ +import { expect, vi } from "vitest"; +import { isInFuture } from "../dueDates/dueDatesUtils"; + +test("Date Utils", () => { + vi.useFakeTimers(); + const date = new Date(1999, 2, 31); + vi.setSystemTime(date); + + const today = "1999-03-31T06:30:00+00:00"; + const yesterday = "1999-03-30T06:30:00+00:00"; + const tomorrow = "1999-04-01T06:30:00+00:00"; + + expect(isInFuture(yesterday)).toBeFalsy(); + expect(isInFuture(today)).toBeFalsy(); + expect(isInFuture(tomorrow)).toBeTruthy(); +});