Spaces:
Running on Zero
Running on Zero
Download frontend/src/Pilot.test.jsx from ManasT2485/readloops: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/ManasT2485/readloops/resolve/main/frontend/src/Pilot.test.jsx
- Command line
-
hf download hf://spaces/ManasT2485/readloops/frontend/src/Pilot.test.jsx
-
curl -L -o Pilot.test.jsx https://huggingface.co/spaces/ManasT2485/readloops/resolve/main/frontend/src/Pilot.test.jsx
2.21 kB
| // @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 }) => <p>{pilot ? 'Pilot reading opened' : 'Personal reading opened'}</p> })) | |
| 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(<App />) | |
| await screen.findByText('Greek assessment') | |
| expect(screen.getByRole('button', { name: /English/ }).disabled).toBe(true) | |
| expect(screen.getByRole('button', { name: 'Practice' }).disabled).toBe(true) | |
| expect(screen.queryByLabelText('Exercise selection')).toBeNull() | |
| fireEvent.click(within(screen.getByRole('region', { name: 'Choose a passage' })).getByRole('button', { name: 'Read', exact: true })) | |
| await waitFor(() => expect(postJson).toHaveBeenCalledWith('/sessions', { id: 'assigned-id', passage_id: next.passage_id, mode: 'adaptive' })) | |
| await screen.findByText('Pilot reading opened') | |
| }) | |