Added some small enchances

This commit is contained in:
Oleksandr Prokhorenko
2026-09-24 22:41:06 +03:00
parent 9ccbac4aca
commit 7f3a56a4ca
21 changed files with 441 additions and 211 deletions
+7
View File
@@ -0,0 +1,7 @@
import { expect, type Locator } from '@playwright/test';
export async function selectOption(trigger: Locator, value: string) {
await trigger.click();
await trigger.page().locator(`[role="option"][data-value="${value}"]`).click();
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
}
+4 -3
View File
@@ -1,3 +1,4 @@
import { selectOption } from './helpers/select';
import { test, expect, type Page } from '@playwright/test';
import { createDatabase } from '../packages/database/dist/index.js';
@@ -34,8 +35,8 @@ async function fill(page: Page) {
await page.locator('#lead-contactName').fill('Test Contact');
await page.locator('#lead-contactEmail').fill(email);
await page.locator('#lead-website').fill('example.test');
await page.locator('#lead-country').selectOption('GB');
await page.locator('#lead-industry').selectOption('OTHER');
await selectOption(page.locator('#lead-country'), 'GB');
await selectOption(page.locator('#lead-industry'), 'OTHER');
await page.locator('#lead-estimatedMonthlyVolumeUsd').fill('12500,50');
return email;
}
@@ -84,7 +85,7 @@ for (const language of ['en', 'ru'])
.click();
await expect(page.locator('#lead-name')).toHaveValue('MerchantFlow browser fixture');
await expect(page.locator('#lead-estimatedMonthlyVolumeUsd')).toHaveValue('12500,50');
await expect(page.locator('#lead-country')).toHaveValue('GB');
await expect(page.locator('#lead-country')).toHaveText(/United Kingdom|Великобритания/);
await page
.getByRole('button', { name: language === 'en' ? 'English' : 'Русский', exact: true })
.click();
+15 -11
View File
@@ -1,3 +1,4 @@
import { selectOption } from './helpers/select';
import { test, expect, type APIRequestContext } from '@playwright/test';
import { createDatabase } from '../packages/database/dist/index.js';
@@ -74,21 +75,24 @@ for (const language of ['en', 'ru'])
await page.goto('/app/review-queue');
const search = page.getByRole('textbox', { name: /Search merchants|Поиск мерчантов/ });
await search.fill(name);
await page
.getByRole('combobox', { name: /Account manager|Аккаунт-менеджер/ })
.selectOption('user-manager1');
await selectOption(
page.getByRole('combobox', { name: /Account manager|Аккаунт-менеджер/ }),
'user-manager1',
);
await expect(page.locator('article')).toHaveCount(1);
await expect(page.locator('article')).toContainText(/Waiting|Ожидание/);
await page
.getByRole('combobox', { name: /Waiting time|Время ожидания/ })
.selectOption('24');
await selectOption(
page.getByRole('combobox', { name: /Waiting time|Время ожидания/ }),
'24',
);
await expect(page.locator('article')).toHaveCount(0);
await expect(page).toHaveURL(/waiting=24/);
await page.reload();
await expect(search).toHaveValue(name);
await page
.getByRole('combobox', { name: /Waiting time|Время ожидания/ })
.selectOption('ALL');
await selectOption(
page.getByRole('combobox', { name: /Waiting time|Время ожидания/ }),
'ALL',
);
await expect(page.locator('article')).toHaveCount(1);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(
true,
@@ -110,7 +114,7 @@ for (const language of ['en', 'ru'])
'aria-invalid',
'true',
);
await dialog.getByLabel(/Decision$|^Решение$/).selectOption('REJECTED');
await selectOption(dialog.getByLabel(/Decision$|^Решение$/), 'REJECTED');
await expect(dialog.getByLabel(/Risk level|Уровень риска/)).toHaveCount(0);
await dialog.getByRole('button', { name: /^(Reject|Отклонить)$/ }).click();
const reason = dialog.getByLabel(/Rejection reason|Причина отклонения/);
@@ -166,7 +170,7 @@ test('an open decision form stays bound to its original cycle after another revi
await page.goto(`/app/merchants/${merchant.id}?tab=onboarding`);
await page.getByRole('button', { name: 'Record decision', exact: true }).click();
const dialog = page.getByRole('dialog');
await dialog.getByLabel('Risk level', { exact: true }).selectOption('LOW');
await selectOption(dialog.getByLabel('Risk level', { exact: true }), 'LOW');
await dialog
.getByLabel('Approval rationale (required)', { exact: true })
.fill('Assessment of the original submission.');
+98 -19
View File
@@ -1,3 +1,5 @@
import { selectOption } from './helpers/select';
import { createHash, randomBytes } from 'node:crypto';
import { test, expect, type Page } from '@playwright/test';
import { createDatabase } from '../packages/database/dist/index.js';
@@ -5,9 +7,12 @@ if (!process.env.DATABASE_URL?.endsWith('/merchantflow_test'))
throw new Error('Daily sales browser tests require the isolated database');
const db = createDatabase(process.env.DATABASE_URL);
const names = new Set<string>();
const sessions = new Set<string>();
test.afterEach(async () => {
await db.merchant.deleteMany({ where: { name: { in: [...names] } } });
names.clear();
await db.session.deleteMany({ where: { id: { in: [...sessions] } } });
sessions.clear();
});
test.afterAll(() => db.$disconnect());
async function login(page: Page, account = 'head') {
@@ -65,19 +70,19 @@ for (const language of ['en', 'ru'])
page.getByText(/Log a call or email before|Запишите звонок или письмо/),
).toBeVisible();
await page.getByRole('button', { name: /^(Assign manager|Назначить менеджера)$/ }).click();
await page
.getByRole('dialog')
.getByLabel(/^(Account manager|Аккаунт-менеджер)$/)
.selectOption('user-manager1');
await selectOption(
page.getByRole('dialog').getByLabel(/^(Account manager|Аккаунт-менеджер)$/),
'user-manager1',
);
await save(page);
await page.getByRole('tab', { name: /^(Activity|Активность)$/ }).click();
await page
.getByRole('button', { name: /^(Log interaction|Добавить взаимодействие)$/ })
.click();
await page
.getByRole('dialog')
.getByLabel(/^(Interaction type|Тип взаимодействия)$/)
.selectOption('CALL');
await selectOption(
page.getByRole('dialog').getByLabel(/^(Interaction type|Тип взаимодействия)$/),
'CALL',
);
await page
.getByRole('dialog')
.getByLabel(/^(Details|Подробности)$/)
@@ -114,7 +119,7 @@ for (const language of ['en', 'ru'])
const dialog = page.getByRole('dialog');
await dialog.getByLabel(/^(Website|Сайт)$/).fill('https://daily.example.test');
await dialog.getByLabel(/^(Country code|Код страны)$/).fill('GB');
await dialog.getByLabel(/^(Industry|Отрасль)$/).selectOption('OTHER');
await selectOption(dialog.getByLabel(/^(Industry|Отрасль)$/), 'OTHER');
await dialog
.getByLabel(/^(Estimated monthly processing \(USD\)|Месячный объём обработки \(USD\))$/)
.fill('0');
@@ -123,15 +128,18 @@ for (const language of ['en', 'ru'])
await page
.getByRole('textbox', { name: /Search merchants|Название мерчанта/ })
.fill(`Contact ${name}`);
await page
.getByRole('combobox', { name: /^(All countries|Все страны)$/ })
.selectOption('GB');
await page
.getByRole('combobox', { name: /^(All industries|Все отрасли)$/ })
.selectOption('OTHER');
await page
.getByRole('combobox', { name: /^(All managers|Все менеджеры)$/ })
.selectOption('user-manager1');
await selectOption(
page.getByRole('combobox', { name: /^(All countries|Все страны)$/ }),
'GB',
);
await selectOption(
page.getByRole('combobox', { name: /^(All industries|Все отрасли)$/ }),
'OTHER',
);
await selectOption(
page.getByRole('combobox', { name: /^(All managers|Все менеджеры)$/ }),
'user-manager1',
);
await expect(page).toHaveURL(/country=GB.*industry=OTHER.*ownerId=user-manager1/);
await expect(page.getByRole('link', { name: new RegExp(name) }).first()).toBeVisible();
await noOverflow(page);
@@ -158,7 +166,7 @@ for (const language of ['en', 'ru'])
await expect
.poll(async () => (await (await page.request.get(`/api/merchants/${id}`)).json()).status)
.toBe('CONTACTED');
if (width === 390) await page.getByRole('combobox').selectOption('CONTACTED');
if (width === 390) await selectOption(page.getByRole('combobox'), 'CONTACTED');
const contactedCard = page
.getByRole('region', {
name: language === 'en' ? 'Contacted' : 'Контакт установлен',
@@ -237,3 +245,74 @@ test('manager creation assigns self and stale edits keep unsaved form values', a
await page.goto('/app/merchants');
await expect(page.getByRole('button', { name: 'Add merchant', exact: true })).toHaveCount(0);
});
for (const width of [390, 1440]) {
test(`custom dropdown keyboard navigation and merchant page sizes at ${width}px`, async ({
page,
}) => {
await page.setViewportSize({ width, height: 1000 });
// Login has dedicated coverage; these checks must not exhaust its rate limit.
const user = await db.user.findUniqueOrThrow({ where: { email: '[email protected]' } });
const token = randomBytes(32).toString('hex');
const id = createHash('sha256').update(token).digest('hex');
sessions.add(id);
await db.session.create({
data: { id, userId: user.id, expiresAt: new Date(Date.now() + 3600000) },
});
await page.context().addCookies([
{
name: 'mf_session',
value: token,
domain: '127.0.0.1',
path: '/api',
httpOnly: true,
sameSite: 'Lax',
},
]);
await page.goto('/app/merchants');
const size = page.getByRole('combobox', { name: 'Show per page' });
await expect(size).toHaveText('10');
await expect(page.locator('select:visible')).toHaveCount(0);
await page.getByRole('button', { name: 'Next', exact: true }).click();
await expect(page).toHaveURL(/page=2/);
for (const count of [20, 30, 10]) {
const response = page.waitForResponse((response) => {
const url = new URL(response.url());
return (
url.pathname === '/api/merchants' && url.searchParams.get('pageSize') === String(count)
);
});
await selectOption(size, String(count));
const result = await (await response).json();
expect(result.page).toBe(1);
expect(result.pageSize).toBe(count);
expect(result.items).toHaveLength(Math.min(count, result.total));
await expect(
page.getByText(`1–${Math.min(count, result.total)} of ${result.total} merchants`, {
exact: true,
}),
).toBeVisible();
expect(new URL(page.url()).searchParams.has('page')).toBe(false);
await noOverflow(page);
}
await selectOption(size, '20');
await page.reload();
await expect(size).toHaveText('20');
const stage = page.getByRole('combobox', { name: 'Filter by stage' });
await stage.focus();
await stage.press('ArrowDown');
await expect(page.getByRole('listbox')).toBeVisible();
await expect(page.getByRole('option', { name: 'All stages', exact: true })).toBeFocused();
await page.keyboard.press('End');
await expect(page.getByRole('option', { name: 'Rejected', exact: true })).toBeFocused();
await page.keyboard.press('Enter');
await expect(stage).toHaveText('Rejected');
await expect(stage).toBeFocused();
await expect(page).toHaveURL(/status=REJECTED/);
await stage.press('ArrowDown');
await page.keyboard.press('Escape');
await expect(page.getByRole('listbox')).not.toBeVisible();
await expect(stage).toBeFocused();
await expect(stage).toHaveText('Rejected');
});
}
+24 -22
View File
@@ -1,3 +1,4 @@
import { selectOption } from './helpers/select';
import { test, expect, type Page } from '@playwright/test';
async function signIn(page: Page, account = 'head') {
await page.goto('/login');
@@ -94,9 +95,10 @@ for (const language of ['en', 'ru'])
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).not.toBeVisible();
await page.goto('/app/merchants');
await page
.getByRole('combobox', { name: /Filter by stage|Фильтр по этапу/ })
.selectOption('LIVE');
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();
@@ -104,9 +106,9 @@ for (const language of ['en', 'ru'])
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');
if (width === 390) await selectOption(page.getByRole('combobox'), 'KYB');
await expect(page.getByRole('link', { name: /Luma Labs/ })).toBeVisible();
if (width === 390) await page.getByRole('combobox').selectOption('REJECTED');
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 });
@@ -238,7 +240,7 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
await page.goto(merchantPath);
await expect(page.getByText('Unassigned', { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Assign manager', exact: true }).click();
await page.getByRole('dialog').getByLabel('Account manager').selectOption('user-manager1');
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);
@@ -255,7 +257,7 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
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 page.getByRole('dialog').getByLabel('Interaction type').selectOption('CALL');
await selectOption(page.getByRole('dialog').getByLabel('Interaction type'), 'CALL');
await page
.getByRole('dialog')
.getByLabel('Details', { exact: true })
@@ -280,10 +282,10 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
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 page
.getByRole('dialog')
.getByLabel('Collection status', { exact: true })
.selectOption('RECEIVED');
await selectOption(
page.getByRole('dialog').getByLabel('Collection status', { exact: true }),
'RECEIVED',
);
await save();
}
await advance('Compliance Review');
@@ -291,10 +293,10 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
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('Decision', { exact: true })
.selectOption('CORRECTIONS');
await selectOption(
page.getByRole('dialog').getByLabel('Decision', { exact: true }),
'CORRECTIONS',
);
await page
.getByRole('dialog')
.getByLabel('Required changes (required)', { exact: true })
@@ -314,10 +316,10 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
.locator('#checklist > div > div')
.filter({ hasText: 'Ownership structure' });
await ownership.getByRole('button', { name: 'Update collection', exact: true }).click();
await page
.getByRole('dialog')
.getByLabel('Collection status', { exact: true })
.selectOption('RECEIVED');
await selectOption(
page.getByRole('dialog').getByLabel('Collection status', { exact: true }),
'RECEIVED',
);
await page
.getByRole('dialog')
.getByLabel('Collection notes', { exact: true })
@@ -331,7 +333,7 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
.getByRole('dialog')
.getByLabel('Approval rationale (required)', { exact: true })
.fill('All evidence checked and approved.');
await page.getByRole('dialog').getByLabel('Risk level', { exact: true }).selectOption('LOW');
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);
@@ -347,7 +349,7 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
.locator('article')
.filter({ has: page.getByRole('heading', { name, exact: true }) });
await row.getByRole('button', { name: 'Update demo check' }).click();
await page.getByRole('dialog').getByLabel('Result', { exact: true }).selectOption(result);
await selectOption(page.getByRole('dialog').getByLabel('Result', { exact: true }), result);
await save();
};
await expect(page.getByRole('button', { name: 'Move to Testing', exact: true })).toBeDisabled();
@@ -364,7 +366,7 @@ test('Head assignment, manager editing, Compliance decisions and manager activat
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 page.getByRole('dialog').getByLabel('Account manager').selectOption('user-manager2');
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();