68 lines
3.1 KiB
TypeScript
68 lines
3.1 KiB
TypeScript
import { test, expect, type Page } from '@playwright/test';
|
|
|
|
const PUBLIC_ID = '550e8400-e29b-41d4-a716-446655440000'; // "ЯКС-1", public
|
|
const UNLISTED_ID = '550e8400-e29b-41d4-a716-446655440001'; // "Тестовый", unlisted
|
|
const PRIVATE_ID = '550e8400-e29b-41d4-a716-446655440002'; // "Секретный", admin-owned
|
|
|
|
async function login(page: Page, user: string, pass: string) {
|
|
await page.goto('/login/');
|
|
await page.fill('#lg-username', user);
|
|
await page.fill('#lg-password', pass);
|
|
await page.click('button[type=submit]');
|
|
await expect(page.getByTestId('nav-menu')).toBeVisible();
|
|
}
|
|
|
|
test('the public flight list is reachable without signing in', async ({ page }) => {
|
|
await page.goto('/flights/');
|
|
await expect(page.getByTestId('flights-list')).toBeVisible();
|
|
// Only public flights are listed — unlisted and private ones are not.
|
|
await expect(page.getByTestId('flights-list')).toContainText('ЯКС-1');
|
|
await expect(page.getByTestId('flights-list')).not.toContainText('Тестовый');
|
|
await expect(page.getByTestId('flights-list')).not.toContainText('Секретный');
|
|
});
|
|
|
|
test('a shared flight link opens anonymously and streams telemetry', async ({ page }) => {
|
|
await page.goto(`/track/${PUBLIC_ID}/`);
|
|
await expect(page.getByTestId('track-name')).toHaveText('ЯКС-1');
|
|
// History loads, then the socket takes over — no session involved.
|
|
await expect(page.getByTestId('track-readout')).toBeVisible({ timeout: 15000 });
|
|
await expect(page.getByTestId('track-status')).toContainText(/на связи|live/i, {
|
|
timeout: 15000
|
|
});
|
|
});
|
|
|
|
test('an unlisted flight opens by link but is absent from the list', async ({ page }) => {
|
|
await page.goto(`/track/${UNLISTED_ID}/`);
|
|
await expect(page.getByTestId('track-name')).toHaveText('Тестовый');
|
|
});
|
|
|
|
test('a private flight is not readable by others', async ({ page }) => {
|
|
// Anonymous: hidden.
|
|
await page.goto(`/track/${PRIVATE_ID}/`);
|
|
await expect(page.getByTestId('track-error')).toBeVisible();
|
|
|
|
// A signed-in non-owner: still hidden.
|
|
await login(page, 'demo', 'demo');
|
|
await page.goto(`/track/${PRIVATE_ID}/`);
|
|
await expect(page.getByTestId('track-error')).toBeVisible();
|
|
});
|
|
|
|
test('the owner sees a private flight and can change its tier', async ({ page }) => {
|
|
await login(page, 'admin', 'admin');
|
|
await page.goto(`/track/${PRIVATE_ID}/`);
|
|
await expect(page.getByTestId('track-name')).toHaveText('Секретный');
|
|
|
|
// Owners get the privacy control; it takes effect immediately.
|
|
const privacy = page.getByTestId('track-privacy');
|
|
await expect(privacy).toHaveValue('private');
|
|
await privacy.selectOption('public');
|
|
await expect(page.getByTestId('track-card')).toContainText(/публичный|public/i);
|
|
|
|
// Now it shows up on the public map, and reverting hides it again.
|
|
await page.goto('/flights/');
|
|
await expect(page.getByTestId('flights-list')).toContainText('Секретный');
|
|
await page.goto(`/track/${PRIVATE_ID}/`);
|
|
await page.getByTestId('track-privacy').selectOption('private');
|
|
await page.goto('/flights/');
|
|
await expect(page.getByTestId('flights-list')).not.toContainText('Секретный');
|
|
});
|