92 lines
3.5 KiB
TypeScript
92 lines
3.5 KiB
TypeScript
import { test, expect } from './fixtures';
|
|
import { mockApi } from './mock-api';
|
|
|
|
test('przekierowuje niezalogowanego użytkownika na /login', async ({ page }) => {
|
|
mockApi(page);
|
|
await page.goto('/');
|
|
await expect(page).toHaveURL(/\/login$/);
|
|
await expect(page.getByRole('heading', { name: 'FitOS Admin' })).toBeVisible();
|
|
});
|
|
|
|
test('udane logowanie admina przekierowuje na /gyms', async ({ page }) => {
|
|
mockApi(page);
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('admin@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('haslo123');
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page).toHaveURL(/\/gyms$/);
|
|
await expect(page.getByRole('heading', { name: 'Siłownie' })).toBeVisible();
|
|
});
|
|
|
|
test('zapamiętaj mnie zapisuje e-mail i podpowiada go po wylogowaniu', async ({ page }) => {
|
|
mockApi(page);
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('admin@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('haslo123');
|
|
await page.getByRole('checkbox', { name: 'Zapamiętaj mnie' }).check();
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page).toHaveURL(/\/gyms$/);
|
|
await page.getByRole('button', { name: 'Wyloguj' }).click();
|
|
await expect(page).toHaveURL(/\/login$/);
|
|
await expect(page.locator('input[type="email"]')).toHaveValue('admin@fitos.pl');
|
|
});
|
|
|
|
test('bez zaznaczenia zapamiętaj mnie e-mail nie jest zapisywany', async ({ page }) => {
|
|
mockApi(page);
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('admin@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('haslo123');
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page).toHaveURL(/\/gyms$/);
|
|
const stored = await page.evaluate(() => localStorage.getItem('fitos-remembered-email'));
|
|
expect(stored).toBeNull();
|
|
});
|
|
|
|
test('logowanie konta bez uprawnień panelu zostaje odrzucone', async ({ page }) => {
|
|
mockApi(page, {
|
|
loginBody: {
|
|
user: {
|
|
id: 'user-1',
|
|
email: 'user@fitos.pl',
|
|
firstName: 'User',
|
|
lastName: null,
|
|
birthDate: null,
|
|
heightCm: null,
|
|
phone: null,
|
|
platformRoles: [],
|
|
permissions: [],
|
|
availability: null,
|
|
priorities: null,
|
|
exclusions: null,
|
|
developMuscles: [],
|
|
canDoMuscles: [],
|
|
difficultMuscles: [],
|
|
avoidMuscles: [],
|
|
createdAt: '2026-01-01T00:00:00.000Z',
|
|
},
|
|
accessToken: 'test-access-token',
|
|
},
|
|
});
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('user@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('haslo123');
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page).toHaveURL(/\/login$/);
|
|
await expect(page.getByText('To konto nie ma dostępu do panelu administracyjnego.')).toBeVisible();
|
|
});
|
|
|
|
test('nieudane logowanie administratora pokazuje komunikat o błędnych danych', async ({ page }) => {
|
|
mockApi(page, {
|
|
loginStatus: 401,
|
|
loginBody: {
|
|
error: { code: 'INVALID_CREDENTIALS', message: 'Invalid credentials' },
|
|
},
|
|
});
|
|
await page.goto('/login');
|
|
await page.locator('input[type="email"]').fill('admin@fitos.pl');
|
|
await page.locator('input[type="password"]').fill('zle-haslo');
|
|
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
|
await expect(page).toHaveURL(/\/login$/);
|
|
await expect(page.getByText('Nieprawidłowy e-mail lub hasło.')).toBeVisible();
|
|
});
|