// @vitest-environment jsdom import React from 'react' import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react' import { afterEach, expect, it, vi } from 'vitest' import { App } from './App.jsx' import { api, postJson } from './api.js' vi.mock('./api.js', () => ({ api: vi.fn(), postJson: vi.fn() })) vi.mock('./Session.jsx', () => ({ Session: ({ pilot }) =>
{pilot ? 'Pilot reading opened' : 'Personal reading opened'}
})) afterEach(() => { cleanup(); vi.resetAllMocks() }) it('locks the assigned language and uses the server-assigned session ID and policy', async () => { const next = { session_id: 'assigned-id', passage_id: 'el-eval-library', stage: 'before' } const pilot = { code: 'participant-code', language: 'el', arm: 'adaptive', completed: 0, total: 8, next, delete_by: '2027-01-01', contact: 'Organiser', notice: 'Voluntary participation.' } api.mockImplementation(path => { if (path === '/health') return Promise.resolve({ speech: { ready: true }, pilot }) if (path === '/benchmarks/latest') return Promise.resolve({ languages: [] }) if (path.startsWith('/policy-report')) return Promise.resolve({ arms: [] }) if (path.startsWith('/sessions?')) return Promise.resolve([]) if (path === '/sessions/assigned-id') return Promise.resolve({ id: 'assigned-id', passage: { id: next.passage_id } }) return Promise.resolve(path.includes('language=el') && path.includes('evaluation') ? [{ id: next.passage_id, title: 'Greek assessment', word_count: 50 }] : []) }) postJson.mockResolvedValue({ id: 'assigned-id' }) render(