test(app): card glyph per failure and focus rule after retry
This commit is contained in:
1 parent
04b723cc54
commit
83f2d8bede
1 file changed
+62
@@ -21,6 +21,7 @@ import { cardFailure, coreFailure, serverFailure, type CatalogueFailure } from '
|
|||||||
import { SheetFailure } from '@faunosteo/supabase'
|
import { SheetFailure } from '@faunosteo/supabase'
|
||||||
import { useAuthStore } from '@/state/authStore'
|
import { useAuthStore } from '@/state/authStore'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
import Icon, { type IconName } from '@/components/ui/Icon'
|
||||||
import { fr } from '@/i18n/fr'
|
import { fr } from '@/i18n/fr'
|
||||||
import { en } from '@/i18n/en'
|
import { en } from '@/i18n/en'
|
||||||
|
|
||||||
@@ -639,6 +640,67 @@ describe('catalogue cards (R4, board 30)', () => {
|
|||||||
expect(await within(horse).findByText(en['catalogue.card.integrity_failed'])).toBeInTheDocument()
|
expect(await within(horse).findByText(en['catalogue.card.integrity_failed'])).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The path data the Icon component draws for a name (no hook of its own). */
|
||||||
|
function iconPath(name: IconName): string | null {
|
||||||
|
const { container } = render(<Icon name={name} />)
|
||||||
|
const d = container.querySelector('path')!.getAttribute('d')
|
||||||
|
cleanup()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['a network line', 'network', 'catalogue.failure.network', 'wifi-off'],
|
||||||
|
['an unavailable line', 'boom', 'catalogue.failure.unavailable', 'alert'],
|
||||||
|
] as const)('draws the glyph of %s', async (_case, message, key, icon) => {
|
||||||
|
fake.rpcResults.get_sheet_version = () => ({ error: { message } })
|
||||||
|
const expected = iconPath(icon)
|
||||||
|
const other = iconPath(icon === 'alert' ? 'wifi-off' : 'alert')
|
||||||
|
mount('/app/anatomy')
|
||||||
|
const cheval = await failedCheval(fr[key])
|
||||||
|
const path = noticeOf(within(cheval).getByText(fr[key])).querySelector('svg path')!
|
||||||
|
expect(path.getAttribute('d')).toBe(expected)
|
||||||
|
expect(path.getAttribute('d')).not.toBe(other)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('draws the alert glyph on an integrity line', async () => {
|
||||||
|
serveVersions({ [V3]: versionAnswer(V3, 'published', { fingerprint: 'a'.repeat(64) }) })
|
||||||
|
const expected = iconPath('alert')
|
||||||
|
mount('/app/anatomy')
|
||||||
|
const cheval = await failedCheval(fr['catalogue.card.integrity_failed'])
|
||||||
|
const path = noticeOf(within(cheval).getByText(fr['catalogue.card.integrity_failed'])).querySelector('svg path')!
|
||||||
|
expect(path.getAttribute('d')).toBe(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('moves the focus to « Consulter » when the attempt settles with the focus on the page body', async () => {
|
||||||
|
failNetwork()
|
||||||
|
mount('/app/anatomy')
|
||||||
|
const cheval = await failedCheval(fr['catalogue.failure.network'])
|
||||||
|
const release = holdVersions()
|
||||||
|
serveVersions({ [V3]: versionAnswer(V3, 'published') })
|
||||||
|
const retry = within(cheval).getByRole('button', { name: fr['common.retry'] })
|
||||||
|
await userEvent.click(retry)
|
||||||
|
act(() => retry.blur())
|
||||||
|
expect(globalThis.document.body).toHaveFocus()
|
||||||
|
await act(async () => release())
|
||||||
|
expect(await within(cheval).findByText(/2 vues, 27 zones de constats/)).toBeInTheDocument()
|
||||||
|
expect(within(cheval).getByRole('link', { name: 'Consulter Cheval' })).toHaveFocus()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('leaves the focus where it is when the attempt settles with the focus elsewhere', async () => {
|
||||||
|
failNetwork()
|
||||||
|
mount('/app/anatomy')
|
||||||
|
const cheval = await failedCheval(fr['catalogue.failure.network'])
|
||||||
|
const release = holdVersions()
|
||||||
|
serveVersions({ [V3]: versionAnswer(V3, 'published') })
|
||||||
|
await userEvent.click(within(cheval).getByRole('button', { name: fr['common.retry'] }))
|
||||||
|
const search = screen.getByRole('searchbox', { name: fr['catalogue.search'] })
|
||||||
|
act(() => search.focus())
|
||||||
|
await act(async () => release())
|
||||||
|
expect(await within(cheval).findByText(/2 vues, 27 zones de constats/)).toBeInTheDocument()
|
||||||
|
expect(search).toHaveFocus()
|
||||||
|
expect(within(cheval).getByRole('link', { name: 'Consulter Cheval' })).not.toHaveFocus()
|
||||||
|
})
|
||||||
|
|
||||||
it('classes every failure kind', () => {
|
it('classes every failure kind', () => {
|
||||||
const expected: Record<CatalogueFailure, [integrity: boolean, refused: boolean]> = {
|
const expected: Record<CatalogueFailure, [integrity: boolean, refused: boolean]> = {
|
||||||
fingerprint_mismatch: [true, true],
|
fingerprint_mismatch: [true, true],
|
||||||
|
|||||||
Reference in new issue
Block a user