46724b1db9
Fixes CAR-673, CAR-676. Replaces VITE_MOCK_AUTH with Playwright route mocking for all e2e tests. Fixes color contrast (text-gray-400 → text-gray-600).
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 });
|
|
});
|
|
});
|