Files
pleno-vue/tests/unit/system-search-department-goal-support.spec.js
T
Jeppe Bundgaard b39b458f4f Add .prettierrc.json and refactor test files for improved formatting consistency:
- Introduced `.prettierrc.json` to enforce consistent code formatting across the project.
- Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
2026-04-13 09:13:27 +02:00

97 lines
2.5 KiB
JavaScript

import { describe, expect, it } from "vitest";
import {
buildDepartmentGoalOverview,
extractDepartmentGoalId,
} from "@/components/viewport/page/headers/menu/systemSearchDepartmentGoalSupport.ts";
describe("system search department goal support", () => {
it("extracts goal ids from payload before falling back to the row id", () => {
expect(extractDepartmentGoalId({ id: 1 }, "9")).toBe("1");
expect(extractDepartmentGoalId({ goal_id: "7" }, "9")).toBe("7");
expect(extractDepartmentGoalId(null, "9")).toBe("9");
});
it("builds a compact department goal overview from fetched progress data", () => {
const overview = buildDepartmentGoalOverview({
id: "1",
departments: [1, 2],
criteria: {
end: "2026-01-31T00:00:00+01:00",
type: "PRODUCT",
start: "2026-01-01T00:00:00+01:00",
users: [12345679],
target: 100,
products: [1],
departments: [1, 2, 3],
},
progress: {
to_date: {
count: 42,
target: 100,
},
},
});
expect(overview).toEqual({
goalId: "1",
type: "PRODUCT",
count: 42,
target: 100,
percentage: 42,
start: "2026-01-01T00:00:00+01:00",
end: "2026-01-31T00:00:00+01:00",
departmentCount: 3,
userCount: 1,
productCount: 1,
progressKey: "to_date",
hasProgressData: true,
});
});
it("falls back to criteria target and the best available progress frame", () => {
const overview = buildDepartmentGoalOverview({
id: 11,
criteria: {
type: "REVENUE",
target: 2500,
},
progress: {
this_week: {
count: "1000",
},
},
});
expect(overview?.goalId).toBe("11");
expect(overview?.progressKey).toBe("this_week");
expect(overview?.target).toBe(2500);
expect(overview?.percentage).toBe(40);
expect(overview?.hasProgressData).toBe(true);
});
it("prioritizes OpenAPI progress keys over legacy aliases when both exist", () => {
const overview = buildDepartmentGoalOverview({
id: 24,
criteria: {
type: "VISITS",
target: 120,
},
progress: {
this_week: {
count: 99,
target: 120,
},
week: {
count: 45,
target: 90,
},
},
});
expect(overview?.progressKey).toBe("week");
expect(overview?.count).toBe(45);
expect(overview?.target).toBe(90);
expect(overview?.percentage).toBe(50);
});
});