import assert from 'node:assert/strict'; import test from 'node:test'; import { Window } from 'happy-dom'; test('callouts are typed from a marker or a leading emoji, and unlabelled code stays unlabelled', async () => { const window = new Window({ url: 'https://example.test/sheets/active-directory/certipy' }); globalThis.window = window; globalThis.document = window.document; globalThis.localStorage = window.localStorage; // app.ts reads `NodeFilter` as a bare global, as a browser provides it. globalThis.NodeFilter = window.NodeFilter; document.body.innerHTML = `

[!warning]+ Check the clock first.

⚠️ Server 2022: stricter defaults.

💡 Use the RC4 hash.

[!opsec] Loud on the wire.

Hash format you will see.

1. Gain a foothold
id
`; await import('../src/scripts/app.ts'); const callout = (id) => { const el = document.getElementById(id); return [el.dataset.callout ?? null, el.querySelector('.callout__label')?.textContent ?? null, el.querySelector('p').textContent]; }; assert.deepEqual(callout('marker'), ['warning', 'Warning', 'Check the clock first.']); assert.deepEqual(callout('emoji'), ['warning', 'Warning', 'Server 2022: stricter defaults.'], 'the emoji and its selector are dropped'); assert.deepEqual(callout('tip'), ['tip', 'Tip', 'Use the RC4 hash.']); assert.deepEqual(callout('custom'), ['note', 'opsec', 'Loud on the wire.'], 'an unknown type keeps the author\'s word as its label'); assert.deepEqual(callout('plain'), [null, null, 'Hash format you will see.']); const labels = [...document.querySelectorAll('.code-pane__lang')].map((el) => el.textContent); assert.deepEqual(labels, ['', 'bash']); assert.equal(document.querySelectorAll('.code-pane .code-copy').length, 2, 'the copy control is there either way'); }); test('pressing Copy copies the listing, confirms it on the block, and puts everything back', async () => { // Runs in the document the test above set up; app.ts is already bound. let clipboard = null; Object.defineProperty(globalThis, 'navigator', { value: { clipboard: { writeText: async (text) => { clipboard = text; } } }, configurable: true, }); const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const pane = [...document.querySelectorAll('.code-pane')].at(-1); const copy = pane.querySelector('.code-copy'); const word = pane.querySelector('.code-copy__word'); assert.equal(word.textContent, 'Copy'); assert.ok(pane.querySelector('.code-pane__sweep'), 'the sweep line is in the pane, waiting'); copy.click(); await wait(20); assert.equal(clipboard, 'id'); assert.equal(pane.classList.contains('is-copied'), true); assert.equal(copy.classList.contains('copied'), true); assert.equal(copy.getAttribute('aria-label'), 'Copied', 'the accessible name never passes through the scramble'); assert.notEqual(word.textContent, 'Copied', 'the visible word is still settling'); assert.equal(word.textContent.length, 'Copied'.length); await wait(420); assert.equal(word.textContent, 'Copied'); // A second press mid-confirmation restarts the clock rather than cutting it short. copy.click(); await wait(1500); assert.equal(pane.classList.contains('is-copied'), true); await wait(400); assert.equal(word.textContent, 'Copy'); assert.equal(copy.getAttribute('aria-label'), 'Copy'); assert.equal(pane.classList.contains('is-copied'), false); assert.equal(copy.classList.contains('copied'), false); });