79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
import { expect, test } from "@playwright/test";
|
|
|
|
test("InvoiceOrdersPagination uses specific date for duplicate groups", async ({ page }) => {
|
|
// We don't need full auth for this check if we mock the right things
|
|
|
|
const mockPeriodData = {
|
|
possible_duplicates: [
|
|
{
|
|
key: "ABC1234|2026-05-12",
|
|
plate: "ABC1234",
|
|
dateKey: "2026-05-12",
|
|
testId: "ABC1234-2026-05-12",
|
|
customers: [
|
|
{
|
|
customer_number: 1001,
|
|
customer_name: "Customer A",
|
|
transactions: [{ id: 1, plate: "ABC1234", date: "2026-05-12T10:00:00Z" }],
|
|
},
|
|
{
|
|
customer_number: 1002,
|
|
customer_name: "Customer B",
|
|
transactions: [{ id: 2, plate: "ABC1234", date: "2026-05-12T11:00:00Z" }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
types: { all: [] },
|
|
statistics: { total_amount: 0, total_count: 0 },
|
|
};
|
|
|
|
await page.route("**/superuser/invoicing/period**", async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify(mockPeriodData),
|
|
});
|
|
});
|
|
|
|
let capturedOrdersUrl = null;
|
|
await page.route("**/orders**", async (route) => {
|
|
if (route.request().method() === "GET" && route.request().url().includes("orders")) {
|
|
capturedOrdersUrl = route.request().url();
|
|
}
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({ data: [], meta: { total: 0 } }),
|
|
});
|
|
});
|
|
|
|
// Mock initial session data
|
|
await page.route("**/auth/session**", async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({ data: { user: { role: "superuser" } } }),
|
|
});
|
|
});
|
|
|
|
// Navigate directly to the view
|
|
await page.goto(
|
|
"/superuser/invoices?activeTab=period&periodView=possible_duplicates&startDate=2026-05-01&endDate=2026-05-31"
|
|
);
|
|
|
|
// Wait for the duplicate group and click it
|
|
const duplicateGroup = page.getByTestId("invoicing-period-duplicate-group-ABC1234-2026-05-12");
|
|
await expect(duplicateGroup).toBeVisible();
|
|
await duplicateGroup.click();
|
|
|
|
// Wait for the orders request
|
|
await page.waitForResponse((res) => res.url().includes("/orders") && res.request().method() === "GET");
|
|
|
|
console.log("Captured Orders URL:", capturedOrdersUrl);
|
|
|
|
// Verify the date range in the URL
|
|
expect(capturedOrdersUrl).toContain("created_at-date_from=2026-05-12");
|
|
expect(capturedOrdersUrl).toContain("created_at-date_to=2026-05-12");
|
|
});
|