From d9a45b0b338c820c2f955c1596b5d69f750929ec Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 17 Jun 2026 14:49:53 -0600 Subject: [PATCH] test(admin): add offline mutation queue spec (mark ready offline, sync on reconnect) --- tests/mobile-admin/offline-queue.spec.ts | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/mobile-admin/offline-queue.spec.ts diff --git a/tests/mobile-admin/offline-queue.spec.ts b/tests/mobile-admin/offline-queue.spec.ts new file mode 100644 index 0000000..caee7af --- /dev/null +++ b/tests/mobile-admin/offline-queue.spec.ts @@ -0,0 +1,39 @@ +// tests/mobile-admin/offline-queue.spec.ts +import { test, expect } from "@playwright/test"; + +test.use({ viewport: { width: 390, height: 844 } }); // iPhone 13 + +test.beforeEach(async ({ page }) => { + // Sign in as a test admin (requires the seed admin from db/seed.ts). + await page.goto("/login"); + await page.fill('input[name="email"]', "test-admin@example.com"); + await page.fill('input[name="password"]', "test-password"); + await page.click('button[type="submit"]'); + await page.waitForURL(/\/admin/); +}); + +test("marking an order ready offline queues and syncs on reconnect", async ({ page, context }) => { + // Find a "placed" order from the v2 list + await page.goto("/admin/v2/orders"); + const placedOrderLink = page.locator('a:has(span:has-text("Placed"))').first(); + await placedOrderLink.click(); + await page.waitForURL(/\/admin\/v2\/orders\/[a-f0-9-]+/); + + // Go offline + await context.setOffline(true); + + // Click "Mark Ready" + const markReady = page.locator('button:has-text("Mark Ready")'); + await expect(markReady).toBeVisible(); + await markReady.click(); + + // Optimistic UI: the page should still update (or the button should disable) + // and the StickyActionBar should show "Pending sync" + await expect(page.locator('text="Pending sync"')).toBeVisible({ timeout: 5000 }); + + // Reconnect + await context.setOffline(false); + + // Wait up to 10s for sync + await expect(page.locator('text="Pending sync"')).toBeHidden({ timeout: 10000 }); +});