fix(editor): say when a pinned tile is outside the search
A shown tile the search misses carries « Ne correspond pas à la recherche » under its header (aria-describedby). The no-result notice now needs no shown tile at all. Flip test watchers are stopped in afterEach, so a failing assertion never leaves the setters patched.
This commit is contained in:
1 parent
c8109af719
commit
b1fd8962ff
9 files changed
+148
-2
No files matched your search
@@ -23,7 +23,10 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
}))
|
||||
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
/** Every watcher made by `watchNotes`: stopped after each test, even a failing one. */
|
||||
const watchers: { stop: () => void }[] = []
|
||||
afterEach(() => {
|
||||
watchers.splice(0).forEach((watch) => watch.stop())
|
||||
cleanup()
|
||||
resetStore()
|
||||
setWidth(1024)
|
||||
@@ -131,7 +134,9 @@ function watchNotes() {
|
||||
}
|
||||
wrap(live(), 'textContent')
|
||||
wrap(document.createTextNode(''), 'nodeValue')
|
||||
return { seen, stop: () => restore.forEach((undo) => undo()) }
|
||||
const watch = { seen, stop: () => restore.forEach((undo) => undo()) }
|
||||
watchers.push(watch)
|
||||
return watch
|
||||
}
|
||||
|
||||
async function mount(width = 1280) {
|
||||
|
||||
@@ -396,6 +396,93 @@ describe('the tile in edit is pinned (P23)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the tile outside the search (C3)', () => {
|
||||
const line = 'Ne correspond pas à la recherche'
|
||||
const notice = () => screen.queryByTestId('editor-references-no-result')
|
||||
const lineOf = (id: string) =>
|
||||
within(header(id).closest('li')!).queryByText(line)
|
||||
|
||||
async function editedOut(user: User) {
|
||||
await user.type(search(), 'zèbre')
|
||||
const item = await startEdit(user, 'r1')
|
||||
const citation = within(item).getByLabelText('Citation')
|
||||
await user.clear(citation)
|
||||
await user.type(citation, 'Autre titre')
|
||||
return item
|
||||
}
|
||||
|
||||
it('after « Terminer » shows the tile with its line, no notice, focus on its header', async () => {
|
||||
const { user } = await mount()
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'alpha')
|
||||
const item = await startEdit(user, 'r5')
|
||||
await user.clear(within(item).getByLabelText('Citation'))
|
||||
await user.type(within(item).getByLabelText('Citation'), 'Autre titre')
|
||||
await user.click(within(item).getByRole('button', { name: 'Terminer' }))
|
||||
expect(order()).toEqual(['r5'])
|
||||
expect(lineOf('r5')).toBeVisible()
|
||||
expect(notice()).toBeNull()
|
||||
expect(screen.getByText('0 référence sur 5')).toBeInTheDocument()
|
||||
expect(document.activeElement).toBe(header('r5'))
|
||||
expect(header('r5').getAttribute('aria-describedby')).toBe(lineOf('r5')!.id)
|
||||
expect(header('r5')).toHaveAccessibleDescription(line)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('the next search change drops the tile and shows the notice', async () => {
|
||||
const { user } = await mount()
|
||||
await user.type(search(), 'alpha')
|
||||
const item = await startEdit(user, 'r5')
|
||||
await user.clear(within(item).getByLabelText('Citation'))
|
||||
await user.type(within(item).getByLabelText('Citation'), 'Autre titre')
|
||||
await user.click(within(item).getByRole('button', { name: 'Terminer' }))
|
||||
await user.type(search(), 'x')
|
||||
expect(order()).toEqual([])
|
||||
expect(notice()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a tile in edit that does not match carries the line', async () => {
|
||||
const { user } = await mount()
|
||||
const item = await editedOut(user)
|
||||
expect(lineOf('r1')).toBeNull()
|
||||
await user.type(search(), 'x')
|
||||
expect(within(item).getByLabelText('Citation')).toBeVisible()
|
||||
expect(lineOf('r1')).toBeVisible()
|
||||
})
|
||||
|
||||
it('a matching pinned tile has no line', async () => {
|
||||
const { user } = await mount()
|
||||
await startEdit(user, 'r1')
|
||||
await user.type(search(), 'alpha')
|
||||
expect(lineOf('r1')).toBeVisible()
|
||||
expect(lineOf('r5')).toBeNull()
|
||||
await user.clear(search())
|
||||
expect(lineOf('r1')).toBeNull()
|
||||
})
|
||||
|
||||
it('a read-only flip keeps the tile and its line', async () => {
|
||||
const { user, view } = await mount()
|
||||
await startEdit(user, 'r1')
|
||||
await user.type(search(), 'alpha')
|
||||
view.rerender(lib(true))
|
||||
expect(order()).toEqual(['r1', 'r5'])
|
||||
expect(lineOf('r1')).toBeVisible()
|
||||
expect(notice()).toBeNull()
|
||||
})
|
||||
|
||||
it('an open draft tile does not hide the notice for a search matching nothing', async () => {
|
||||
const { user } = await mount()
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une référence' }),
|
||||
)
|
||||
await user.type(search(), 'radiographie')
|
||||
expect(order()).toEqual([])
|
||||
expect(notice()).not.toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding (P24)', () => {
|
||||
const add = () =>
|
||||
screen.getByRole('button', { name: 'Ajouter une référence' })
|
||||
|
||||
Reference in new issue
Block a user