import { describe, expect, it } from 'vitest'; import { formatRationale, splitSentences } from '../shared/rationale.ts'; describe('rationale layout', () => { it('keeps decimals and abbreviations inside a sentence', () => { expect(splitSentences('Give 2.5 mg now, e.g. with food. Recheck the level in 6 hr. Then report it.')).toEqual(['Give 2.5 mg now, e.g. with food.', 'Recheck the level in 6 hr. Then report it.']); }); it('breaks a long paragraph into a lead sentence and short paragraphs', () => { const brick = 'Potassium of 2.9 mEq/L is hypokalemia caused by loop-diuretic potassium loss. It explains the cramps, weakness and palpitations the client reports. Hypokalemia destabilises cardiac membranes and can cause dysrhythmias. This is more dangerous in a client who also takes digoxin. The nurse notifies the provider and anticipates potassium replacement. The weight loss and urine output show the drug is working as intended.'; const out = formatRationale(brick); const blocks = out.split('\n\n'); expect(blocks[0]).toBe('**Potassium of 2.9 mEq/L is hypokalemia caused by loop-diuretic potassium loss.**'); expect(blocks.length).toBeGreaterThanOrEqual(3); expect(out.replace(/\*\*/g, '').replace(/\s+/g, ' ')).toBe(brick); }); it('turns a walk-through of the choices into a list', () => { const brick = 'The priority is airway, so suctioning comes first in this situation for the client. Option A is wrong because repositioning does not clear secretions. It also delays care. Option B is wrong because oxygen will not help a blocked airway. Option D can wait until the airway is clear and the client is stable. The nurse reassesses breath sounds after suctioning.'; const out = formatRationale(brick); expect(out).toMatch(/\n- Option A is wrong because repositioning does not clear secretions\. It also delays care\.\n/); expect(out).toMatch(/\n- Option B is wrong/); // A closing sentence on a new subject ends the list. expect(out).toMatch(/stable\.\n\nThe nurse reassesses/); }); it('leaves short or already structured rationales alone', () => { expect(formatRationale('Short and clear.')).toBe('Short and clear.'); const md = '**Furosemide is a loop diuretic.**\n\n- Check potassium before each dose and report any low value.\n- Weigh daily at the same time with the same scale and clothing.\n- Give it in the morning to prevent nocturia and falls overnight at home.'; expect(formatRationale(md)).toBe(md); }); });