diff --git a/app/apis/mocks/stubs/troi/billings_hours.json b/app/apis/mocks/stubs/troi/billings_hours.json index 5738596..2a547a7 100644 --- a/app/apis/mocks/stubs/troi/billings_hours.json +++ b/app/apis/mocks/stubs/troi/billings_hours.json @@ -25,7 +25,7 @@ "CalculationPosition": { "id": 7 }, - "Date": "2024-08-03", + "Date": "will be replaced by one week ago", "Quantity": 5, "Remark": "Invoiced", "IsBillable": true, diff --git a/app/apis/mocks/stubs/troi/calendarEvents.json b/app/apis/mocks/stubs/troi/calendarEvents.json index 688a2f4..3a8c32a 100644 --- a/app/apis/mocks/stubs/troi/calendarEvents.json +++ b/app/apis/mocks/stubs/troi/calendarEvents.json @@ -27,5 +27,12 @@ "Subject": "Bezahlter Urlaub", "Type": "P", "id": "P5" + }, + { + "Start": "will be replaced by two weeks ago", + "End": "will be replaced by two weeks ago", + "Subject": "Holiday", + "Type": "H", + "id": "11" } ] diff --git a/app/apis/mocks/troiHandlers.ts b/app/apis/mocks/troiHandlers.ts index c609643..5f8628f 100644 --- a/app/apis/mocks/troiHandlers.ts +++ b/app/apis/mocks/troiHandlers.ts @@ -2,12 +2,23 @@ import md5 from "crypto-js/md5.js"; import { HttpResponse, delay, http } from "msw"; import type { ProjectTime } from "../troi/Troi.types"; +const calendarEvents = require("./stubs/troi/calendarEvents.json"); +// Replace holiday with two weeks ago +const holiday = calendarEvents.find( + (event: any) => event.Subject === "Holiday", +); +const holidayDate = new Date(Date.now() - 14 * 86400000) + .toISOString() + .split("T")[0]; +holiday.Start = `${holidayDate} 00:00:00`; +holiday.End = `${holidayDate} 23:59:59`; + const projectTimes = require("./stubs/troi/billings_hours.json"); -// Replace invoiced project time date with yesterday -const yesterday = new Date(Date.now() - 7 * 86400000) +// Replace invoiced project time date with one week ago +const oneWeekAgo = new Date(Date.now() - 7 * 86400000) .toISOString() .split("T")[0]; -projectTimes.find((pt: any) => pt.Remark === "Invoiced").Date = yesterday; +projectTimes.find((pt: any) => pt.Remark === "Invoiced").Date = oneWeekAgo; export const handlers = [ http.get( @@ -31,7 +42,11 @@ export const handlers = [ ), http.get( "https://digitalservice.troi.software/api/v2/rest/calendarEvents", - () => HttpResponse.json(require("./stubs/troi/calendarEvents.json")), + () => { + // Replace holiday with two weeks ago + + return HttpResponse.json(calendarEvents); + }, ), http.get( "https://digitalservice.troi.software/api/v2/rest/billings/hours", diff --git a/tests/e2e/projectHours.spec.ts b/tests/e2e/projectHours.spec.ts index 5e67a45..d803114 100644 --- a/tests/e2e/projectHours.spec.ts +++ b/tests/e2e/projectHours.spec.ts @@ -141,3 +141,16 @@ test.describe("invoiced projects", () => { await expect(projectLocator.getByRole("button")).not.toBeVisible(); }); }); + +test.describe("holidays", () => { + test("can't book on holidays", async ({ page }) => { + await new LoginPage(page).logIn("max.mustermann", "aSafePassword"); + // date of holiday is replaced by two weeks ago in mock so we need to go back + await page.getByTestId("btn-previous-week").click(); + await page.getByTestId("btn-previous-week").click(); + await expect(page.getByTestId("week-view")).toContainText("holiday"); + await expect( + page.locator("form").filter({ hasText: "2nd" }), + ).not.toBeVisible(); + }); +});