// ============================================================ // PE GUIDE — smoke tests for the Physical Exam Guide tab // ============================================================ // Exercises the full rendering path: tab load → age group selection → // system switching (msk / neuro / resp / cv) → expected per-system // cards (scales, sounds library for resp, APTM image + innocent // murmur panel for cv) → step toggle interaction. // // Uses the shared fixture so any uncaught JS error or console.error // fails the test automatically (catches a repeat of the SSO-bug // class on this page). // ============================================================ const { test, expect, E2E_BASE } = require('../fixtures'); async function openPEGuide(page) { await page.goto(E2E_BASE + '/'); await page.waitForSelector('button.tab-btn', { timeout: 15000 }); // On mobile the sidebar collapses behind a hamburger. Open it so the // tab button is actually in the viewport before we click it. const vp = page.viewportSize(); if (vp && vp.width <= 768) { await page.click('#btn-menu-toggle').catch(() => {}); } await page.click('button.tab-btn[data-tab="peguide"]'); await page.waitForFunction(() => { const el = document.getElementById('peguide-tab'); return el && el.classList.contains('active') && el.innerHTML.trim().length > 100; }, { timeout: 15000 }); } async function selectAge(page, value) { await page.selectOption('#pe-age-group', value); // Wait for components to render (at least one card with a step) await page.waitForFunction(() => { return document.querySelectorAll('#pe-content .pe-step').length > 0; }, { timeout: 5000 }); } async function switchSystem(page, sys) { await page.click('button.wv-subtab-btn[data-pesystem="' + sys + '"]'); // Either steps are there, or the resp/cv cards are (which have no .pe-step) await page.waitForFunction((s) => { const content = document.getElementById('pe-content'); if (!content) return false; if (s === 'resp') return content.innerHTML.includes('Respiratory sounds library'); if (s === 'cv') return content.innerHTML.includes('Auscultation landmarks'); return content.querySelectorAll('.pe-step').length > 0; }, sys, { timeout: 5000 }); } test.describe('PE Guide — smoke', () => { test('tab loads with empty-state message before age group selected', async ({ authedPage: _, page }) => { await openPEGuide(page); await expect(page.locator('#pe-content')).toContainText(/Select an age group/i); }); test('MSK (default) renders with overview and grading scales for adolescent', async ({ authedPage: _, page }) => { await openPEGuide(page); await selectAge(page, 'adolescent'); await expect(page.locator('#pe-content')).toContainText('Musculoskeletal'); await expect(page.locator('#pe-content')).toContainText(/Scoliometer|Beighton/); // At least one step card present await expect(page.locator('.pe-step').first()).toBeVisible(); }); test('switches to Neuro and shows MRC scale + teaching pearl', async ({ authedPage: _, page }) => { await openPEGuide(page); await selectAge(page, 'adolescent'); await switchSystem(page, 'neuro'); await expect(page.locator('#pe-content')).toContainText('Neurologic'); await expect(page.locator('#pe-content')).toContainText(/MRC strength/i); // Teaching pearl rendered (amber block) await expect(page.locator('#pe-content')).toContainText(/Pronator drift/i); }); test('Respiratory system shows the 7-sound library, all with real audio players', async ({ authedPage: _, page }) => { await openPEGuide(page); await selectAge(page, 'adolescent'); await switchSystem(page, 'resp'); await expect(page.locator('#pe-content')).toContainText('Respiratory sounds library'); // All 7 sounds must render as native