- Introduced task order priority, dynamic image thumb position, and improved task gate type handling in the self-serve studio. - Enhanced task payload normalization with nullable fields and parameter verification. - Updated UI with order priority controls, dynamic images configuration, and machine type-specific scoping options. - Added and refined unit tests for task sorting, form controls, and validation rules.
97 lines
5.9 KiB
JavaScript
97 lines
5.9 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 task scope", () => {
|
|
it("renders task selectors for lane and vehicle", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("v-model=\"taskForm.lane\"");
|
|
expect(studioSource).toContain("v-model=\"taskForm.product\"");
|
|
expect(studioSource).toContain("Select lane");
|
|
expect(studioSource).toContain("Select vehicle type");
|
|
expect(studioSource).toContain("v-for=\"entry in lanes\"");
|
|
});
|
|
|
|
it("keeps department and lane visible for machine-type task scope", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("v-if=\"taskForm.scope_mode === 'machine_type'\" class=\"field\"");
|
|
expect(studioSource).toContain("<label class=\"label\">Department</label>");
|
|
expect(studioSource).toContain("<select v-model=\"taskForm.lane\">");
|
|
expect(studioSource).toContain("<template v-if=\"taskForm.scope_mode === 'legacy'\">");
|
|
expect(studioSource).toContain("<label class=\"label\">Vehicle Type</label>");
|
|
});
|
|
|
|
it("uses primary vehicle type product selection for machine scope", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("const machineScopePrimaryVehicleTypeOptions = computed(() => {");
|
|
expect(studioSource).toContain("Primary Vehicle Type Product ID");
|
|
expect(studioSource).toContain("v-for=\"entry in machineScopePrimaryVehicleTypeOptions\"");
|
|
expect(studioSource).toContain("machineScopePrimaryVehicleTypeProductId");
|
|
expect(studioSource).toContain("product: taskForm.value.scope_mode === \"machine_type\"");
|
|
});
|
|
|
|
it("defaults new task modal to legacy scope so department and lane are immediately visible", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("scope_mode: \"legacy\"");
|
|
expect(studioSource).toContain("machine_type_id: scopedProductId.value || 0");
|
|
});
|
|
|
|
it("guards task submission for machine-type and legacy scope requirements", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("Task name is required.");
|
|
expect(studioSource).toContain("Task description is required.");
|
|
expect(studioSource).toContain("Primary vehicle type product id is required for this scope.");
|
|
expect(studioSource).toContain("Department is required for Department/Lane/Vehicle scope.");
|
|
expect(studioSource).toContain("Lane is required for Department/Lane/Vehicle scope.");
|
|
expect(studioSource).toContain("Vehicle type is required for Department/Lane/Vehicle scope.");
|
|
expect(studioSource).toContain("if (payload.lane <= 0)");
|
|
expect(studioSource).toContain("if (payload.product <= 0)");
|
|
});
|
|
|
|
it("requires gate reference for non-ALWAYS gate types", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("if (payload.gate_type !== \"ALWAYS\")");
|
|
expect(studioSource).toContain("if (!payload.gate_ref_id)");
|
|
expect(studioSource).toContain("Gate reference is required for selected gate type.");
|
|
expect(studioSource).toContain("payload.condition_id = payload.gate_type === \"CONDITION\" ? payload.gate_ref_id : null;");
|
|
});
|
|
|
|
it("includes all task payload parameters in saveTask submission", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("const payload = {");
|
|
expect(studioSource).toContain("task: String(taskForm.value.task || \"\").trim()");
|
|
expect(studioSource).toContain("description: String(taskForm.value.description || \"\").trim()");
|
|
expect(studioSource).toContain("order_priority: parseIntOrZero(taskForm.value.order_priority)");
|
|
expect(studioSource).toContain("services: normalizeTaskServices(taskForm.value.services)");
|
|
expect(studioSource).toContain("buttons: normalizeTaskButtons(taskForm.value.buttons)");
|
|
expect(studioSource).toContain("dynamic_images_vehicle_type: parseNullableInt(taskForm.value.dynamic_images_vehicle_type)");
|
|
expect(studioSource).toContain("gate_type: gateType");
|
|
expect(studioSource).toContain("gate_ref_id: null");
|
|
expect(studioSource).toContain("condition_id: null");
|
|
expect(studioSource).toContain("machine_type_id: taskForm.value.scope_mode === \"machine_type\"");
|
|
expect(studioSource).toContain("const resolvedDepartmentId = parseIntOrZero(taskForm.value.department || departmentId.value);");
|
|
expect(studioSource).toContain("const resolvedLaneId = parseIntOrZero(taskForm.value.lane);");
|
|
expect(studioSource).toContain("department: resolvedDepartmentId");
|
|
expect(studioSource).toContain("lane: resolvedLaneId");
|
|
expect(studioSource).toContain("product: taskForm.value.scope_mode === \"machine_type\"");
|
|
});
|
|
|
|
it("renders task controls for order priority and dynamic images vehicle type", () => {
|
|
const studioSource = readSource("src/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeStudio.vue");
|
|
|
|
expect(studioSource).toContain("<label class=\"label\">Order Priority</label>");
|
|
expect(studioSource).toContain("v-model=\"taskForm.order_priority\"");
|
|
expect(studioSource).toContain("<label class=\"label\">Dynamic Images Thumb Position</label>");
|
|
expect(studioSource).toContain("v-model=\"taskForm.dynamic_images_vehicle_type\"");
|
|
});
|
|
});
|