diora-web/e2e/authenticated.spec.js

26 lines
1 KiB
JavaScript
Raw Permalink Normal View History

// Authenticated smoke tests: reuse the storage state saved in global-setup.js
// for the fixed TEST_USER, so no login step is needed per test.
const { test, expect } = require('@playwright/test');
const path = require('path');
const { TEST_USER } = require('./env');
test.use({ storageState: path.join(__dirname, '.auth', 'user.json') });
test('logged-in home page shows the username and settings link', async ({ page }) => {
await page.goto('/');
await expect(page.locator('.navbar-user')).toHaveText(TEST_USER.username);
await expect(page.locator('a[href="/accounts/settings/"]')).toBeVisible();
});
test('settings page is reachable while authenticated', async ({ page }) => {
await page.goto('/accounts/settings/');
await expect(page).toHaveURL(/\/accounts\/settings\//);
});
test('book list API requires auth and returns JSON for the logged-in user', async ({ request }) => {
const res = await request.get('/books/');
expect(res.ok()).toBeTruthy();
const body = await res.json();
expect(Array.isArray(body)).toBe(true);
});