Files
pleno-vue/tests/unit/self-serve-studio-vehicle-type-scope.spec.js
T
Jeppe Bundgaard d354ce7737 Enhance self-serve functionality with dynamic images, gate handling, and machine-scoped vehicle type filtering:
- Added dynamic image previews with query parameter handling and error recovery in `SelfServeTryModal.vue`.
- Introduced outside gate controls (`Entrance` and `Exit`) in `SelfServeMachineRelayControls.vue` with corresponding command handling logic.
- Enhanced vehicle type scoping logic in `SelfServeTasksPagination.vue` and `SelfServeConditionsPagination.vue` to ensure machine-type filtering consistency.
- Updated related unit tests to verify new dynamic image logic, gate controls, and scoping behaviors.
2026-03-26 14:13:15 +01:00

38 lines
2.4 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 studio vehicle type scope", () => {
it("adds a vehicle-type select bound to product query scope", () => {
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
expect(studioSource).toContain("const scopedProductId = computed(() => parseScopedProduct(route.query.product));");
expect(studioSource).toContain("const scopedProductModel = computed({");
expect(studioSource).toContain("delete nextQuery.product;");
expect(studioSource).toContain("data-testid=\"self-serve-studio-vehicle-type-select\"");
expect(studioSource).toContain("<option :value=\"null\">All vehicle types</option>");
});
it("applies product scope filtering and defaults for new records", () => {
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
expect(studioSource).toContain("const scopedQuestions = computed(() => questions.value.filter((entry) => matchesScopedProduct(entry)));");
expect(studioSource).toContain("const scopedConditions = computed(() => conditions.value.filter((entry) => matchesScopedProduct(entry)));");
expect(studioSource).toContain("const scopedTasks = computed(() => tasks.value.filter((entry) => matchesScopedProduct(entry)));");
expect(studioSource).toContain("const machineTypeId = parseNullableInt(item.machine_type_id);");
expect(studioSource).toContain("return machineTypeId === scopedProductId.value;");
expect(studioSource).not.toContain("if (parseNullableInt(item.machine_type_id)) {\n return true;\n }\n const product = parseIntOrZero(item.product);");
expect(studioSource).toContain("product: scopedProductId.value || 0,");
});
it("sorts scoped question and task source lists by order priority", () => {
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
expect(studioSource).toContain("const compareByOrderPriority = (left, right) => {");
expect(studioSource).toContain(".sort(compareByOrderPriority);");
expect(studioSource).toContain("questions.value = [...questions.value].sort(compareByOrderPriority);");
});
});