forked from cartsnitch/cartsnitch
09f88f0bf8
- Make mockAuthRoutes async and await all page.route() calls to prevent race conditions - Add auth route mocking to J8 unauth tests (required since VITE_MOCK_AUTH was removed) - Add auth route mocking to smoke test - Replace broken mockSessionPending with mockSessionDelayed for spinner test Co-Authored-By: Paperclip <noreply@paperclip.ing>
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { mockAuthRoutes, mockSessionDelayed } from '../fixtures';
|
|
|
|
test.describe('J8: Unauthenticated Access', () => {
|
|
test('redirects /dashboard (/) to /login when not authenticated', async ({ page }) => {
|
|
await mockAuthRoutes(page, false);
|
|
await page.goto('/');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /purchases to /login when not authenticated', async ({ page }) => {
|
|
await mockAuthRoutes(page, false);
|
|
await page.goto('/purchases');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /products to /login when not authenticated', async ({ page }) => {
|
|
await mockAuthRoutes(page, false);
|
|
await page.goto('/products');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('redirects /coupons to /login when not authenticated', async ({ page }) => {
|
|
await mockAuthRoutes(page, false);
|
|
await page.goto('/coupons');
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.getByRole('heading', { name: /cartsnitch/i })).toBeVisible();
|
|
});
|
|
|
|
test('shows loading spinner while auth session is pending', async ({ page }) => {
|
|
await mockSessionDelayed(page, 3000);
|
|
await page.goto('/purchases');
|
|
await expect(page.locator('.animate-spin')).toBeVisible({ timeout: 2000 });
|
|
await expect(page).toHaveURL(/\/login/, { timeout: 10_000 });
|
|
});
|
|
});
|