import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; import { Window } from 'happy-dom'; const readJson = async (name) => JSON.parse(await readFile(new URL(`../${name}`, import.meta.url), 'utf8')); test('the homepage mirror panel reports both trees at their synced size', async () => { const html = await readFile(new URL('../dist/index.html', import.meta.url), 'utf8'); const window = new Window(); window.document.write(html); const mirrors = window.document.querySelector('#mirrors'); assert.ok(mirrors, 'the mirrors band is missing from the homepage'); assert.match(mirrors.textContent, /PayloadsAllTheThings/); assert.match(mirrors.textContent, /InternalAllTheThings/); // The panel counts real collection entries, so it is where a sync becomes // visible. Assert it against the manifests the sync scripts write rather // than against hard-coded totals, which go stale on every sync. const rows = [...mirrors.querySelectorAll('.mirror-row')].map((row) => ({ path: row.querySelector('.path')?.textContent?.trim(), count: row.querySelector('.count')?.textContent?.trim(), })); const payloads = await readJson('payloads-manifest.json'); const internal = await readJson('internal-manifest.json'); assert.equal( rows.find((row) => row.path === 'payloads/')?.count, `${payloads.pages} files`, 'the payloads/ row disagrees with payloads-manifest.json', ); assert.equal( rows.find((row) => row.path === 'internal/')?.count, `${internal.pages} files`, 'the internal/ row disagrees with internal-manifest.json', ); });