// `npm run unit` in web/ (`just check` runs it). import { strict as assert } from 'node:assert'; import { test } from 'node:test'; import { actionForm, areasOf, frameCss, layoutOf } from './frame.ts'; const call = { name: 'query', args: { method: 'test.aside' } }; test('a frame left out is drawn with every default', () => { assert.deepEqual(layoutOf(undefined), { rail: 600, sidebar: 1200, content: 600, wide: 935, aside: null }); }); test("a host's bands are drawn over the frame's, and a wide screen is never narrower than the column", () => { const layout = layoutOf({ bands: { rail: 700, sidebar: 1300 }, sizes: { content: 700, wide: 500 } }, { sidebar: 1400 }); assert.deepEqual(layout, { rail: 700, sidebar: 1400, content: 700, wide: 700, aside: null }); }); test('each band sets the navigation, from its start to before the next', () => { const css = frameCss(layoutOf(undefined)); assert.match(css, /@media \(max-width: 599\.98px\)\{:root\{--hud-frame-nav:0px;--hud-frame-bar-display:grid/); assert.match(css, /@media \(min-width: 600px\) and \(max-width: 1199\.98px\)\{:root\{--hud-frame-nav:72px;--hud-frame-bar-display:none/); assert.match(css, /@media \(min-width: 1200px\)\{:root\{--hud-frame-nav:245px/); assert.doesNotMatch(css, /hud-aside/); }); test('an aside shows beside the column from where the navigation, the column and it fit, never beside a wide screen that would not', () => { const css = frameCss(layoutOf({ aside: { call } })); // The rail's band: 72 + 600 + 320 = 992. assert.match(css, /@media \(min-width: 992px\) and \(max-width: 1199\.98px\)\{\.hud-frame\[data-measure="content"\]\{--hud-frame-aside-shown:320px\}/); // The sidebar's: 245 + 600 + 320 = 1165, under its start. assert.match(css, /@media \(min-width: 1200px\)\{\.hud-frame\[data-measure="content"\]/); assert.doesNotMatch(css, /data-measure="wide"/); // Where the room holds a wide screen and the aside, beside it too. assert.match(frameCss(layoutOf({ aside: { call, width: 200 }, sizes: { content: 900, wide: 900 } })), /@media \(min-width: 1345px\)\{\.hud-frame\[data-measure="wide"\]/); }); test("signed in beside the navigation, a Bar's button for the action's form is hidden; under the rail it shows", () => { const action = (compose: unknown) => ({ action: { label: 'Create', icon: 'imagePlus' as const, call: { name: 'query', args: { method: 'test.feed', compose } } } }); assert.equal(actionForm(action('New gallery')), 'New gallery'); assert.equal(actionForm(action(true)), null); assert.equal(actionForm(undefined), null); const hide = '.hud-frame[data-signed-in] button[data-bar-form="New gallery"]{display:none}'; const css = frameCss(layoutOf(undefined), 'New gallery'); assert.ok(css.includes(`@media (min-width: 600px) and (max-width: 1199.98px){:root{`) && css.split(hide).length === 3, css); assert.doesNotMatch(css.match(/@media \(max-width: 599\.98px\)\{[^@]*/)?.[0] ?? '', /data-bar-form/); assert.doesNotMatch(frameCss(layoutOf(undefined)), /data-bar-form/); // Its label as CSS writes it, never ending the page's ').includes('[data-bar-form="a\\22 b\\5c \\3c /style>"]')); }); test("each measure's area is its width right of the navigation in its band, the window's in the bar's", () => { const areas = areasOf(layoutOf(undefined)); assert.equal(areas.content, '(min-width: 1200px) min(600px, 100vw - 245px), (min-width: 600px) min(600px, 100vw - 72px), 100vw'); assert.equal(areas.wide, '(min-width: 1200px) min(935px, 100vw - 245px), (min-width: 600px) min(935px, 100vw - 72px), 100vw'); assert.equal(areas.full, '(min-width: 1200px) min(100vw - 245px, 50vw + 345px), (min-width: 600px) min(100vw - 72px, 50vw + 431.5px), 100vw'); });