Files
Void-Homelab/tests/frontend/card_contract.test.js
root b82b90d2f5 fix(sacred-valley): review polish — render-gen guard, auth-boundary tests, PNG sig, dedup note
Addresses final-review findings: I1 render-generation guard prevents a double-mount
/timer leak on rapid re-navigation; I2 adds anonymous-rejection tests for the owner-only
POST /speedtest/run and /health/check; M1 CSS comment; M2 cron↔worker dedup note;
M4 full 8-byte PNG signature check; M5 card-contract unit test for all 7 cards.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 23:20:14 +10:00

32 lines
1.4 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import clock from '../../public/views/cards/clock.js';
import weather from '../../public/views/cards/weather.js';
import hostPerf from '../../public/views/cards/host_perf.js';
import jobs from '../../public/views/cards/jobs.js';
import inbox from '../../public/views/cards/inbox.js';
import search from '../../public/views/cards/search.js';
import speedtest from '../../public/views/cards/speedtest.js';
// Every data card must satisfy the uniform contract that sacred_valley.js relies
// on: { id, title, size: s|m|l, mount(), start(), stop() }. Importing the modules
// is safe in node — their browser globals (document/localStorage/fetch) are only
// touched inside mount()/load(), which this test never calls.
const cards = { clock, weather, hostPerf, jobs, inbox, search, speedtest };
describe('card contract', () => {
for (const [name, c] of Object.entries(cards)) {
it(`${name} implements the card contract`, () => {
expect(typeof c.id).toBe('string');
expect(typeof c.title).toBe('string');
expect(['s', 'm', 'l']).toContain(c.size);
expect(typeof c.mount).toBe('function');
expect(typeof c.start).toBe('function');
expect(typeof c.stop).toBe('function');
});
}
it('all card ids are unique', () => {
const ids = Object.values(cards).map(c => c.id);
expect(new Set(ids).size).toBe(ids.length);
});
});