Files
codex-bot 1a3a2566e3 SUNDIAL solar dial v0.3: round screen, NOAA solar math, day/night arc
- 466px round layout, designWidth 466 (S4 41mm 466x466)
- solar position + dayProgress in src/common/solar.js (pure, TDD'd)
- sunrise/sunset sweep, night moon, countdown, 30s refresh
- tests: solar math, page logic, circle geometry/contrast
2026-09-09 15:09:14 +01:00

47 lines
1.9 KiB
JavaScript

// Test the page's update() logic: clock, phase, angle mapping, countdown wiring.
const fs = require('node:fs');
const assert = require('node:assert/strict');
const solar = require('../src/common/solar.js');
const ux = fs.readFileSync('src/pages/index/index.ux', 'utf8');
const script = ux.match(/<script>([\s\S]*?)<\/script>/)[1];
// strip imports, provide solar as global
const body = script.replace(/import\s+solar\s+from\s+'[^']*';?/, '');
const sandbox = { solar, setInterval: () => 0, clearInterval: () => {}, Date, Math, String, Number, console };
const vm = require('node:vm');
const ctx = vm.createContext(sandbox);
sandbox.spec = vm.runInContext('(' + body.replace('export default', '') + ')', ctx);
const spec = sandbox.spec;
function mk() {
const o = Object.assign({}, JSON.parse(JSON.stringify(spec.private || {})));
for (const k in spec) if (k !== 'private' && k !== 'computed') o[k] = spec[k].bind(o);
o.$element = () => null;
spec.onInit.call(o);
return o;
}
// midday Paris: DAY, angle between -90 and +90, countdown mentions sunset
let c = mk();
let fixedNow = new Date('2026-09-09T12:00:00Z');
const realDate = Date;
class FakeDate extends realDate {
constructor(...args) { super(...(args.length ? args : [fixedNow])); }
static now() { return fixedNow.getTime(); }
}
sandbox.Date = FakeDate;
c.update();
assert.match(c.clock, /^\d{2}:\d{2}$/);
assert.equal(c.isDay, true, 'Paris noon is day');
assert.ok(c.sunAngle > -90 && c.sunAngle < 90, `day angle within upper arc, got ${c.sunAngle}`);
assert.match(c.countdown, /sunset in/);
// night: angle in lower arc, countdown mentions sunrise
fixedNow = new Date('2026-09-09T22:00:00Z');
c.update();
assert.equal(c.isDay, false, 'Paris 22:00Z is night');
assert.ok(c.sunAngle < -90 || c.sunAngle > 90, `night angle in lower arc, got ${c.sunAngle}`);
assert.match(c.countdown, /sunrise in/);
console.log('PAGE LOGIC PASS (day arc, night arc, countdowns)');