import { expect, test } from '@playwright/test' import { expectNoHorizontalOverflow, learnerFor, signIn, startSession } from './helpers.js' test.describe('sitting a session', () => { test.beforeEach(async ({ page }, testInfo) => { await signIn(page, learnerFor(testInfo)) }) test('a learner answers a question and is told why', async ({ page }) => { await startSession(page) await expect(page.locator('#quiz-question-heading')).toContainText(/barking cough/i) // Study mode marks as you go, so the answer and its reason arrive together. await page.locator('.option', { hasText: 'Dexamethasone' }).first().click() await expect(page.getByText(/shortens croup/i)).toBeVisible() await expectNoHorizontalOverflow(page) }) test('the answer is not on the page before it is chosen', async ({ page }) => { // The whole point of a question. If the correct option reaches the browser // with the stem, no amount of hiding it in CSS is worth anything. await startSession(page) await expect(page.locator('#quiz-question-heading')).toContainText(/barking cough/i) const html = await page.content() expect(html).not.toContain('shortens croup') }) test('the session ends on its analysis', async ({ page }) => { await startSession(page) await expect(page.locator('#quiz-question-heading')).toContainText(/barking cough/i) for (let i = 0; i < 3; i += 1) { const next = page.getByRole('button', { name: /^(next|skip|submit|finish)/i }).last() await next.click() await page.waitForTimeout(400) } await expect(page).toHaveURL(/\/sessions\/\d+|\/study\/1/) }) })