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

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

37 lines
1.8 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict';
import { write } from './ui.mjs';
export default async function create(ctx) {
const page = await ctx.pageFor('assistant'),
old = ctx.version === 'old';
const btn = (name, scope = page) => scope.getByRole('button', { name, exact: true });
await page
.locator(old ? '#order-template-panel summary' : '.ant-collapse-header')
.filter({ hasText: '开单模板' })
.click();
await btn('保存为新模板').click();
const nameField = () =>
old ? page.locator('[name=template_name]') : page.getByRole('textbox', { name: '模板名称' });
await nameField().fill('逐笔开单模板');
const result = await write(ctx, page, '保存开单模板', '/api/order-templates', () => btn('保存模板').click());
assert.ok(result.id);
// 从列表重新套用刚才写入的模板。
if (old) {
const got = page.waitForResponse(r => new URL(r.url()).pathname === '/api/order-templates/' + result.id);
await page.locator('#order-template-select').selectOption(result.id);
await got;
await page.locator('#order-template-panel:not([open]) summary').click();
} else {
await page.getByTestId('template-select').locator('.ant-select-selector').click();
await page.locator('.ant-select-item-option').filter({ hasText: '逐笔开单模板' }).click();
}
await btn('更新所选模板').click();
await nameField().fill('逐笔模板修改');
await write(ctx, page, '更新开单模板', '/api/order-templates/' + result.id + '/update', () =>
btn('保存更新').click(),
);
const remove = async () => {
await btn('删除模板').click();
if (!old) await btn(/^删\s*除$/, page.getByRole('dialog')).click();
};
await write(ctx, page, '删除开单模板', '/api/order-templates/' + result.id + '/delete', remove);
}