From 6b55c93edfcb328b1a53a9239e0da6879d0e4759 Mon Sep 17 00:00:00 2001 From: Bankim Date: Fri, 27 Nov 2026 01:32:13 +0530 Subject: [PATCH 1/2] fix(pos): respect Auto-print Bill in prepaid checkout Prepaid checkout forced the receipt print, so the system print dialog opened even with Auto-print Bill off. Co-Authored-By: Claude Sonnet 5.5 --- frontend/e2e/pos-prepaid-auto-print.spec.ts | 74 +++++++++++++++++++++ frontend/src/app/(dashboard)/pos/page.tsx | 3 +- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 frontend/e2e/pos-prepaid-auto-print.spec.ts diff --git a/frontend/e2e/pos-prepaid-auto-print.spec.ts b/frontend/e2e/pos-prepaid-auto-print.spec.ts new file mode 100644 index 000000000..f3d52f5a8 --- /dev/null +++ b/frontend/e2e/pos-prepaid-auto-print.spec.ts @@ -0,0 +1,74 @@ +import { test, expect, type Page } from '@playwright/test'; +import { E2E_BASE_URL as BASE } from './helpers/urls'; +import { E2E_PASSWORD, getE2eToken, setLanguage } from './helpers/test-auth'; + +const MANAGER_TOKEN = getE2eToken('e2e-manager', 'manager@flo.local', 'manager'); +const AUTH = { Authorization: `Bearer ${MANAGER_TOKEN}` }; + +type PrintProbe = Window & { receiptWindowOpens?: number }; + +/** Pays one prepaid cash order and returns how many receipt print windows it opened. */ +async function payPrepaidOrder(page: Page, autoPrintBill: boolean): Promise { + await page.addInitScript((enabled) => { + const stored = JSON.parse(localStorage.getItem('pos-settings') || '{"state":{},"version":6}'); + stored.state.autoPrintBill = enabled; + localStorage.setItem('pos-settings', JSON.stringify(stored)); + const probe = window as PrintProbe; + probe.receiptWindowOpens = 0; + window.open = (() => { + probe.receiptWindowOpens = (probe.receiptWindowOpens ?? 0) + 1; + return null; + }) as typeof window.open; + }, autoPrintBill); + + await page.goto(`${BASE}/auth/login`); + await page.locator('#email').fill('manager@flo.local'); + await page.locator('#password').fill(E2E_PASSWORD); + await page.locator('button[type="submit"]').click(); + await page.waitForURL('**/pos/**', { timeout: 20000 }); + await setLanguage(page, 'en'); + await page.goto(`${BASE}/pos`); + await page.getByTestId('pos-product-card').first().click(); + const addToCart = page.getByRole('button', { name: /Add to Cart/ }); + if (await addToCart.count()) await addToCart.click(); + + await page.getByRole('button', { name: 'Place Order' }).click(); + const checkout = page.getByTestId('prepaid-checkout-modal'); + await expect(checkout.getByRole('button', { name: /^Tax / })).toBeVisible(); + await checkout.getByRole('button', { name: 'Cash', exact: true }).click(); + await checkout.getByRole('button', { name: /Confirm Payment/ }).click(); + // The success state renders only after the checkout handler has awaited auto-print. + await expect(checkout.getByText('Payment recorded!', { exact: true })).toBeVisible(); + return page.evaluate(() => (window as PrintProbe).receiptWindowOpens ?? 0); +} + +test.describe('prepaid checkout receipt auto-print', () => { + let originalBusiness: Record; + + test.beforeEach(async ({ page }) => { + const response = await page.request.get(`${BASE}/api/settings/business`, { headers: AUTH }); + expect(response.ok()).toBeTruthy(); + originalBusiness = await response.json(); + const updated = await page.request.put(`${BASE}/api/settings/business`, { + headers: AUTH, + data: { ...originalBusiness, billing_type: 'prepaid' }, + }); + expect(updated.ok()).toBeTruthy(); + }); + + test.afterEach(async ({ page }) => { + const restored = await page.request.put(`${BASE}/api/settings/business`, { + headers: AUTH, + data: originalBusiness, + }); + expect(restored.ok()).toBeTruthy(); + }); + + test('does not print when Auto-print Bill is off', async ({ page }) => { + expect(await payPrepaidOrder(page, false)).toBe(0); + }); + + test('prints once when Auto-print Bill is on', async ({ page }) => { + expect(await payPrepaidOrder(page, true)).toBe(1); + }); +}); diff --git a/frontend/src/app/(dashboard)/pos/page.tsx b/frontend/src/app/(dashboard)/pos/page.tsx index 0f6df566c..3a579791c 100644 --- a/frontend/src/app/(dashboard)/pos/page.tsx +++ b/frontend/src/app/(dashboard)/pos/page.tsx @@ -2836,7 +2836,6 @@ export default function POSPage() { walletAmount: number, discount: PrepaidDiscount | null, ) => { - const isPrepaidCheckout = shouldTakePaymentNow; setSubmitting(true); const originContext = readLiveSupportContext(); const originUserId = originContext.userId; @@ -3382,7 +3381,7 @@ export default function POSPage() { await printBillForTenant( { ...paidBill, order: paidBill.order ?? bill.order ?? order }, - isPrepaidCheckout, + false, undefined, originContext, ); From 4d1ba15018686cbc69a8f2a2d9171fbe1ec114b0 Mon Sep 17 00:00:00 2001 From: Bankim Date: Fri, 27 Nov 2026 01:40:40 +0530 Subject: [PATCH 2/2] test(pos): enable Auto-print Bill where prepaid receipt print is asserted Co-Authored-By: Claude Sonnet 5.5 --- tests/pin-quick-switch.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/pin-quick-switch.test.ts b/tests/pin-quick-switch.test.ts index 8411b7435..4807d9a27 100644 --- a/tests/pin-quick-switch.test.ts +++ b/tests/pin-quick-switch.test.ts @@ -26,6 +26,7 @@ const mockPosSettingsStore = { kotLanguagePolicy: null as unknown, autoLockMinutes: 0, tablesRequired: false, + autoPrintBill: false, setLanguage(language: string) { this.language = language; }, @@ -1812,7 +1813,12 @@ async function run() { }, get: async () => ({ data: {} }), }; - await managerPrepaidModal.props.onConfirm([{ method: 'cash', amount: 120 }], 0, null); + mockPosSettingsStore.state.autoPrintBill = true; + renderPOSPage(POSPage); + tree = renderPOSPage(POSPage); + const autoPrintModal = findElement(tree, PrepaidCheckoutModalStub); + await autoPrintModal.props.onConfirm([{ method: 'cash', amount: 120 }], 0, null); + mockPosSettingsStore.state.autoPrintBill = false; assertEqualOrThrow( capturedPrintedBills.length, 1,