| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import assert from 'node:assert/strict';
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
- import { chromium } from 'playwright';
- const accounts = JSON.parse(await readFile(new URL('../../.work/frontend-accounts.json', import.meta.url), 'utf8'));
- const base = process.env.FRONTEND_URL || 'http://127.0.0.1:18763';
- const browser = await chromium.launch({ headless: true, executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE });
- const page = await browser.newPage();
- const errors = [];
- page.on('pageerror', error => errors.push(error.message));
- async function route(path) {
- await page.evaluate(value => { location.hash = `/${value}`; }, path);
- await page.waitForURL(new RegExp(`#/${path}$`));
- await page.waitForFunction(() => !document.querySelector('.mobile .content[aria-busy="true"], .merchant-loading'));
- }
- try {
- await page.goto(`${base}/#/customer/login`);
- await page.getByLabel('账户', { exact: true }).fill('customer01');
- await page.getByLabel('密码', { exact: true }).fill(accounts.password);
- await page.getByRole('checkbox').check();
- await page.getByRole('button', { name: '登录并继续' }).click();
- await page.waitForURL('**/#/customer/chat');
- await route('customer/orders');
- await page.locator('.order-card').filter({ hasText: accounts.order_id }).getByRole('button', { name: '申请售后', exact: true }).click();
- await page.waitForURL('**/#/customer/apply');
- await page.getByLabel('故障描述').fill('保留给消费者本人检查的未提交内容');
- // 同一个页面切换入口,商家必须通过真实接口自行选择业务上下文。
- await page.getByRole('button', { name: '商家后台', exact: true }).click();
- const panel = page.locator('.login-panel');
- await panel.getByLabel('商家标识').fill(accounts.tenant_id);
- await panel.getByLabel('员工账户').fill('staff01');
- await panel.getByLabel('密码', { exact: true }).fill(accounts.password);
- await panel.getByRole('button', { name: '登录', exact: true }).click();
- await page.waitForURL('**/#/merchant/service/queue');
- await route('merchant/service/conversation');
- await page.getByText('请选择需要处理的会话。', { exact: true }).waitFor();
- assert.equal(await page.getByRole('heading', { name: '当前客户订单', exact: true }).count(), 0);
- await page.locator('.admin-session').getByRole('button', { name: '退出登录', exact: true }).click();
- await page.getByRole('dialog').getByRole('button', { name: '确认操作', exact: true }).click();
- await panel.waitFor();
- await route('customer/apply');
- assert.equal(await page.getByLabel('故障描述').inputValue(), '保留给消费者本人检查的未提交内容');
- assert.equal(await page.getByLabel('申请数量', { exact: true }).inputValue(), '1');
- assert.deepEqual(errors, []);
- await mkdir(new URL('../../.work/frontend-verification/', import.meta.url), { recursive: true });
- await writeFile(new URL('../../.work/frontend-verification/entry-isolation.json', import.meta.url), JSON.stringify({ date: new Date().toISOString(), checks: ['消费者与客服业务上下文独立', '商家退出后消费者身份和未提交内容保持'], browserErrors: errors, generatedModelCalls: 0 }, null, 2));
- console.log('同页面入口切换及身份数据隔离检查通过。');
- } finally {
- await browser.close();
- }
|