Files
pleno-vue/tests/unit/department-opening-hours-route-sync.spec.js
T
Jeppe B 5204536f92 Fix self-serve settings state and contract (#229)
Ensure department-scoped self-serve settings load and save safely across route transitions, document the API contract, and cover stale in-flight state.
2026-07-28 18:34:35 +02:00

38 lines
1.5 KiB
JavaScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const source = readFileSync(
join(
process.cwd(),
"src/views/dashboards/departmentDashboard/modules/time-bookings/DepartmentTimeBookingsOpeningHours.vue"
),
"utf8"
);
describe("Department opening-hours route synchronization", () => {
it("clears and reloads opening hours when the selected department changes", () => {
expect(source).toContain("departmentId.value, isSuperuserDepartmentRoute.value");
expect(source).toContain("{ immediate: true }");
expect(source).toContain("opening_hours.value = null");
expect(source).toContain("department: selectedDepartmentId");
});
it("ignores a slower response from the previously selected department", () => {
expect(source).toContain("const requestId = ++openingHoursRequest");
expect(source).toContain("requestId !== openingHoursRequest");
});
it("initializes the selected superuser department for direct and reloaded routes", () => {
expect(source).toContain("setDepartment as setSelectedDepartment");
expect(source).toContain("if (isSuperuserRoute)");
expect(source).toContain("setSelectedDepartment(selectedDepartmentId)");
});
it("initializes superuser state when only the route context changes", () => {
expect(source).toContain("isSuperuserDepartmentRoute.value");
expect(source).toContain("[selectedDepartmentId, isSuperuserRoute]");
expect(source).toContain("selectedDepartmentId !== previousDepartmentId");
});
});