Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/verify_drawerclosed.mjs

2.8 KiB, 1 run

created by r2519314175:383, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// Does signing in leave the Admin drawer alone?
2//
3// It did not. `afterUnlock` called `DaimondAdmin.home()` to bring the account's
4// controls up to date, and that one call both RENDERED the home view and
5// SUMMONED the drawer -- so every sign-in ended with Admin standing open over
6// the app, whatever the user had done with it last time. The drawer is a
7// transient surface by its own stylesheet's account: summoned, and gone again
8// when finished.
9//
10// The test signs in a SECOND time, after a reload, because that is the
11// complaint: not that the drawer opens, but that closing it does not stick
12// across a session. It also proves the cog still opens it and clicking away
13// still shuts it -- a test that only looked for "closed" would pass just as
14// well against a drawer that had stopped working altogether.
15//
16// `open()` itself leaves the drawer open: `connectMock` drives the model form
17// through the cog and does not put it away. That is the harness, not the app,
18// so the state is normalised before anything is asserted.
19import { open, shot, signInAs } from './harness.mjs';
20
21const s = await open({ name: 'drawerclosed' });
22const { page } = s;
23let bad = 0;
24const check = (ok, what) => { console.log(`${ok ? 'PASS' : 'FAIL'} ${what}`); if (!ok) bad++; };
25
26const drawerOpen = () => page.evaluate(() => {
27 const a = document.getElementById('admin');
28 return !!(a && a.classList.contains('admin-open'));
29});
30// The dismissal the drawer documents (`outsideClose`), which listens for
31// mousedown rather than click.
32const clickAway = async () => {
33 await page.evaluate(() => {
34 document.body.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
35 });
36 await page.waitForTimeout(400);
37};
38
39// ── Normalise: put away whatever the harness left open ──────────────────────
40await clickAway();
41check((await drawerOpen()) === false, 'clicking away shuts the drawer');
42
43// ── The complaint: close it, come back, and find it open again ──────────────
44await page.reload({ waitUntil: 'domcontentloaded' });
45await page.waitForTimeout(800);
46await signInAs(s, 'drawer');
47await page.waitForTimeout(1000);
48check((await drawerOpen()) === false,
49 'signing in again does NOT reopen the drawer');
50
51// ── The other half: it must still be reachable and still render ─────────────
52await page.click('#settings-btn', { force: true });
53await page.waitForTimeout(700);
54check((await drawerOpen()) === true, 'the cog still opens it');
55
56const sections = await page.$$eval('.admin-sec', els => els.map(e => e.textContent.trim()));
57console.log('drawer sections:', JSON.stringify(sections));
58check(sections.filter(Boolean).length > 0,
59 'the home view still renders its sections');
60
61await shot(s, 'drawer-closed');
62console.log(bad ? `\n${bad} FAILED` : '\nall passed');
63process.exit(bad ? 1 : 0);