screentinker/Examples/PIP-Fundraiser-Thermometer/test.js
screentinker 0b138f10c6
Add PiP overlay example recipes (#132)
Self-contained examples for the PiP overlay API (POST /api/pip), each
with a CSP-safe query-param overlay (external JS), config.example.json,
zero runtime deps, an offline test, and a README:

- PIP-Announce-Broadcast    manual one-shot message to a screen/group
- PIP-Weather-Widget        Open-Meteo current conditions (keyless)
- PIP-Air-Quality           Open-Meteo US AQI widget (keyless)
- PIP-Crypto-Ticker         CoinGecko price strip (keyless)
- PIP-News-Ticker           scrolling RSS/Atom headlines
- PIP-Room-Status-Calendar  ICS-driven Available/Busy room sign
- PIP-Event-Countdown       client-side countdown, auto-clears at zero
- PIP-Welcome-Board         rotating welcome/birthday cards from CSV
- PIP-Fundraiser-Thermometer goal-progress bar from local/URL JSON
- PIP-QR-Rotator            rotating QR codes, encoded client-side
- PIP-Incident-Webhook      event-driven: red on firing, clear on resolved

Also includes the CAP-AU (NSW RFS) and US NWS/NOAA emergency-alert
monitors that push expiry-aware PiP overlays.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 20:20:37 -05:00

55 lines
2.1 KiB
JavaScript

'use strict';
const t = require('./thermo');
const checks = [];
const eq = (name, got, want) => checks.push({ name, ok: got === want, got, want });
// money formatting
eq('formatMoney USD', t.formatMoney(12450, 'USD'), '$12,450');
eq('formatMoney EUR', t.formatMoney(12450, 'EUR'), '€12,450');
eq('formatMoney GBP', t.formatMoney(1234567, 'GBP'), '£1,234,567');
eq('formatMoney unknown code', t.formatMoney(2500, 'BTC'), 'BTC 2,500');
eq('formatMoney small', t.formatMoney(999, 'USD'), '$999');
eq('formatMoney rounds', t.formatMoney(12450.7, 'USD'), '$12,451');
eq('groupThousands', t.groupThousands(1000000), '1,000,000');
// progress
const p1 = t.computeProgress({ raised: 12450, goal: 20000 });
eq('pct 12450/20000', p1.pct, 62.25);
eq('pctLabel 12450/20000', p1.pctLabel, '62%');
const p2 = t.computeProgress({ raised: 25000, goal: 20000 });
eq('clamp over 100 pct', p2.pct, 100);
eq('clamp over 100 label', p2.pctLabel, '100%');
const p3 = t.computeProgress({ raised: 500, goal: 0 });
eq('goal 0 -> 0 pct', p3.pct, 0);
eq('goal 0 -> 0 label', p3.pctLabel, '0%');
const p4 = t.computeProgress({ raised: 0, goal: 20000 });
eq('zero raised', p4.pct, 0);
// normalise + uri
const v = t.normalise({ campaign: 'Community Garden', raised: 12450, goal: 20000, currency: 'USD' });
eq('normalise campaign', v.campaign, 'Community Garden');
eq('normalise raisedLabel', v.raisedLabel, '$12,450');
eq('normalise goalLabel', v.goalLabel, '$20,000');
eq('normalise pctLabel', v.pctLabel, '62%');
const uri = t.overlayUri('https://s/thermo-overlay.html', v);
const parsed = new URL(uri);
eq('uri campaign round-trips', parsed.searchParams.get('campaign'), 'Community Garden');
eq('uri raised round-trips', parsed.searchParams.get('raised'), '$12,450');
eq('uri pct round-trips', parsed.searchParams.get('pct'), '62.25');
let pass = 0;
for (const c of checks) {
console.log(`${c.ok ? '✓' : '✗'} ${c.name}` + (c.ok ? '' : ` got=${JSON.stringify(c.got)} want=${JSON.stringify(c.want)}`));
if (c.ok) pass++;
}
const ok = pass === checks.length;
console.log(`\n${pass}/${checks.length} checks`);
console.log('\nRESULT:', ok ? 'PASS ✅' : 'FAIL ❌');
process.exit(ok ? 0 : 1);