154 lines
5.0 KiB
TypeScript
154 lines
5.0 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { mockApi, primeMockSession } from "./support/network.js";
|
|
|
|
test("[PAGES][User][/user/orders] handles sparse order fields without invalid collected invoice lookups", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
const consoleMessages: string[] = [];
|
|
const pageErrors: string[] = [];
|
|
const collectedInvoiceRequests: string[] = [];
|
|
|
|
page.on("console", (message) => {
|
|
if (message.type() === "warning" || message.type() === "error") {
|
|
consoleMessages.push(message.text());
|
|
}
|
|
});
|
|
|
|
page.on("pageerror", (error) => {
|
|
pageErrors.push(String(error));
|
|
});
|
|
|
|
page.on("request", (request) => {
|
|
if (request.url().includes("/collected-invoices")) {
|
|
collectedInvoiceRequests.push(request.url());
|
|
}
|
|
});
|
|
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
sessionData: {
|
|
display_name: "Demo",
|
|
permissions: ["user"],
|
|
},
|
|
pos: {
|
|
ordersById: {
|
|
54518: {
|
|
id: 54518,
|
|
customer_id: 12345,
|
|
department_id: 12,
|
|
reference: undefined,
|
|
notes: null,
|
|
po: undefined,
|
|
reg_1: "AB12345",
|
|
reg_2: "",
|
|
reg_3: "",
|
|
invoice_collection_id: undefined,
|
|
booking_id: null,
|
|
completed_at: null,
|
|
closed_at: null,
|
|
created_at: "2026-04-13 10:00:00",
|
|
include_in_invoice: null,
|
|
total_net_amount: 649,
|
|
},
|
|
54519: {
|
|
id: 54519,
|
|
customer_id: 12345,
|
|
department_id: 12,
|
|
reference: "",
|
|
notes: undefined,
|
|
po: null,
|
|
reg_1: "CD67890",
|
|
reg_2: "",
|
|
reg_3: "",
|
|
invoice_collection_id: 14,
|
|
booking_id: null,
|
|
completed_at: null,
|
|
closed_at: null,
|
|
created_at: "2026-04-13 09:00:00",
|
|
include_in_invoice: null,
|
|
total_net_amount: 399,
|
|
},
|
|
54520: {
|
|
id: 54520,
|
|
customer_id: 12345,
|
|
department_id: 12,
|
|
reference: "Normal ref",
|
|
notes: "",
|
|
po: "PO-123",
|
|
reg_1: "EF11111",
|
|
reg_2: "",
|
|
reg_3: "",
|
|
invoice_collection_id: 18,
|
|
booking_id: null,
|
|
completed_at: null,
|
|
closed_at: null,
|
|
created_at: "2026-04-13 08:00:00",
|
|
include_in_invoice: null,
|
|
total_net_amount: 249,
|
|
},
|
|
},
|
|
orderItemsByOrderId: {
|
|
54518: [],
|
|
54519: [],
|
|
54520: [],
|
|
},
|
|
economicModuleOrdersByOrderId: {
|
|
54518: { invoice_id: null, invoice_draft_id: null },
|
|
54519: { invoice_id: null, invoice_draft_id: null },
|
|
54520: { invoice_id: null, invoice_draft_id: null },
|
|
},
|
|
stripeModuleOrdersByOrderId: {
|
|
54518: {},
|
|
54519: {},
|
|
54520: {},
|
|
},
|
|
},
|
|
});
|
|
|
|
await primeMockSession(page);
|
|
await page.goto("/user/orders");
|
|
await expect(page).toHaveURL(/\/user\/orders/);
|
|
await expect(page.getByText("Historiske vaske").first()).toBeVisible();
|
|
await expect(page.locator("table.table").first().or(page.getByTestId("pos-order-list-card-54518"))).toBeVisible();
|
|
await expect(
|
|
page.getByTestId("pos-order-list-settings-54518").or(page.getByTestId("pos-order-list-card-54518"))
|
|
).toBeVisible();
|
|
await expect(
|
|
page.getByTestId("pos-order-list-settings-54520").or(page.getByTestId("pos-order-list-card-54520"))
|
|
).toBeVisible();
|
|
|
|
if (/desktop/i.test(testInfo.project.name)) {
|
|
const referenceCell = page.getByTestId("pos-order-reference-54520");
|
|
await expect(referenceCell).toBeVisible();
|
|
|
|
const metadataFontSizes = await referenceCell.evaluate((cell) => {
|
|
const row = cell.closest("tr");
|
|
const readFontSize = (selector: string) => {
|
|
const element = selector.startsWith("[") ? document.querySelector(selector) : row?.querySelector(selector);
|
|
|
|
return element ? window.getComputedStyle(element).fontSize : null;
|
|
};
|
|
|
|
return {
|
|
reference: window.getComputedStyle(cell).fontSize,
|
|
notes: readFontSize('[data-testid="pos-order-notes-54520"]'),
|
|
po: readFontSize('[data-testid="pos-order-po-54520"]'),
|
|
date: readFontSize(".pos-orders-table-date-cell"),
|
|
amount: readFontSize(".pos-orders-table-amount-cell"),
|
|
};
|
|
});
|
|
|
|
expect(metadataFontSizes.reference).toBe(metadataFontSizes.date);
|
|
expect(metadataFontSizes.notes).toBe(metadataFontSizes.date);
|
|
expect(metadataFontSizes.po).toBe(metadataFontSizes.date);
|
|
expect(metadataFontSizes.reference).toBe(metadataFontSizes.amount);
|
|
}
|
|
|
|
const combinedMessages = [...consoleMessages, ...pageErrors].join("\n");
|
|
|
|
expect(combinedMessages).not.toContain("Cannot read properties of undefined (reading 'length')");
|
|
expect(combinedMessages).not.toContain("Cannot read properties of undefined (reading 'orders')");
|
|
expect(combinedMessages).not.toContain("Unhandled error during execution of component update");
|
|
expect(collectedInvoiceRequests.some((url) => url.includes("/collected-invoices?id=undefined"))).toBe(false);
|
|
});
|