Files
test-assignment/tests/workspace.spec.ts
T

185 lines
9.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect, type Page } from '@playwright/test';
async function signIn(page: Page, account = 'head') {
await page.goto('/login');
await page.getByLabel(/Email address|Электронная почта/).fill(`${account}@merchantflow.test`);
await page.getByLabel(/^Password$|^Пароль$/).fill('MerchantFlow123!');
await page
.getByRole('button', { name: /^Sign in to workspace$|^Войти в рабочее пространство$/ })
.click();
await expect(page).toHaveURL(/\/app$/);
await expect(page.getByRole('heading', { name: /^Overview$|^Обзор$/ })).toBeVisible();
await expect(
page.getByRole('heading', { name: /Pipeline at a glance|Воронка с первого взгляда/ }),
).toBeVisible();
}
async function noOverflow(page: Page) {
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(
true,
);
}
for (const language of ['en', 'ru'])
for (const width of [390, 1440])
test.describe(`${language} ${width}px`, () => {
test.use({ viewport: { width, height: 1000 } });
test('public journey, navigation, browsing, filters, keyboard and locale persistence', async ({
page,
}, info) => {
const errors: string[] = [];
page.on('pageerror', (e) => errors.push(e.message));
await page.addInitScript(
(lang) => localStorage.setItem('merchantflow.language', lang),
language,
);
await page.goto('/');
await expect(page.locator('h1')).toBeVisible();
await noOverflow(page);
await page.screenshot({ path: info.outputPath('landing.png'), fullPage: true });
await signIn(page);
await noOverflow(page);
await expect(page.locator('html')).toHaveAttribute('lang', language);
await page.screenshot({ path: info.outputPath('dashboard.png'), fullPage: true });
if (width === 390) {
await page.getByRole('button', { name: /Open navigation|Открыть навигацию/ }).click();
await expect(page.getByRole('dialog')).toBeVisible();
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).not.toBeVisible();
await expect(
page.getByRole('button', { name: /Open navigation|Открыть навигацию/ }),
).toBeFocused();
} else {
await page.keyboard.press('Tab');
await expect(
page.getByRole('link', { name: /Skip to content|Перейти к содержимому/ }),
).toBeFocused();
}
await page.goto('/app/merchants');
await expect(page.getByRole('heading', { name: /^Merchants$|^Мерчанты$/ })).toBeVisible();
await page.getByRole('button', { name: /^Next$|^Далее$/ }).click();
await expect(page).toHaveURL(/page=2/);
const search = page.getByRole('textbox', { name: /Search merchants|Название мерчанта/ });
await search.fill('Luma');
await expect(page.getByRole('link', { name: /Luma Labs/ }).first()).toBeVisible();
await page
.getByRole('link', { name: /Luma Labs/ })
.first()
.click();
await expect(page.locator('h1')).toHaveText('Luma Labs');
await expect(page.getByText(/Please clarify the beneficial ownership/)).toBeVisible();
await noOverflow(page);
await page.reload();
await expect(page.locator('h1')).toHaveText('Luma Labs');
await expect(page.locator('html')).toHaveAttribute('lang', language);
await page.screenshot({ path: info.outputPath('merchant.png'), fullPage: true });
await page.goto('/app/merchants');
await page.getByRole('combobox').selectOption('LIVE');
await expect(page.getByRole('link', { name: /Sunday Market/ }).first()).toBeVisible();
await page.getByRole('textbox').fill('no-such-merchant');
await expect(page.getByText(/No merchants found|Мерчанты не найдены/)).toBeVisible();
await page.getByRole('button', { name: /Clear filters|Сбросить фильтры/ }).click();
await expect(page.getByRole('textbox')).toHaveValue('');
await page.goto('/app/pipeline');
await expect(page.locator('h1')).toHaveText(language === 'en' ? 'Pipeline' : 'Воронка');
if (width === 390) await page.getByRole('combobox').selectOption('KYB');
await expect(page.getByRole('link', { name: /Luma Labs/ })).toBeVisible();
await expect(
page.getByRole('heading', { name: /Closed · Rejected|Закрыто · Отклонён/ }),
).toBeVisible();
await noOverflow(page);
await page.screenshot({ path: info.outputPath('pipeline.png'), fullPage: true });
await page.goto('/app/tasks');
await page.getByRole('button', { name: /^Completed$|^Выполненные$/ }).click();
await expect(page.getByText('Confirm the primary contact details').first()).toBeVisible();
await noOverflow(page);
await page.goto('/app/review-queue');
await expect(
page.getByText(/This view is for Compliance|Раздел для комплаенса/),
).toBeVisible();
expect(errors).toEqual([]);
});
});
test('account switching removes old data, manager isolation and Compliance navigation', async ({
page,
}) => {
await signIn(page);
await page.goto('/app/merchants/merchant-02');
await expect(page.locator('h1')).toHaveText('Northstar Studio');
await page.getByRole('button', { name: 'Sign out' }).click();
await expect(page).toHaveURL(/login/);
await signIn(page, 'manager1');
const dashboard = await page.request.get('/api/dashboard');
expect((await dashboard.json()).merchantCount).toBe(9);
await page.goto('/app/merchants/merchant-02');
await expect(
page.getByText('This merchant was not found or is outside your portfolio.'),
).toBeVisible();
await page.getByRole('button', { name: 'Sign out' }).click();
await signIn(page, 'compliance');
expect((await (await page.request.get('/api/dashboard')).json()).merchantCount).toBe(4);
await page.getByRole('link', { name: 'Review queue', exact: true }).click();
await expect(page.getByRole('heading', { name: '2 merchants awaiting review' })).toBeVisible();
await page.getByRole('link', { name: 'View checklist' }).first().click();
await expect(page.getByRole('heading', { name: 'KYB checklist' })).toBeVisible();
await page.goto('/app/merchants/merchant-15');
await expect(
page.getByText('This merchant was not found or is outside your portfolio.'),
).toBeVisible();
});
test('translated validation, persistent language changes and accessible form errors', async ({
page,
}) => {
await page.goto('/login');
await page.getByRole('button', { name: 'Русский', exact: true }).click();
await page.getByRole('button', { name: 'Войти в рабочее пространство', exact: true }).click();
await expect(page.getByText('Введите корректный адрес почты.')).toBeVisible();
await expect(page.getByLabel('Электронная почта')).toHaveAttribute('aria-invalid', 'true');
await page.reload();
await expect(page.locator('html')).toHaveAttribute('lang', 'ru');
await page.getByRole('button', { name: 'English', exact: true }).click();
await page.reload();
await expect(page.locator('html')).toHaveAttribute('lang', 'en');
await page.getByLabel('Email address').fill('[email protected]');
await page.getByLabel('Password', { exact: true }).fill('wrong');
await page.getByRole('button', { name: 'Sign in to workspace', exact: true }).click();
await expect(page.getByRole('alert')).toHaveText('The email or password is incorrect.');
});
test('loading, retryable errors, empty states, session expiry and reduced motion', async ({
page,
}) => {
await signIn(page);
let release: () => void = () => {};
const held = new Promise<void>((resolve) => {
release = resolve;
});
await page.route('**/api/merchants?**', async (route) => {
await held;
await route.continue();
});
await page.goto('/app/merchants');
await expect(page.getByRole('status', { name: 'Loading your workspace…' })).toBeVisible();
release();
await expect(page.getByRole('link', { name: /Orbit Goods/ }).first()).toBeVisible();
await page.unroute('**/api/merchants?**');
await page.route('**/api/pipeline', (route) =>
route.fulfill({ status: 503, json: { code: 'DATABASE_UNAVAILABLE' } }),
);
await page.goto('/app/pipeline');
await expect(
page.getByText('The workspace database is unavailable. Please try again.'),
).toBeVisible();
await page.unroute('**/api/pipeline');
await page.getByRole('button', { name: 'Try again' }).click();
await expect(page.getByRole('heading', { name: 'Closed · Rejected' })).toBeVisible();
await page.route('**/api/tasks?**', (route) => route.fulfill({ json: [] }));
await page.goto('/app/tasks');
await expect(page.getByText('You’re all caught up here')).toBeVisible();
await page.emulateMedia({ reducedMotion: 'reduce' });
expect(
await page
.getByRole('button', { name: 'English', exact: true })
.evaluate((el) => getComputedStyle(el).transitionDuration),
).toBe('1e-05s');
await page.context().clearCookies();
await page.goto('/app/merchants');
await expect(page).toHaveURL(/\/login\?next=/);
});