import test from 'node:test'; import assert from 'node:assert/strict'; import { createDraft, draftNotice, isDraftDirty } from '../src/draft.js'; test('a fresh draft is empty and reports nothing to resume', () => { const draft = createDraft(); assert.equal(isDraftDirty(draft), false); assert.equal(draftNotice(draft), ''); assert.equal(draft.bristolType, 4); assert.equal(draft.color, 'brown'); assert.deepEqual(draft.symptoms, {}); }); test('a fresh draft is independent so one log cannot leak into the next', () => { const first = createDraft(); first.symptoms.blood = true; first.note = 'leaked'; const second = createDraft(); assert.equal(second.symptoms.blood, undefined); assert.equal(second.note, ''); assert.equal(isDraftDirty(second), false); }); test('any user-entered context makes the draft worth resuming', () => { const cases = [ [{ typeChosen: true, bristolType: 6 }, /type 6/i], [{ note: 'After lunch' }, /note/i], [{ urgency: 3 }, /urgency/i], [{ discomfort: 2 }, /discomfort/i], [{ photoDataUrl: 'data:image/jpeg;base64,abc' }, /photo/i], [{ symptoms: { blood: true } }, /symptom/i], ]; for (const [patch, expected] of cases) { const draft = { ...createDraft(), ...patch }; assert.equal(isDraftDirty(draft), true, JSON.stringify(patch)); assert.match(draftNotice(draft), expected); } }); test('untouched defaults are not treated as user context', () => { assert.equal(isDraftDirty({ ...createDraft(), bristolType: 7 }), false); assert.equal(isDraftDirty({ ...createDraft(), color: 'brown', urgency: 0, discomfort: 0, note: ' ' }), false); assert.equal(draftNotice({ ...createDraft(), color: 'brown' }), ''); }); test('a changed color is user context and unconfirmed AI defaults are not', () => { assert.equal(isDraftDirty({ ...createDraft(), color: 'black' }), true); assert.match(draftNotice({ ...createDraft(), color: 'black' }), /color/i); }); test('draft copy never implies the photo or note left this device', () => { const notice = draftNotice({ ...createDraft(), typeChosen: true, photoDataUrl: 'data:image/jpeg;base64,abc', note: 'x' }); assert.doesNotMatch(notice, /upload|server|sent|cloud/i); });