Files
weiguang-jewelry-ledger/新账系统/e2e/writes/setup.mjs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.5 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict';
import { fill, write } from './ui.mjs';
export async function logout(ctx, page, label) {
await write(ctx, page, label, '/api/logout', () =>
page.locator(ctx.version === 'old' ? '[data-action=logout]' : '.logout-button').click(),
);
}
export async function login(ctx, page, role, label, password) {
if (ctx.version === 'old') await page.locator('#login-form [name=member]').selectOption(role);
else {
await page.getByTestId('login-member').locator('.ant-select-selector').click();
await page.locator('.ant-select-item-option').filter({ hasText: label }).first().click();
}
await page.locator('[name=password]:visible').fill(password);
await write(ctx, page, role + '从登录页进入', '/api/login', () =>
page.getByRole('button', { name: /^登\s*录$/ }).click(),
);
await page.locator(ctx.version === 'old' ? '[data-action=logout]' : '.logout-button').waitFor();
}
export default async function setup(ctx) {
const page = await ctx.pageFor('guest');
await fill(page, {
storeName: '试用对照店铺',
ownerLabel: '店主甲',
ownerLoginName: 'owner',
ownerPassword: ctx.passwords.owner,
});
await write(ctx, page, '空库初始化', '/api/setup', () => page.getByRole('button', { name: '建立试用账号' }).click());
await logout(ctx, page, '新店主退出');
await login(ctx, page, 'owner', '店主甲', ctx.passwords.owner);
assert.equal((await page.context().cookies()).filter(c => c.name === 'mm_session').length, 1);
}