import assert from 'node:assert/strict'; import { action, navigate, write, fill, submit } from './ui.mjs'; export default async function report(ctx) { const owner = await ctx.pageFor('owner'); const staff = await ctx.pageFor('assistant'); async function formSubmit(page, form, label, suffix) { return ctx.step(label, async () => { const [res] = await Promise.all([ page.waitForResponse(r => r.request().method() === 'POST' && new URL(r.url()).pathname.endsWith(suffix)), submit(form), ]); assert.equal(res.status(), 200, label + ' ' + (await res.text())); await page.waitForLoadState('networkidle'); }); } for (const [page, role] of [ [staff, '店员'], [owner, '店主'], ]) { await navigate(page, ctx.version, 'report'); await action(page, 'reimbursement-new').click(); const form = page.locator('#reimbursement-form'); await fill(form, { itemName: role + '运费', itemAmount: '12.30' }); await write(ctx, page, role + '新增报销', '/api/reimbursements', () => submit(form)); await action(page, 'reimbursement-edit').click(); await fill(form, { itemAmount: '12.35' }); await formSubmit(page, form, role + '修改报销', '/update'); } for (const [verb, title] of [ ['reject', '驳回'], ['approve', '同意'], ]) { await action(owner, 'reimbursement-' + verb).click(); const form = owner.locator('#reimbursement-review-form'); if (verb === 'reject') await fill(form, { note: '缺少原票' }); else await form.locator('[name=verified]').check(); await formSubmit(owner, form, title + '报销', '/' + verb); } // 服务端启动即迁移为团队账本。完整对外支出只在旧双人账务模式渲染。 assert.equal(await owner.locator('#daily-outlay-form').count(), 0); await write(ctx, owner, '保存当日对账', '/api/close', () => action(owner, 'close-day').click()); }