Files
pleno-vue/tests/unit/pos-route-state.spec.js
T
Jeppe Bundgaard c437c89cfa Add release management enhancements, runtime-aware frontend updates, and extensive test coverage
- Implement release update detection, asset preloading, and frontend version management.
- Add unit and E2E tests for release update workflows, widget behavior, and failure scenarios.
- Introduce new services for handling release ping, error reporting, and update installation workflows.
- Extend i18n for release-related components and error report localization.
- Add `ReleaseFrontendVersionBadge.vue` and related styles to display frontend update statuses.
2026-05-27 13:23:22 +02:00

165 lines
5.4 KiB
JavaScript

import { describe, expect, it, vi } from "vitest";
import {
applyPosRouteSearch,
parsePosRouteSearch,
} from "@/views/dashboards/departmentDashboard/modules/Pos/posRouteState.js";
describe("parsePosRouteSearch", () => {
it("extracts valid positive integers from search params", () => {
expect(parsePosRouteSearch("?id=9201&customer_id=12345&step=2")).toEqual({
orderId: 9201,
customerId: 12345,
step: 2,
});
});
it("ignores invalid or missing params", () => {
expect(parsePosRouteSearch("?id=abc&customer_id=0&step=-1")).toEqual({
orderId: null,
customerId: null,
step: null,
});
expect(parsePosRouteSearch("")).toEqual({
orderId: null,
customerId: null,
step: null,
});
});
it("does not treat customer_id as id", () => {
expect(parsePosRouteSearch("?customer_id=12345&step=1")).toEqual({
orderId: null,
customerId: 12345,
step: 1,
});
});
});
describe("applyPosRouteSearch", () => {
it("loads order data only when a valid order id is present", () => {
const handlers = {
setOrderId: vi.fn(),
loadOrderItems: vi.fn(),
setStep: vi.fn(),
searchAndSelectCustomer: vi.fn(),
clearActivePosOrderContext: vi.fn(),
resetMobilePos: vi.fn(),
};
const result = applyPosRouteSearch("?id=9201&customer_id=12345&step=2", handlers);
expect(result).toEqual({
orderId: 9201,
customerId: 12345,
step: 2,
});
expect(handlers.setOrderId).toHaveBeenCalledWith(9201);
expect(handlers.loadOrderItems).toHaveBeenCalledTimes(1);
expect(handlers.setStep).toHaveBeenCalledWith(2);
expect(handlers.searchAndSelectCustomer).toHaveBeenCalledWith(12345, { forceRefresh: true });
expect(handlers.clearActivePosOrderContext).not.toHaveBeenCalled();
expect(handlers.resetMobilePos).not.toHaveBeenCalled();
});
it("resets to a fresh step 1 route when only customer_id exists", () => {
const handlers = {
setOrderId: vi.fn(),
loadOrderItems: vi.fn(),
setStep: vi.fn(),
searchAndSelectCustomer: vi.fn(),
clearActivePosOrderContext: vi.fn(() => false),
resetMobilePos: vi.fn(),
};
const result = applyPosRouteSearch("?customer_id=12345&step=1", handlers);
expect(result).toEqual({
orderId: null,
customerId: 12345,
step: 1,
});
expect(handlers.setOrderId).not.toHaveBeenCalled();
expect(handlers.loadOrderItems).not.toHaveBeenCalled();
expect(handlers.setStep).toHaveBeenCalledWith(1);
expect(handlers.searchAndSelectCustomer).not.toHaveBeenCalled();
expect(handlers.clearActivePosOrderContext).toHaveBeenCalledWith({ clearStep: true });
expect(handlers.resetMobilePos).toHaveBeenCalledTimes(1);
});
it("treats explicit step 1 as fresh even when stale order params exist", () => {
const handlers = {
setOrderId: vi.fn(),
loadOrderItems: vi.fn(),
setStep: vi.fn(),
searchAndSelectCustomer: vi.fn(),
clearActivePosOrderContext: vi.fn(() => false),
resetMobilePos: vi.fn(),
};
const result = applyPosRouteSearch("?id=9201&customer_id=12345&step=1", handlers);
expect(result).toEqual({
orderId: 9201,
customerId: 12345,
step: 1,
});
expect(handlers.setOrderId).not.toHaveBeenCalled();
expect(handlers.loadOrderItems).not.toHaveBeenCalled();
expect(handlers.searchAndSelectCustomer).not.toHaveBeenCalled();
expect(handlers.setStep).toHaveBeenCalledWith(1);
expect(handlers.clearActivePosOrderContext).toHaveBeenCalledWith({ clearStep: true });
expect(handlers.resetMobilePos).toHaveBeenCalledTimes(1);
});
it("resets invalid later-step routes that do not include an order id", () => {
const handlers = {
setOrderId: vi.fn(),
loadOrderItems: vi.fn(),
setStep: vi.fn(),
searchAndSelectCustomer: vi.fn(),
clearActivePosOrderContext: vi.fn(() => false),
resetMobilePos: vi.fn(),
};
const result = applyPosRouteSearch("?step=2&customer_id=12345", handlers);
expect(result).toEqual({
orderId: null,
customerId: 12345,
step: 2,
});
expect(handlers.setOrderId).not.toHaveBeenCalled();
expect(handlers.loadOrderItems).not.toHaveBeenCalled();
expect(handlers.searchAndSelectCustomer).not.toHaveBeenCalled();
expect(handlers.setStep).toHaveBeenCalledWith(1);
expect(handlers.clearActivePosOrderContext).toHaveBeenCalledWith({ clearStep: true });
expect(handlers.resetMobilePos).toHaveBeenCalledTimes(1);
});
it("keeps step 3 route hydration when a valid order id is present", () => {
const handlers = {
setOrderId: vi.fn(),
loadOrderItems: vi.fn(),
setStep: vi.fn(),
searchAndSelectCustomer: vi.fn(),
clearActivePosOrderContext: vi.fn(),
resetMobilePos: vi.fn(),
};
const result = applyPosRouteSearch("?id=9201&customer_id=12345&step=3", handlers);
expect(result).toEqual({
orderId: 9201,
customerId: 12345,
step: 3,
});
expect(handlers.setOrderId).toHaveBeenCalledWith(9201);
expect(handlers.loadOrderItems).toHaveBeenCalledTimes(1);
expect(handlers.setStep).toHaveBeenCalledWith(3);
expect(handlers.searchAndSelectCustomer).toHaveBeenCalledWith(12345, { forceRefresh: true });
expect(handlers.clearActivePosOrderContext).not.toHaveBeenCalled();
expect(handlers.resetMobilePos).not.toHaveBeenCalled();
});
});