|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +// The strip is the way back from staging, so it must stay usable on every |
| 4 | +// route, including the landing page with its fixed navigation bar. |
| 5 | +for (const path of ['/', '/login']) { |
| 6 | + const landing = path === '/'; |
| 7 | + test(`the staging strip returns to production from ${path}`, async ({ page }) => { |
| 8 | + // Never reach a real Supabase project from this test. |
| 9 | + await page.route('https://*.supabase.co/**', (route) => route.abort()); |
| 10 | + await page.addInitScript(() => { |
| 11 | + if (!sessionStorage.getItem('staging-switch-test-started')) { |
| 12 | + sessionStorage.setItem('staging-switch-test-started', '1'); |
| 13 | + localStorage.setItem('debate-supabase-env', 'staging'); |
| 14 | + } |
| 15 | + }); |
| 16 | + await page.goto(path); |
| 17 | + // The landing navigation is fixed and slides in from above. Click only once |
| 18 | + // it has arrived, so the test sees what a person sees. |
| 19 | + if (landing) { |
| 20 | + const landingNav = page.locator('nav.fixed'); |
| 21 | + await landingNav.waitFor(); |
| 22 | + await expect.poll(() => landingNav.evaluate((nav) => getComputedStyle(nav).transform)).toMatch(/^(none|matrix\(1, 0, 0, 1, 0, 0\))$/); |
| 23 | + } |
| 24 | + |
| 25 | + const strip = page.getByRole('status').filter({ hasText: 'Staging backend' }); |
| 26 | + await expect(strip).toBeVisible(); |
| 27 | + if (landing) { |
| 28 | + // The fixed navigation must sit below the strip, not underneath it. |
| 29 | + const stripBox = await strip.boundingBox(); |
| 30 | + const navBox = await page.locator('nav.fixed').boundingBox(); |
| 31 | + expect(navBox!.y).toBeGreaterThanOrEqual(stripBox!.y + stripBox!.height - 1); |
| 32 | + } |
| 33 | + await strip.getByRole('button', { name: 'Switch to Production' }).click({ timeout: 5_000 }); |
| 34 | + |
| 35 | + await expect(strip).toHaveCount(0); |
| 36 | + expect(await page.evaluate(() => localStorage.getItem('debate-supabase-env'))).toBeNull(); |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +test('switching in one tab reloads the other tabs onto the same project', async ({ context }) => { |
| 41 | + await context.route('https://*.supabase.co/**', (route) => route.abort()); |
| 42 | + await context.addInitScript(() => { |
| 43 | + if (!sessionStorage.getItem('staging-switch-test-started')) { |
| 44 | + sessionStorage.setItem('staging-switch-test-started', '1'); |
| 45 | + localStorage.setItem('debate-supabase-env', 'staging'); |
| 46 | + } |
| 47 | + }); |
| 48 | + const switching = await context.newPage(); |
| 49 | + const other = await context.newPage(); |
| 50 | + await switching.goto('/login'); |
| 51 | + await other.goto('/login'); |
| 52 | + const stripIn = (page: typeof other) => page.getByRole('status').filter({ hasText: 'Staging backend' }); |
| 53 | + await expect(stripIn(other)).toBeVisible(); |
| 54 | + |
| 55 | + await stripIn(switching).getByRole('button', { name: 'Switch to Production' }).click(); |
| 56 | + |
| 57 | + await expect(stripIn(switching)).toHaveCount(0); |
| 58 | + await expect(stripIn(other)).toHaveCount(0); |
| 59 | +}); |
0 commit comments