保留新版关店入口并在页面跳转前核对原始写入回执

This commit is contained in:
黄健铭 committed 2026-12-05 21:51:56 -08:00
1 parent 42395de23a
commit 81b1954b4c
4 files changed
+34 -9

No files matched your search

+22 -7
View File
@@ -93,14 +93,29 @@ async function exercise(dir, browser, useNext) {
await page.locator('input[name=password]').fill(password);
await page.locator('button[type=submit]').click();
await page.getByText('距离停止访问不足 5 分钟,请及时保存。').waitFor();
const openPages = [page];
if (useNext) {
// 已登录员工也能通过无尾斜杠的入口打开账本,闭店后应返回同一版登录页。
const bare = await context.newPage();
await bare.clock.install();
await bare.goto(base + '/next');
await bare.getByText('距离停止访问不足 5 分钟,请及时保存。').waitFor();
await bare.locator('#order-form').waitFor();
await bare.waitForLoadState('networkidle');
assert.equal(new URL(bare.url()).pathname, '/next');
openPages.push(bare);
}
now = at('2026-12-05', '02:00');
await page.clock.fastForward(61_000);
await page.locator('[data-standalone-login] select[name=member]').waitFor();
assert.deepEqual(await page.locator('select[name=member] option').evaluateAll(xs => xs.map(x => x.value)), [
'',
'owner',
]);
assert.equal(await page.locator('script[src]').count(), 0, '闭店后只加载轻量登录页');
for (const openPage of openPages) {
await openPage.clock.fastForward(61_000);
await openPage.locator('[data-standalone-login] select[name=member]').waitFor();
assert.equal(new URL(openPage.url()).pathname, useNext ? '/next/' : '/', '闭店后保留原界面入口');
assert.deepEqual(await openPage.locator('select[name=member] option').evaluateAll(xs => xs.map(x => x.value)), [
'',
'owner',
]);
assert.equal(await openPage.locator('script[src]').count(), 0, '闭店后只加载轻量登录页');
}
for (const route of ['/api/session', '/api/state', '/api/access-window', '/print/example'])
await check('闭店仍持员工会话 ' + route, 403, call(route, { cookie: staff }));
await check('闭店店主会话继续使用', 200, call('/api/session', { cookie: owner }), session);
+8
View File
@@ -74,6 +74,12 @@ async function run(browser, group, scenario, version, target = oldApp) {
if (previousPreload) process.env.E2E_MUTATION_REQUIRE = previousPreload;
else delete process.env.E2E_MUTATION_REQUIRE;
}
// 轻量登录页可在点击完成前整页跳转。按原 Request 留存交给浏览器的同一份 JSON 回执。
const writeResponses = new WeakMap();
function responseBody(request) {
assert.ok(writeResponses.has(request), '未捕获这笔 POST 的响应正文:' + request.url());
return writeResponses.get(request);
}
const contexts = new Map(),
pages = new Map(),
steps = {},
@@ -203,6 +209,7 @@ async function run(browser, group, scenario, version, target = oldApp) {
}
const record = pending.get(req);
const body = await res.json();
writeResponses.set(req, body);
record.response = normal.value(safeData(body));
finish(req, res.status());
await route.fulfill({ response: res });
@@ -251,6 +258,7 @@ async function run(browser, group, scenario, version, target = oldApp) {
server,
session,
pageFor,
responseBody,
step,
day,
passwords,
+2 -1
View File
@@ -20,7 +20,8 @@ export function write(ctx, page, label, endpoint, trigger, status = 200) {
trigger(),
]);
assert.equal(response.status(), status, label);
const result = ctx.responseBody(response.request());
await page.waitForLoadState('networkidle');
return response.json();
return result;
});
}
+2 -1
View File
@@ -10,7 +10,8 @@
if (leaving) return;
leaving = true;
document.documentElement.style.visibility = 'hidden';
location.replace(location.pathname.startsWith('/next/') ? '/next/' : '/');
const next = location.pathname === '/next' || location.pathname.startsWith('/next/');
location.replace(next ? '/next/' : '/');
}
function warn() {
if (document.getElementById('closing-warning')) return;