// ============================================================ // CALCULATORS (React port) — sub-nav shell smoke test. // // Pure shell test until test vectors + formula ports land in // dedicated follow-up commits. // ============================================================ const { test, expect, E2E_BASE } = require('../fixtures'); const EXPECTED_PILLS = [ 'bp', 'bmi', 'growth', 'bili', 'vitals', 'bsa', 'dose', 'resus', 'gcs', 'equipment', ]; async function openReactCalc(page) { await page.goto(E2E_BASE + '/app/calculators'); await page.waitForSelector('[data-testid="calc-subnav"]', { timeout: 15000 }); } test.describe('React Calculators — sub-nav shell', () => { test('all 10 pills render in expected order', async ({ authedPage: _, page }) => { await openReactCalc(page); for (const id of EXPECTED_PILLS) { await expect(page.locator('[data-testid="calc-pill-' + id + '"]')).toBeVisible(); } }); test('clicking a pill switches the active panel', async ({ authedPage: _, page }) => { await openReactCalc(page); await expect(page.locator('[data-testid="calc-panel-bp"]')).toBeVisible(); await page.click('[data-testid="calc-pill-bili"]'); await expect(page.locator('[data-testid="calc-panel-bili"]')).toBeVisible(); }); test('each panel carries a legacy-viewer link', async ({ authedPage: _, page }) => { await openReactCalc(page); await expect(page.getByText('Open in legacy viewer').first()).toBeVisible(); }); test('BSA calculator runs in React', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-bsa"]'); await page.fill('#react-bsa-weight', '20'); await page.fill('#react-bsa-height', '110'); await page.click('[data-testid="calc-bsa-calculate"]'); await expect(page.locator('[data-testid="calc-bsa-result"]')).toContainText('0.782'); }); test('weight-based dose calculator caps max dose', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-dose"]'); await page.fill('#react-dose-weight', '15'); await page.fill('#react-dose-per-kg', '100'); await page.fill('#react-dose-max', '500'); await page.click('[data-testid="calc-dose-calculate"]'); await expect(page.locator('[data-testid="calc-dose-result"]')).toContainText('500.0 mg'); await expect(page.locator('[data-testid="calc-dose-result"]')).toContainText('Capped'); }); test('GCS calculator updates score from selected components', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-gcs"]'); await expect(page.locator('[data-testid="calc-gcs-result"]')).toContainText('GCS: 15/15'); await page.selectOption('#react-gcs-motor', '1'); await expect(page.locator('[data-testid="calc-gcs-result"]')).toContainText('GCS: 10/15'); }); test('AAP 2022 bilirubin classifies above exchange correctly', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-bili"]'); // 38w low-risk at 72h: phototherapy threshold = 18.8, exchange = 25.9. // TSB 20 should be "Above Phototherapy"; 26 should be "Above Exchange". await page.selectOption('#bili-ga', '38'); await page.selectOption('#bili-risk', 'low'); await page.fill('#bili-hours', '72'); await page.fill('#bili-tsb', '20'); await page.click('[data-testid="calc-bili-calculate"]'); await expect(page.locator('[data-testid="calc-bili-aap-result"]')).toContainText('Above Phototherapy'); await expect(page.locator('[data-testid="calc-bili-aap-result"]')).toContainText('18.8'); await page.fill('#bili-tsb', '26'); await page.click('[data-testid="calc-bili-calculate"]'); await expect(page.locator('[data-testid="calc-bili-aap-result"]')).toContainText('Above Exchange'); }); test('Bhutani nomogram classifies high-risk zone', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-bili"]'); await page.click('[data-testid="bili-mode-bhutani"]'); // At 36h, p95 = 12.8 — TSB 13 should land in High-Risk. await page.fill('#bili-hours', '36'); await page.fill('#bili-tsb', '13'); await page.click('[data-testid="calc-bili-calculate"]'); await expect(page.locator('[data-testid="calc-bili-bhutani-result"]')).toContainText('High-Risk Zone'); }); test('Fenton growth classifies 32w male 1795g as AGA (50th percentile)', async ({ authedPage: _, page }) => { await openReactCalc(page); await page.click('[data-testid="calc-pill-growth"]'); // 32w male median is 1795g — should land right at 50th percentile. await page.selectOption('#fenton-sex', 'male'); await page.fill('#fenton-ga', '32'); await page.fill('#fenton-weight', '1795'); await page.click('[data-testid="calc-fenton-calculate"]'); await expect(page.locator('[data-testid="calc-fenton-result"]')).toContainText('AGA'); await expect(page.locator('[data-testid="calc-fenton-result"]')).toContainText('50.0%'); }); });