47 lines
2.2 KiB
JavaScript
47 lines
2.2 KiB
JavaScript
// The saved dock layout: a stored mode and width are honoured, widths outside
|
|
// the allowed range are clamped, unreadable JSON falls back to a usable
|
|
// floating dock that saves again, and visiting phone width never overwrites
|
|
// the desktop choice.
|
|
const assert = require('node:assert/strict');
|
|
const h = require('./helpers/chat-dock.cjs');
|
|
|
|
module.exports = async ({ page, go, shot, tolerate }) => {
|
|
tolerate(/JSON|SyntaxError/);
|
|
const dock = h.dockOf(page);
|
|
|
|
await h.load(page, go, JSON.stringify({ mode: 'left', w: 500 }));
|
|
await h.expand(page);
|
|
let box = await dock.boundingBox();
|
|
h.near(box.x, 0, 'saved left pin');
|
|
h.near(box.width, 500, 'saved width');
|
|
assert.ok((await h.mainRect(page)).x >= 499, 'page did not reflow beside the restored dock');
|
|
|
|
await h.load(page, go, JSON.stringify({ mode: 'right', w: -4 }));
|
|
await h.expand(page);
|
|
h.near((await dock.boundingBox()).width, 320, 'a negative width clamps to the minimum');
|
|
|
|
await h.load(page, go, JSON.stringify({ mode: 'right', w: 9999 }));
|
|
await h.expand(page);
|
|
h.near((await dock.boundingBox()).width, 720, 'a huge width clamps to the maximum');
|
|
|
|
await h.load(page, go, '{broken');
|
|
await h.expand(page);
|
|
box = await dock.boundingBox();
|
|
assert.ok(box.height < 900 && box.x > 0 && box.x + box.width < 1440, 'unreadable layout did not fall back to a floating dock');
|
|
await h.composerOf(page).fill('still usable');
|
|
await h.dragTo(page, 1430);
|
|
await page.mouse.up();
|
|
await h.until(async () => (await h.saved(page)).mode === 'right', 'the dock did not save a layout over the unreadable one');
|
|
await shot('recovered');
|
|
|
|
await h.load(page, go, JSON.stringify({ mode: 'left', w: 460 }));
|
|
const layout = await h.stored(page);
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await h.expand(page);
|
|
box = await dock.boundingBox();
|
|
assert.ok(box.x >= 0 && box.x + box.width <= 390, 'the dock overflows the phone viewport');
|
|
await page.setViewportSize({ width: 1440, height: 900 });
|
|
assert.equal(await h.stored(page), layout, 'visiting phone width rewrote the saved layout');
|
|
await h.until(async () => Math.abs((await dock.boundingBox()).width - 460) <= 1, 'the desktop layout did not return after phone width');
|
|
};
|