Files

381 lines
18 KiB
TypeScript

import { selectOption } from './helpers/select';
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.locator('h1')).toHaveText(
account === 'head'
? /Portfolio overview|Обзор портфеля/
: account === 'compliance'
? /Review workspace|Проверки комплаенса/
: /My merchant workspace|Мои мерчанты/,
);
await expect(
page.getByRole('heading', {
name:
account === 'compliance'
? /Oldest waiting reviews|Дольше всего ожидают/
: /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 page.getByRole('tab', { name: /^(Onboarding|Онбординг)$/ }).click();
await expect(
page.getByText(/Please clarify the beneficial ownership/).first(),
).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 });
const editButton = page.getByRole('button', {
name: /^(Edit merchant|Изменить мерчанта)$/,
});
await editButton.click();
await expect(page.getByRole('dialog')).toBeVisible();
await noOverflow(page);
await page.screenshot({ path: info.outputPath('merchant-editor.png'), fullPage: true });
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).not.toBeVisible();
await page.goto('/app/merchants');
await selectOption(
page.getByRole('combobox', { name: /Filter by stage|Фильтр по этапу/ }),
'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 selectOption(page.getByRole('combobox'), 'KYB');
await expect(page.getByRole('link', { name: /Luma Labs/ })).toBeVisible();
if (width === 390) await selectOption(page.getByRole('combobox'), 'REJECTED');
await expect(page.getByRole('heading', { name: /^(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, 'alex');
const dashboard = await page.request.get('/api/dashboard');
expect((await dashboard.json()).merchantCount).toBe(20);
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(45);
await page
.getByRole('navigation', { name: 'Workspace', exact: true })
.getByRole('link', { name: 'Review queue', exact: true })
.click();
await expect(page.getByRole('heading', { name: '6 merchants awaiting review' })).toBeVisible();
await page.getByRole('link', { name: 'Open review' }).first().click();
await expect(page.getByRole('heading', { name: 'KYB checklist' })).toBeVisible();
await page.goto('/app/merchants/merchant-15');
await expect(page.locator('h1')).toHaveText('Sunday Market');
await expect(page.getByRole('button', { name: 'Edit merchant', exact: true })).toHaveCount(0);
});
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: 'Rejected', exact: true })).toBeVisible();
await page.route('**/api/tasks?**', (route) => route.fulfill({ json: [] }));
await page.goto('/app/tasks');
await expect(page.getByText('No tasks in this view')).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=/);
});
test('Head assignment, manager editing, Compliance decisions and manager activation work through the UI', async ({
page,
}, info) => {
const merchantPath = '/app/merchants/merchant-19';
const save = async () => {
await page.getByRole('button', { name: 'Save changes', exact: true }).click();
await expect(page.getByRole('dialog')).not.toBeVisible();
};
const switchAccount = async (account: string) => {
await page.getByRole('button', { name: 'Sign out', exact: true }).click();
await signIn(page, account);
await page.goto(merchantPath);
await expect(page.locator('h1')).toHaveText('Willow Ceramics');
};
const advance = async (stage: string) => {
await page.getByRole('button', { name: `Move to ${stage}`, exact: true }).click();
await expect(
page.getByRole('status').filter({ hasText: 'Changes saved.' }).first(),
).toBeVisible();
await expect
.poll(
async () => (await (await page.request.get('/api/merchants/merchant-19')).json()).status,
)
.toBe(stage.toUpperCase().replaceAll(' ', '_'));
};
await signIn(page);
await page.goto(merchantPath);
await expect(page.getByText('Unassigned', { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Assign manager', exact: true }).click();
await selectOption(page.getByRole('dialog').getByLabel('Account manager'), 'user-manager1');
await save();
await switchAccount('alex');
await expect(page.getByRole('button', { name: 'Assign manager', exact: true })).toHaveCount(0);
await page.getByRole('button', { name: 'Edit merchant', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Contact title', { exact: true })
.fill('Director of Partnerships');
await page
.getByRole('dialog')
.getByLabel('Estimated monthly processing (USD)', { exact: true })
.fill('246000.75');
await save();
await expect(page.getByText('Director of Partnerships', { exact: true })).toBeVisible();
await page.getByRole('tab', { name: 'Activity', exact: true }).click();
await page.getByRole('button', { name: 'Log interaction', exact: true }).click();
await selectOption(page.getByRole('dialog').getByLabel('Interaction type'), 'CALL');
await page
.getByRole('dialog')
.getByLabel('Details', { exact: true })
.fill('Confirmed the launch requirements in a discovery call.');
await save();
await expect(
page.getByText('Confirmed the launch requirements in a discovery call.', { exact: true }),
).toBeVisible();
await page.getByRole('tab', { name: 'Tasks', exact: true }).click();
await page.getByRole('button', { name: 'Add task', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Task title', { exact: true })
.fill('Send the integration guide');
await save();
const taskRow = page.locator('#tasks > div').filter({ hasText: 'Send the integration guide' });
await taskRow.getByRole('button', { name: 'Complete task', exact: true }).click();
await expect(taskRow.getByText(/^Completed ·/).first()).toBeVisible();
await advance('Contacted');
await advance('Qualified');
await advance('KYB');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
for (let i = 0; i < 3; i++) {
await page.getByRole('button', { name: 'Update collection', exact: true }).nth(i).click();
await selectOption(
page.getByRole('dialog').getByLabel('Collection status', { exact: true }),
'RECEIVED',
);
await save();
}
await advance('Compliance Review');
await expect(page.getByRole('button', { name: 'Record decision', exact: true })).toBeDisabled();
await switchAccount('compliance');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
await page.getByRole('button', { name: 'Record decision', exact: true }).click();
await selectOption(
page.getByRole('dialog').getByLabel('Decision', { exact: true }),
'CORRECTIONS',
);
await page
.getByRole('dialog')
.getByLabel('Required changes (required)', { exact: true })
.fill('The ownership declaration needs a current signature.');
await page
.getByRole('dialog')
.getByLabel('Ownership structure', { exact: true })
.fill('Please sign and date the declaration.');
await page
.getByRole('dialog')
.getByRole('button', { name: 'Request changes', exact: true })
.click();
await expect(page.getByRole('dialog')).not.toBeVisible();
await switchAccount('alex');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
const ownership = page
.locator('#checklist > div > div')
.filter({ hasText: 'Ownership structure' });
await ownership.getByRole('button', { name: 'Update collection', exact: true }).click();
await selectOption(
page.getByRole('dialog').getByLabel('Collection status', { exact: true }),
'RECEIVED',
);
await page
.getByRole('dialog')
.getByLabel('Collection notes', { exact: true })
.fill('Updated signature received.');
await save();
await advance('Compliance Review');
await switchAccount('compliance');
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
await page.getByRole('button', { name: 'Record decision', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Approval rationale (required)', { exact: true })
.fill('All evidence checked and approved.');
await selectOption(page.getByRole('dialog').getByLabel('Risk level', { exact: true }), 'LOW');
await page.getByRole('dialog').getByRole('button', { name: 'Approve', exact: true }).click();
await expect(page.getByRole('dialog')).not.toBeVisible();
await expect(page.getByRole('button', { name: 'Edit merchant', exact: true })).toHaveCount(0);
await switchAccount('alex');
await page.getByRole('button', { name: 'Edit merchant', exact: true }).click();
await expect(
page.getByRole('dialog').getByLabel('Legal company name', { exact: true }),
).toBeDisabled();
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
await page.getByRole('tab', { name: 'Onboarding', exact: true }).click();
const check = async (name: string, result: string) => {
const row = page
.locator('article')
.filter({ has: page.getByRole('heading', { name, exact: true }) });
await row.getByRole('button', { name: 'Update demo check' }).click();
await selectOption(page.getByRole('dialog').getByLabel('Result', { exact: true }), result);
await save();
};
await expect(page.getByRole('button', { name: 'Move to Testing', exact: true })).toBeDisabled();
await check('API connection', 'COMPLETE');
await check('Webhook setup', 'COMPLETE');
await advance('Testing');
await expect(page.getByRole('button', { name: 'Move to Live', exact: true })).toBeDisabled();
await check('Test payment', 'FAILED');
await check('Reconciliation', 'PASSED');
await expect(page.getByRole('button', { name: 'Move to Live', exact: true })).toBeDisabled();
await check('Test payment', 'PASSED');
await advance('Live');
await noOverflow(page);
await page.screenshot({ path: info.outputPath('approved-live-merchant.png'), fullPage: true });
await switchAccount('head');
await page.getByRole('button', { name: 'Assign manager', exact: true }).click();
await selectOption(page.getByRole('dialog').getByLabel('Account manager'), 'user-manager2');
await save();
await switchAccount('sam');
await expect(page.getByText('Director of Partnerships', { exact: true })).toBeVisible();
const hidden = await page.request.get('/api/merchants/merchant-01');
expect(hidden.status()).toBe(404);
expect(
await page.evaluate(() =>
Object.keys(localStorage).every((key) => key === 'merchantflow.language'),
),
).toBe(true);
});