pediatric-ai-scribe-v3/e2e/tests/settings-faq-dictation.spec.js
Daniel 3884bf673b test(e2e): +120 tests across 8 new specs; baseline fixes
8 new spec files covering sections previously only smoke-tested:
- ai-endpoints-contract.spec.js  — hits 8 real AI endpoints via request
  context and fails if the response leaks TypeError / ReferenceError /
  'Cannot read properties of undefined' / 'is not defined' / 'is not a
  function'. This is the class of bug that shipped the PE-narrative
  regression to prod because every page-level mock prevented the real
  handler from running.
- encounter-workflow.spec.js — generate HPI, refine, clear transcript.
- encounter-save-load.spec.js — save draft, load popover, repopulate.
- wellvisit-workflow.spec.js — byvisit, milestones, SSHADESS (12+
  reveal), visit note.
- vaxschedule-content.spec.js — schedule + catch-up panels populate
  beyond "Loading".
- chart-review-workflow.spec.js — generate + load popover.
- learning-tab.spec.js — search filter, category pills, feed.
- settings-faq-dictation.spec.js — voice/password/2FA/Nextcloud
  sections, FAQ expand/collapse, dictation generate flow.

Baseline fixes:
- Added CORS_ORIGINS + API_RATE_LIMIT_MAX env overrides so the e2e
  container accepts the browser's Origin header and can absorb the
  full suite's API traffic without tripping the 200/min guard.
- Server's /api/ rate limit is now configurable via
  API_RATE_LIMIT_MAX (default stays 200).
- extensions-crud: replaced native page.on('dialog') listeners with
  #confirm-modal-ok clicks (we moved off native confirm()).
- pe-guide-smoke + extensions-crud: mobile viewport opens the hamburger
  before clicking sidebar tabs.
- fixtures.js: /api/refine mock uses 'refined' (real API shape), not
  'content'. /api/chart-review replaced with /api/generate-chart-review.

Suite: 230 passed / 0 failed in 4m36s.
2026-04-23 18:58:38 +02:00

115 lines
5 KiB
JavaScript

// ============================================================
// SETTINGS + FAQ + DICTATION — detailed UI exercises that
// don't depend on real AI / recording permissions.
// ============================================================
const { test, expect, E2E_BASE, mockAI } = require('../fixtures');
async function openTab(page, name) {
await page.goto(E2E_BASE + '/');
await page.waitForSelector('button.tab-btn', { timeout: 15000 });
const vp = page.viewportSize();
if (vp && vp.width <= 768) {
await page.click('#btn-menu-toggle').catch(() => {});
}
await page.click(`button.tab-btn[data-tab="${name}"]`);
await page.waitForFunction((t) => {
const el = document.getElementById(t + '-tab');
return el && el.classList.contains('active') && el.innerHTML.trim().length > 100;
}, name, { timeout: 15000 });
}
test.describe('Settings — voice, password, nextcloud sections render', () => {
test('voice-preferences inputs + save button exist', async ({ authedPage: _, page }) => {
await openTab(page, 'settings');
// STT and TTS dropdowns populate; save button exists
await expect(page.locator('#stt-model-select')).toBeVisible();
await expect(page.locator('#tts-voice-select')).toBeVisible();
await expect(page.locator('#btn-save-voice-prefs')).toBeVisible();
});
test('change-password form: all three fields + submit button present', async ({ authedPage: _, page }) => {
await openTab(page, 'settings');
await expect(page.locator('#pw-current')).toBeVisible();
await expect(page.locator('#pw-new')).toBeVisible();
await expect(page.locator('#pw-confirm')).toBeVisible();
await expect(page.locator('#btn-change-password')).toBeVisible();
});
test('2FA setup panel has QR container + verify input', async ({ authedPage: _, page }) => {
await openTab(page, 'settings');
// At least one of the 2FA buttons should be present
const setupCount = await page.locator('#btn-setup-2fa').count();
const disableCount = await page.locator('#btn-disable-2fa').count();
expect(setupCount + disableCount).toBeGreaterThan(0);
});
test('Nextcloud section: URL/user/pass fields render', async ({ authedPage: _, page }) => {
await openTab(page, 'settings');
await expect(page.locator('#nc-url')).toBeVisible();
await expect(page.locator('#nc-user')).toBeVisible();
await expect(page.locator('#nc-pass')).toBeVisible();
});
});
test.describe('FAQ — questions expand + collapse on click', () => {
test('clicking a FAQ question reveals its answer panel', async ({ authedPage: _, page }) => {
await openTab(page, 'faq');
const questions = page.locator('.faq-question');
const count = await questions.count();
expect(count).toBeGreaterThan(0);
const first = questions.first();
await first.click();
// The corresponding answer should become visible — either via class toggle or
// inline style. Grab the sibling / next matching answer element and check.
const ariaControls = await first.getAttribute('aria-controls');
if (ariaControls) {
await expect(page.locator('#' + ariaControls)).toBeVisible();
} else {
// Fallback: any .faq-answer becomes visible
await expect(page.locator('.faq-answer').first()).toBeVisible();
}
});
});
test.describe('Dictation — UI loads, transcript editable, clear works', () => {
test('age/gender/setting inputs + generate + clear all render', async ({ authedPage: _, page }) => {
await mockAI(page);
await openTab(page, 'dictation');
await expect(page.locator('#dict-age')).toBeVisible();
await expect(page.locator('#dict-gender')).toBeVisible();
await expect(page.locator('#dict-setting')).toBeVisible();
await expect(page.locator('#dict-transcript')).toBeVisible();
await expect(page.locator('#dict-generate-btn')).toBeVisible();
});
test('typing into transcript + clear empties it', async ({ authedPage: _, page }) => {
await mockAI(page);
await openTab(page, 'dictation');
await page.locator('#dict-transcript').click();
await page.keyboard.type('Chief complaint: sore throat.');
await expect(page.locator('#dict-transcript')).toContainText('sore throat');
await page.click('#dict-clear');
const text = await page.locator('#dict-transcript').innerText();
expect(text.trim()).toBe('');
});
test('generate with short transcript → mocked HPI renders', async ({ authedPage: _, page }) => {
await mockAI(page);
await openTab(page, 'dictation');
await page.fill('#dict-age', '6 years');
await page.locator('#dict-transcript').click();
await page.keyboard.type('Patient with cough and congestion for 2 days.');
// Default output type is HPI — should call /api/generate-hpi-dictation
const [resp] = await Promise.all([
page.waitForResponse('**/api/generate-hpi-dictation'),
page.click('#dict-generate-btn'),
]);
expect(resp.status()).toBe(200);
await expect(page.locator('#dict-output')).toBeVisible();
await expect(page.locator('#dict-hpi-text')).toContainText('MOCK HPI from dictation');
});
});