Files
trackgo-fe/apps/web/e2e/login.spec.ts
T
shancheas b0090bc15f feat: implement web URL constants and enhance navigation handling
- Introduced a centralized `WEB_URL` constant for managing application routes, improving maintainability and readability across components.
- Updated various components, including login, auth, and main app modules, to utilize the new `WEB_URL` constants for navigation, ensuring consistency in route management.
- Added a new `AppHomeRedirect` component to streamline user redirection based on privileges, enhancing user experience.
- Implemented client-side navigation functions to prevent full page reloads, improving performance and user interaction.
- Added tests for new functionalities, ensuring reliability in navigation and URL handling.

These changes significantly enhance the application's routing structure and navigation efficiency, providing a more cohesive user experience.
2026-09-02 11:17:51 +07:00

41 lines
1.7 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { E2E_LOGIN } from './fixtures/credentials';
import { mockBackend } from './fixtures/mock-api';
test.describe('login', () => {
test('renders the login form', async ({ page }) => {
await mockBackend(page);
await page.goto('/auth/login');
await expect(page.getByRole('heading', { name: 'Login to your account!' })).toBeVisible();
await expect(page.getByLabel('Username')).toBeVisible();
await expect(page.getByLabel('Password')).toBeVisible();
await expect(page.getByRole('button', { name: 'Login' })).toBeVisible();
});
test('signs in with valid credentials and lands in the app', async ({ page }) => {
await mockBackend(page, 'success');
await page.goto('/auth/login');
await page.getByLabel('Username').fill(E2E_LOGIN.username);
await page.getByLabel('Password').fill(E2E_LOGIN.password);
await page.getByRole('button', { name: 'Login' }).click();
await expect(page).toHaveURL(/\/app\/timeline\/index/);
await expect(page.getByPlaceholder('Search activities')).toBeVisible();
});
test('shows an error and stays on login when credentials are rejected', async ({ page }) => {
await mockBackend(page, 'unauthorized');
await page.goto('/auth/login');
await page.getByLabel('Username').fill(E2E_LOGIN.username);
await page.getByLabel('Password').fill(E2E_LOGIN.password);
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Invalid username or password')).toBeVisible();
await expect(page).toHaveURL(/\/auth\/login/);
await expect(page.getByRole('heading', { name: 'Login to your account!' })).toBeVisible();
});
});