fix(app): card retry keeps focus and voice when no retry is left
A retry ending on a failure with no retry (network to integrity, engine stopped for good) keeps the polite region and moves focus to Consulter. Busy look on Réessayer, error tone once the engine stopped, one attempt for two calls in one tick; tests for the stopped engine, two core cards and no blob URL after unmount.
This commit is contained in:
1 parent
4a7919c763
commit
b378cf066f
4 files changed
+97
-15
No files matched your search
@@ -5,6 +5,7 @@ import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
||||
import type { PreviewState } from '@faunosteo/core-wasm/types'
|
||||
import { createFakeSupabase, fakeProfile, fakeUser, type FakeSupabase } from '../helpers/fakeSupabase'
|
||||
import { bundledSheet } from '../helpers/sheet'
|
||||
import { controlStopped } from '../helpers/core'
|
||||
|
||||
const mocks = vi.hoisted(() => ({ fake: null as unknown }))
|
||||
vi.mock('@/lib/supabase', () => ({
|
||||
@@ -464,6 +465,9 @@ describe('catalogue cards (R4, board 30)', () => {
|
||||
await userEvent.click(retry)
|
||||
expect(retry).toHaveFocus()
|
||||
expect(retry).toHaveAttribute('aria-disabled', 'true')
|
||||
// The attempt is seen, not only told: greyed with a wait cursor (no new wording).
|
||||
expect(retry.className).toMatch(/aria-disabled:opacity-60/)
|
||||
expect(retry.className).toMatch(/aria-disabled:cursor-wait/)
|
||||
expect(cheval).toHaveAttribute('aria-busy', 'true')
|
||||
expect(polite).toHaveTextContent('')
|
||||
await act(async () => release())
|
||||
@@ -507,6 +511,36 @@ describe('catalogue cards (R4, board 30)', () => {
|
||||
expect(versionCalls(V3)).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('moves the focus to « Consulter » and says the line when a retry ends with no retry left', async () => {
|
||||
failNetwork()
|
||||
mount('/app/anatomy')
|
||||
const cheval = await failedCheval(fr['catalogue.failure.network'])
|
||||
const polite = cheval.querySelector('[aria-live="polite"]')!
|
||||
serveVersions({ [V3]: versionAnswer(V3, 'published', { fingerprint: 'a'.repeat(64) }) })
|
||||
await userEvent.click(within(cheval).getByRole('button', { name: fr['common.retry'] }))
|
||||
// The region mounted before the attempt is the one that speaks (never mounted with its text).
|
||||
await waitFor(() => expect(polite).toHaveTextContent(fr['catalogue.card.integrity_failed']))
|
||||
expect(polite.isConnected).toBe(true)
|
||||
expect(within(cheval).queryByRole('button', { name: fr['common.retry'] })).toBeNull()
|
||||
expect(within(cheval).getByRole('link', { name: 'Consulter Cheval' })).toHaveFocus()
|
||||
})
|
||||
|
||||
it('ignores a second retry call in the same tick', async () => {
|
||||
vi.spyOn(coreRuntime(), 'ready').mockResolvedValueOnce(false)
|
||||
const restart = vi.spyOn(coreRuntime(), 'retry')
|
||||
mount('/app/anatomy')
|
||||
const cheval = await failedCheval(fr['sheet.core_unavailable'])
|
||||
const before = versionCalls(V3)
|
||||
const retry = within(cheval).getByRole('button', { name: fr['sheet.core_retry'] })
|
||||
act(() => {
|
||||
fireEvent.click(retry)
|
||||
fireEvent.click(retry)
|
||||
})
|
||||
expect(await within(cheval).findByText(/2 vues, 27 zones de constats/)).toBeInTheDocument()
|
||||
expect(restart).toHaveBeenCalledTimes(1)
|
||||
expect(versionCalls(V3)).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('drops a retry still running when the card leaves: no update, URLs and previews balanced', async () => {
|
||||
failNetwork()
|
||||
mount('/app/anatomy')
|
||||
@@ -526,7 +560,8 @@ describe('catalogue cards (R4, board 30)', () => {
|
||||
await act(async () => new Promise((resolve) => setTimeout(resolve, 20)))
|
||||
expect(built.mock.calls.length).toBeGreaterThan(0)
|
||||
expect(freed).toHaveBeenCalledTimes(built.mock.calls.length)
|
||||
expect(created).toHaveBeenCalledTimes(revoked.mock.calls.length)
|
||||
expect(created).not.toHaveBeenCalled()
|
||||
expect(revoked).not.toHaveBeenCalled()
|
||||
expect(errors).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -541,6 +576,37 @@ describe('catalogue cards (R4, board 30)', () => {
|
||||
expect(within(cheval).queryByText(fr['sheet.core_unavailable'])).toBeNull()
|
||||
})
|
||||
|
||||
it('says the engine stopped for good in the error tone, with no « Réessayer »', async () => {
|
||||
const setStopped = controlStopped(coreRuntime(), true)
|
||||
try {
|
||||
vi.spyOn(coreRuntime(), 'ready').mockResolvedValue(false)
|
||||
mount('/app/anatomy')
|
||||
const cheval = await failedCheval(fr['core.stopped'])
|
||||
expect(noticeOf(within(cheval).getByText(fr['core.stopped'])).className).toMatch(/color-danger/)
|
||||
expect(within(cheval).queryByRole('button', { name: fr['sheet.core_retry'] })).toBeNull()
|
||||
expect(within(cheval).getByRole('link', { name: 'Consulter Cheval' })).toBeInTheDocument()
|
||||
} finally {
|
||||
act(() => setStopped(false))
|
||||
}
|
||||
})
|
||||
|
||||
it('restarts the engine and reloads only the card whose « Réessayer » was pressed (R-7)', async () => {
|
||||
serveVersions({ [V3]: versionAnswer(V3, 'published'), [DOG]: versionAnswer(DOG, 'published') })
|
||||
vi.spyOn(coreRuntime(), 'ready').mockResolvedValueOnce(false).mockResolvedValueOnce(false)
|
||||
const restart = vi.spyOn(coreRuntime(), 'retry')
|
||||
mount('/app/anatomy')
|
||||
const cheval = await failedCheval(fr['sheet.core_unavailable'])
|
||||
const dog = await card('Chien, rachis')
|
||||
await within(dog).findByText(fr['sheet.core_unavailable'])
|
||||
const dogCalls = versionCalls(DOG)
|
||||
await userEvent.click(within(cheval).getByRole('button', { name: fr['sheet.core_retry'] }))
|
||||
expect(await within(cheval).findByText(/2 vues, 27 zones de constats/)).toBeInTheDocument()
|
||||
expect(restart).toHaveBeenCalledTimes(1)
|
||||
expect(versionCalls(DOG)).toBe(dogCalls)
|
||||
expect(within(dog).getByText(fr['sheet.core_unavailable'])).toBeInTheDocument()
|
||||
expect(within(dog).getByRole('button', { name: fr['sheet.core_retry'] })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('says an expired session with « Réessayer »', async () => {
|
||||
fake.rpcResults.get_sheet_version = () => ({ error: { message: 'session_expired' } })
|
||||
mount('/app/anatomy')
|
||||
|
||||
Reference in new issue
Block a user