保留新版关店入口并在页面跳转前核对原始写入回执
This commit is contained in:
1 parent
42395de23a
commit
81b1954b4c
4 files changed
+31
-6
No files matched your search
@@ -93,14 +93,29 @@ async function exercise(dir, browser, useNext) {
|
|||||||
await page.locator('input[name=password]').fill(password);
|
await page.locator('input[name=password]').fill(password);
|
||||||
await page.locator('button[type=submit]').click();
|
await page.locator('button[type=submit]').click();
|
||||||
await page.getByText('距离停止访问不足 5 分钟,请及时保存。').waitFor();
|
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');
|
now = at('2026-12-05', '02:00');
|
||||||
await page.clock.fastForward(61_000);
|
for (const openPage of openPages) {
|
||||||
await page.locator('[data-standalone-login] select[name=member]').waitFor();
|
await openPage.clock.fastForward(61_000);
|
||||||
assert.deepEqual(await page.locator('select[name=member] option').evaluateAll(xs => xs.map(x => x.value)), [
|
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',
|
'owner',
|
||||||
]);
|
]);
|
||||||
assert.equal(await page.locator('script[src]').count(), 0, '闭店后只加载轻量登录页');
|
assert.equal(await openPage.locator('script[src]').count(), 0, '闭店后只加载轻量登录页');
|
||||||
|
}
|
||||||
for (const route of ['/api/session', '/api/state', '/api/access-window', '/print/example'])
|
for (const route of ['/api/session', '/api/state', '/api/access-window', '/print/example'])
|
||||||
await check('闭店仍持员工会话 ' + route, 403, call(route, { cookie: staff }));
|
await check('闭店仍持员工会话 ' + route, 403, call(route, { cookie: staff }));
|
||||||
await check('闭店店主会话继续使用', 200, call('/api/session', { cookie: owner }), session);
|
await check('闭店店主会话继续使用', 200, call('/api/session', { cookie: owner }), session);
|
||||||
|
|||||||
@@ -74,6 +74,12 @@ async function run(browser, group, scenario, version, target = oldApp) {
|
|||||||
if (previousPreload) process.env.E2E_MUTATION_REQUIRE = previousPreload;
|
if (previousPreload) process.env.E2E_MUTATION_REQUIRE = previousPreload;
|
||||||
else delete process.env.E2E_MUTATION_REQUIRE;
|
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(),
|
const contexts = new Map(),
|
||||||
pages = new Map(),
|
pages = new Map(),
|
||||||
steps = {},
|
steps = {},
|
||||||
@@ -203,6 +209,7 @@ async function run(browser, group, scenario, version, target = oldApp) {
|
|||||||
}
|
}
|
||||||
const record = pending.get(req);
|
const record = pending.get(req);
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
writeResponses.set(req, body);
|
||||||
record.response = normal.value(safeData(body));
|
record.response = normal.value(safeData(body));
|
||||||
finish(req, res.status());
|
finish(req, res.status());
|
||||||
await route.fulfill({ response: res });
|
await route.fulfill({ response: res });
|
||||||
@@ -251,6 +258,7 @@ async function run(browser, group, scenario, version, target = oldApp) {
|
|||||||
server,
|
server,
|
||||||
session,
|
session,
|
||||||
pageFor,
|
pageFor,
|
||||||
|
responseBody,
|
||||||
step,
|
step,
|
||||||
day,
|
day,
|
||||||
passwords,
|
passwords,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export function write(ctx, page, label, endpoint, trigger, status = 200) {
|
|||||||
trigger(),
|
trigger(),
|
||||||
]);
|
]);
|
||||||
assert.equal(response.status(), status, label);
|
assert.equal(response.status(), status, label);
|
||||||
|
const result = ctx.responseBody(response.request());
|
||||||
await page.waitForLoadState('networkidle');
|
await page.waitForLoadState('networkidle');
|
||||||
return response.json();
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
if (leaving) return;
|
if (leaving) return;
|
||||||
leaving = true;
|
leaving = true;
|
||||||
document.documentElement.style.visibility = 'hidden';
|
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() {
|
function warn() {
|
||||||
if (document.getElementById('closing-warning')) return;
|
if (document.getElementById('closing-warning')) return;
|
||||||
|
|||||||
Reference in new issue
Block a user