Added some small enchances
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user