import assert from 'node:assert/strict'; import { JSDOM } from 'jsdom'; const HTML = `
`; const dom = new JSDOM(HTML, { url: 'http://localhost/' }); global.window = dom.window; global.document = dom.window.document; global.localStorage = dom.window.localStorage; dom.window.alert = () => {}; global.alert = () => {}; // Seed malformed persisted state BEFORE app.js loads: // - an employee with no constraints (would crash plan generation if not normalized) // - an out-of-range moderatorsPerDay localStorage.setItem('morning-planner-state', JSON.stringify({ employees: [{ id: 'x', name: 'NoConstraints' }], calendar: { holidays: [], companyClosures: [] }, history: [], settings: { moderatorsPerDay: 99 } })); const { state } = await import('../js/app.js'); // Employee is loaded but normalized (constraints filled) so nothing crashes later assert.equal(state.employees.length, 1, 'employee loaded from storage'); assert.ok(Array.isArray(state.employees[0].constraints.neverDays), 'missing constraints normalized'); assert.equal(state.employees[0].constraints.minGapDays, 14, 'minGapDays defaulted'); // Invalid moderatorsPerDay (99) falls back to the valid default assert.equal(state.settings.moderatorsPerDay, 1, 'out-of-range setting falls back to 1'); // Rendering the employee tab with the normalized data does not throw assert.ok(document.getElementById('emp-name-input'), 'app rendered after recovering from malformed state'); console.log('All persistence tests passed.');