- 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.
116 lines
2.9 KiB
JavaScript
116 lines
2.9 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
buildOutsideHoursBreakdownText,
|
|
buildOutsideHoursTrendChartState,
|
|
buildOutsideHoursWarningText,
|
|
normalizeOutsideHours,
|
|
} from "@/views/dashboards/departmentDashboard/modules/daily-report/outsideHours.js";
|
|
|
|
const t = (key, values = {}) => {
|
|
if (key === "admin.daily_report.reports.night_washes.warning_missing_opening_hours") {
|
|
return `Missing opening hours: ${values.departments}`;
|
|
}
|
|
|
|
return key;
|
|
};
|
|
|
|
describe("department outside-hours helpers", () => {
|
|
it("normalizes totals, breakdowns, and diagnostics from overview metrics", () => {
|
|
expect(
|
|
normalizeOutsideHours({
|
|
value: 5,
|
|
by_source: {
|
|
orders: "2",
|
|
xlvask: 1,
|
|
selfserve: "2",
|
|
},
|
|
has_missing_opening_hours: true,
|
|
missing_department_ids: ["4", 7, 0],
|
|
})
|
|
).toEqual({
|
|
total: 5,
|
|
by_source: {
|
|
orders: 2,
|
|
xlvask: 1,
|
|
selfserve: 2,
|
|
},
|
|
has_missing_opening_hours: true,
|
|
missing_department_ids: [4, 7],
|
|
});
|
|
});
|
|
|
|
it("builds a stable breakdown and warning string", () => {
|
|
const outsideHours = {
|
|
total: 3,
|
|
by_source: {
|
|
orders: 1,
|
|
xlvask: 1,
|
|
selfserve: 1,
|
|
},
|
|
has_missing_opening_hours: true,
|
|
missing_department_ids: [2, 4],
|
|
};
|
|
|
|
expect(buildOutsideHoursBreakdownText(outsideHours, t)).toBe(
|
|
"admin.daily_report.reports.night_washes.sources.orders: 1 | admin.daily_report.reports.night_washes.sources.xlvask: 1 | admin.daily_report.reports.night_washes.sources.selfserve: 1"
|
|
);
|
|
|
|
expect(
|
|
buildOutsideHoursWarningText(
|
|
outsideHours,
|
|
[
|
|
{ id: 1, name: "North" },
|
|
{ id: 2, name: "South" },
|
|
{ id: 4, name: "West" },
|
|
],
|
|
t
|
|
)
|
|
).toBe("Missing opening hours: South, West");
|
|
});
|
|
|
|
it("transforms trend payloads into stacked chart series", () => {
|
|
expect(
|
|
buildOutsideHoursTrendChartState(
|
|
{
|
|
points: [
|
|
{
|
|
date: "2026-03-23",
|
|
by_source: {
|
|
orders: 1,
|
|
xlvask: 0,
|
|
selfserve: 1,
|
|
},
|
|
},
|
|
{
|
|
date: "2026-03-24",
|
|
by_source: {
|
|
orders: 0,
|
|
xlvask: 2,
|
|
selfserve: 1,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
t
|
|
)
|
|
).toEqual({
|
|
categories: ["2026-03-23", "2026-03-24"],
|
|
series: [
|
|
{
|
|
name: "admin.daily_report.reports.night_washes.sources.orders",
|
|
data: [1, 0],
|
|
},
|
|
{
|
|
name: "admin.daily_report.reports.night_washes.sources.xlvask",
|
|
data: [0, 2],
|
|
},
|
|
{
|
|
name: "admin.daily_report.reports.night_washes.sources.selfserve",
|
|
data: [1, 1],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|