T: Implement backend mocking for tests

This commit is contained in:
Ivan 2025-01-27 16:11:35 +03:00
parent 2b9a3ae189
commit 421cd98429
3 changed files with 15 additions and 0 deletions

View File

@ -1,9 +1,14 @@
import { expect, test } from '@playwright/test'; import { expect, test } from '@playwright/test';
import { authAnonymous } from './mocks/auth';
test('should load the homepage and display login button', async ({ page }) => { test('should load the homepage and display login button', async ({ page }) => {
await authAnonymous(page);
await page.goto('/'); await page.goto('/');
await expect(page).toHaveTitle('Концепт Портал'); await expect(page).toHaveTitle('Концепт Портал');
await expect(page.getByRole('heading', { name: 'Портал' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Портал' })).toBeVisible();
await page.click('.h-full > .mr-1'); await page.click('.h-full > .mr-1');
await expect(page.getByText('Логин или email')).toBeVisible(); await expect(page.getByText('Логин или email')).toBeVisible();
}); });

View File

@ -0,0 +1 @@
export const BACKEND_URL = 'http://localhost:8000';

View File

@ -0,0 +1,9 @@
import { Page } from '@playwright/test';
import { BACKEND_URL } from '../constants';
export async function authAnonymous(page: Page) {
await page.route(`${BACKEND_URL}/users/api/auth`, async route => {
await route.fulfill({ json: { id: null } });
});
}