113 lines
6.1 KiB
JavaScript
113 lines
6.1 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const readSource = (relativePath) => readFileSync(join(process.cwd(), relativePath), "utf8");
|
|
|
|
describe("self-serve alignment", () => {
|
|
it("registers reusable machine types and lane relay/machine_type wiring", () => {
|
|
const sessionUserSource = readSource("src/components/session/token/SessionUser.vue");
|
|
const laneSource = readSource("src/components/session/token/SessionUser/Objects/DepartmentLanes.vue");
|
|
const laneAdminViewSource = readSource(
|
|
"src/views/dashboards/departmentDashboard/modules/wash-lanes/DepartmentWashLane.vue"
|
|
);
|
|
const laneSuperUserViewSource = readSource(
|
|
"src/views/dashboards/superUserDashboard/department/lanes/DepartmentLane.vue"
|
|
);
|
|
|
|
expect(sessionUserSource).toMatch(/self_serve_machine_types\s*:\s*SelfServeMachineTypes\s*,/);
|
|
expect(sessionUserSource).not.toMatch(/get\s+self_serve_machine_types\s*\(/);
|
|
expect(laneSource).toContain("relay_machine_program_picker_id:");
|
|
expect(laneSource).toContain("relay_machine_cleaner_id:");
|
|
expect(laneSource).toContain("machine_type_id:");
|
|
expect(laneSource).toContain("SessionUser.objects.self_serve_machine_types.get.all()");
|
|
expect(laneAdminViewSource).toContain(':set-machine-type-filter="lane.machine_type_id || null"');
|
|
expect(laneAdminViewSource).toContain("lane.relay_machine_program_picker_id");
|
|
expect(laneAdminViewSource).toContain("lane.relay_machine_cleaner_id");
|
|
expect(laneSuperUserViewSource).toContain("lane.relay_machine_program_picker_id");
|
|
expect(laneSuperUserViewSource).toContain("lane.relay_machine_cleaner_id");
|
|
});
|
|
|
|
it("normalizes self-serve config reads and submits merged config payloads", () => {
|
|
const configClientSource = readSource("src/components/session/token/superUser/modules/selfserve/Config.vue");
|
|
const configViewSource = readSource(
|
|
"src/views/dashboards/superUserDashboard/configuration/ConfigurationSelfServe.vue"
|
|
);
|
|
|
|
expect(configClientSource).toContain("const normalizeEntries =");
|
|
expect(configClientSource).toContain("const toConfigPayload =");
|
|
expect(configClientSource).toContain("get_config");
|
|
expect(configClientSource).toContain("set_config");
|
|
expect(configClientSource).toContain("return Config.set_config({");
|
|
expect(configViewSource).toContain("moduleConfigMap.value = response.data.config || {};");
|
|
});
|
|
|
|
it("exposes the self-serve dynamic image size selector in module config", () => {
|
|
const configClientSource = readSource("src/components/session/token/superUser/modules/selfserve/Config.vue");
|
|
const configViewSource = readSource(
|
|
"src/views/dashboards/superUserDashboard/configuration/ConfigurationSelfServe.vue"
|
|
);
|
|
|
|
expect(configClientSource).toContain("dynamic_image_size");
|
|
expect(configClientSource).toContain('return Config.set("dynamic_image_size", value);');
|
|
expect(configViewSource).toContain("ConfigurationSelect");
|
|
expect(configViewSource).toContain('ConfigurationSelectOption("Original", "original")');
|
|
expect(configViewSource).toContain('ConfigurationSelectOption("Relevant", "relevant")');
|
|
expect(configViewSource).toContain("getModuleConfigValue('dynamic_image_size') || 'original'");
|
|
expect(configViewSource).toContain("config.keys.dynamic_image_size.set");
|
|
});
|
|
|
|
it("limits condition rules to documented object types and rule types", () => {
|
|
const rulesSource = readSource("src/components/session/token/SessionUser/Objects/SelfServeConditionRules.vue");
|
|
|
|
expect(rulesSource).toContain('{ id: "question", name: "Spørgsmål" }');
|
|
expect(rulesSource).toContain('{ id: "condition", name: "Betingelse" }');
|
|
expect(rulesSource).not.toContain('{ id: "task"');
|
|
expect(rulesSource).toContain("IS_TRUE_OR_ANY_TRUE");
|
|
expect(rulesSource).not.toContain("IS_NOT_SET");
|
|
expect(rulesSource).not.toContain("IS_FALSE_OR_ANY_FALSE");
|
|
});
|
|
|
|
it("uses preview and summary endpoints as the self-serve runtime source of truth", () => {
|
|
const logicSource = readSource("src/composables/useSelfServeLogic.js");
|
|
const tryModalSource = readSource("src/components/displays/department/tables/SelfServeTryModal.vue");
|
|
const washFlowSource = readSource("src/views/dashboards/userDashboard/wash/MyWashStart.vue");
|
|
|
|
expect(logicSource).toContain("previewAllowed");
|
|
expect(logicSource).toContain("fetchWashSummary");
|
|
expect(logicSource).toContain("syncVehicleAnswer");
|
|
expect(tryModalSource).toContain("syncVehicleAnswer");
|
|
expect(tryModalSource).toContain("fetchSelfServeData");
|
|
expect(washFlowSource).toContain("syncVehicleAnswer");
|
|
expect(washFlowSource).toContain("useWashDepartments");
|
|
expect(washFlowSource).toContain("useWashProgress");
|
|
expect(washFlowSource).toContain("useWashSessionActions");
|
|
});
|
|
|
|
it("keeps the studio workspace shell and page actions wired", () => {
|
|
const studioSource = readSource(
|
|
"src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue"
|
|
);
|
|
|
|
expect(studioSource).toContain('data-testid="self-serve-studio"');
|
|
expect(studioSource).toContain('class="buttons studio-page-actions"');
|
|
expect(studioSource).toContain('data-testid="studio-fullscreen-toggle"');
|
|
expect(studioSource).toContain('@click="loadStudioGraph"');
|
|
expect(studioSource).toContain('class="studio-shell"');
|
|
expect(studioSource).toContain('class="studio-sidebar"');
|
|
expect(studioSource).toContain('class="studio-panel-button"');
|
|
expect(studioSource).toContain('class="studio-main"');
|
|
expect(studioSource).toContain(".studio-page-actions {");
|
|
expect(studioSource).toContain("justify-content: flex-end;");
|
|
expect(studioSource).toContain(".studio-shell {");
|
|
expect(studioSource).toContain("grid-template-columns: 168px minmax(620px, 1fr) minmax(300px, 340px);");
|
|
});
|
|
|
|
it("adds the machine-types admin route", () => {
|
|
const routerSource = readSource("src/router.js");
|
|
|
|
expect(routerSource).toContain("name: 'selfservemachinetypes'");
|
|
expect(routerSource).toContain("path: '/admin/:departmentId/modules/self-serve/machine-types'");
|
|
});
|
|
});
|