53 lines
2.8 KiB
JavaScript
53 lines
2.8 KiB
JavaScript
// Pinning the chat dock: dragging its header to an edge pins it there and the
|
|
// page reflows beside it; double-clicking the header unpins it; hiding the
|
|
// conversation gives the page back its width; the choice survives a reload.
|
|
const assert = require('node:assert/strict');
|
|
const h = require('./helpers/chat-dock.cjs');
|
|
|
|
module.exports = async ({ page, go, shot }) => {
|
|
await h.load(page, go);
|
|
await h.expand(page);
|
|
const dock = h.dockOf(page);
|
|
const free = await h.mainRect(page);
|
|
const floating = await dock.boundingBox();
|
|
assert.ok(floating.height < 900, 'the dock starts as a floating card');
|
|
|
|
await h.dragTo(page, 1430);
|
|
await page.mouse.up();
|
|
await h.until(async () => (await h.saved(page)).side === 'right', 'dragging to the right edge did not pin right');
|
|
const right = await dock.boundingBox();
|
|
h.near(right.x + right.width, 1440, 'right pin touches the right edge');
|
|
h.near(right.height, 900, 'a pinned dock is full height');
|
|
const reflowed = await h.mainRect(page);
|
|
assert.ok(reflowed.x + reflowed.width <= right.x + 1, `page content runs under the pinned dock: ${reflowed.x + reflowed.width} > ${right.x}`);
|
|
assert.ok(reflowed.width < free.width, 'the page did not give up any width');
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth), 'pinning made the page scroll sideways');
|
|
await shot('pinned-right');
|
|
|
|
await page.reload();
|
|
await h.expand(page);
|
|
await h.until(async () => Math.abs((await dock.boundingBox()).x - right.x) <= 1, 'the right pin did not survive a reload');
|
|
|
|
await h.hideOf(page).click();
|
|
await h.until(async () => Math.abs((await h.mainRect(page)).width - free.width) <= 1, 'hiding the conversation kept the page narrowed');
|
|
await h.expand(page);
|
|
await h.until(async () => Math.abs((await dock.boundingBox()).x - right.x) <= 1, 'reopening did not restore the pin');
|
|
|
|
const strip = await h.grip(page);
|
|
await page.mouse.dblclick(strip.x, strip.y);
|
|
await h.until(async () => (await h.saved(page)).side === null, 'double-clicking the header did not unpin');
|
|
assert.ok((await dock.boundingBox()).height < 900, 'an unpinned dock is a floating card again');
|
|
h.near((await h.mainRect(page)).width, free.width, 'the page returns to its full width');
|
|
|
|
await h.dragTo(page, 10);
|
|
await page.mouse.up();
|
|
await h.until(async () => (await h.saved(page)).side === 'left', 'dragging to the left edge did not pin left');
|
|
const left = await dock.boundingBox();
|
|
h.near(left.x, 0, 'left pin touches the left edge');
|
|
assert.ok((await h.mainRect(page)).x >= left.x + left.width - 1, 'page content runs under the left-pinned dock');
|
|
await shot('pinned-left');
|
|
|
|
await page.mouse.dblclick((await h.grip(page)).x, (await h.grip(page)).y);
|
|
await h.until(async () => (await h.saved(page)).side === null, 'double-clicking did not unpin the left pin');
|
|
};
|