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
@@ -486,6 +486,41 @@ test.describe('reference tiles, search, sort and add', () => {
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test('a tile edited out of the search stays after « Terminer », with its line, until the next search', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
const { actor } = await open(page, sortShape)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
await openTab(page, dict, 'references')
|
||||
const bar = toolbar(page)
|
||||
const notice = libraryRoot(page).getByTestId('editor-references-no-result')
|
||||
await bar.search.fill('alpha')
|
||||
await expect(headers(page)).toHaveCount(1)
|
||||
await headers(page).first().click()
|
||||
const tile = tileAt(page, 0)
|
||||
await tile
|
||||
.getByRole('button', { name: dict['editor.references.edit'] })
|
||||
.click()
|
||||
const citation = tile.getByLabel(dict['editor.reference.citation'])
|
||||
await citation.fill('Autre titre')
|
||||
await tile
|
||||
.getByRole('button', {
|
||||
name: dict['editor.references.done'],
|
||||
exact: true,
|
||||
})
|
||||
.click()
|
||||
await expect(
|
||||
tile.getByText(dict['editor.references.outside_search']),
|
||||
).toBeVisible()
|
||||
await expect(notice).toHaveCount(0)
|
||||
await expect(bar.clear).toBeVisible()
|
||||
await bar.search.fill('alphab')
|
||||
await expect(notice).toBeVisible()
|
||||
await expect(headers(page)).toHaveCount(0)
|
||||
})
|
||||
|
||||
test('a refused draft is never dropped silently by a read-only flip', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
@@ -48,6 +48,8 @@ export interface TileProps {
|
||||
readOnly: boolean
|
||||
/** ↑ / ↓ only while neither the search nor a sort narrows or reorders the list. */
|
||||
movable: boolean
|
||||
/** The tab's pinned tile the current search misses: it says so under its header. */
|
||||
outsideSearch?: boolean
|
||||
on: TileHandlers
|
||||
}
|
||||
|
||||
@@ -93,6 +95,7 @@ function TileHeader({
|
||||
data-tile-header
|
||||
aria-expanded={open || editing}
|
||||
aria-controls={`${base}-body`}
|
||||
aria-describedby={props.outsideSearch ? `${base}-outside` : undefined}
|
||||
onClick={onToggle}
|
||||
className={`grid min-h-11 w-full grid-cols-[1.25rem_1fr] items-start gap-x-3 gap-y-1 rounded-lg p-3 text-left ${META_COLUMN[props.host]} ${BUTTON_RING}`}
|
||||
>
|
||||
@@ -296,6 +299,14 @@ export default function ReferenceTile(props: TileProps) {
|
||||
headerRef={headerRef}
|
||||
onToggle={toggle}
|
||||
/>
|
||||
{props.outsideSearch && (
|
||||
<p
|
||||
id={`${base}-outside`}
|
||||
className="px-3 pb-2 text-xs text-[var(--color-ink-muted)]"
|
||||
>
|
||||
{t('editor.references.outside_search')}
|
||||
</p>
|
||||
)}
|
||||
{(open || editing) && (
|
||||
<div
|
||||
id={`${base}-body`}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Reference } from '@faunosteo/core-wasm/types'
|
||||
import { targetOfKey, type EditorTarget } from '@/editor/navigation'
|
||||
import { referenceMatches } from '@/editor/references/filter'
|
||||
import type { CiterItem } from '@/editor/references/citations'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import ReferenceTile from './ReferenceTile'
|
||||
@@ -13,6 +14,8 @@ interface Props {
|
||||
keys: readonly string[]
|
||||
citers: ReadonlyMap<string, readonly CiterItem[]>
|
||||
tiles: ReturnType<typeof useTileState>
|
||||
/** The current search: a tile it misses (a pinned one) says so. */
|
||||
query: string
|
||||
readOnly: boolean
|
||||
movable: boolean
|
||||
navigate: (target: EditorTarget) => void
|
||||
@@ -49,6 +52,7 @@ export default function ReferenceTiles(props: Props) {
|
||||
editing={!props.readOnly && tiles.editingKey === key}
|
||||
readOnly={props.readOnly}
|
||||
movable={props.movable}
|
||||
outsideSearch={!referenceMatches(reference, props.query)}
|
||||
on={{
|
||||
toggle: () => tiles.toggle(key, props.readOnly),
|
||||
edit: () => props.onEdit(position),
|
||||
|
||||
@@ -59,7 +59,7 @@ function Library({ readOnly, navigate, focus, resetSignal }: Props) {
|
||||
{lib.loaded && (
|
||||
<>
|
||||
{all.length === 0 && <EmptyLine />}
|
||||
{all.length > 0 && shown.matchCount === 0 && (
|
||||
{all.length > 0 && shown.positions.length === 0 && (
|
||||
<NoResult query={shown.view.query} onClear={act.clearSearch} />
|
||||
)}
|
||||
{!readOnly && !sheetView && shown.positions.length > 0 && (
|
||||
@@ -73,6 +73,7 @@ function Library({ readOnly, navigate, focus, resetSignal }: Props) {
|
||||
keys={lib.keys}
|
||||
citers={lib.citers}
|
||||
tiles={lib.tiles}
|
||||
query={shown.view.query}
|
||||
readOnly={readOnly}
|
||||
movable={sheetView}
|
||||
navigate={navigate}
|
||||
|
||||
@@ -1271,6 +1271,7 @@ export const en: Dict = {
|
||||
'editor.references.reorder_hint': 'To reorder, show the sheet order without a search.',
|
||||
'editor.references.no_result': 'No reference contains “{q}”.',
|
||||
'editor.references.no_result_scope': 'The search covers the citation, the DOI and the URL.',
|
||||
'editor.references.outside_search': 'Does not match the search',
|
||||
'editor.findings.references_open_one': '{count} reference',
|
||||
'editor.findings.references_open_other': '{count} references',
|
||||
'editor.draft.loading': 'Loading the draft…',
|
||||
|
||||
@@ -1302,6 +1302,7 @@ export const fr: Dict = {
|
||||
'editor.references.reorder_hint': 'Pour réorganiser, affichez l\'ordre de la fiche sans recherche.',
|
||||
'editor.references.no_result': 'Aucune référence ne contient « {q} ».',
|
||||
'editor.references.no_result_scope': 'La recherche porte sur la citation, le DOI et l\'URL.',
|
||||
'editor.references.outside_search': 'Ne correspond pas à la recherche',
|
||||
'editor.findings.references_open_one': '{count} référence',
|
||||
'editor.findings.references_open_other': '{count} références',
|
||||
'editor.draft.loading': 'Chargement du brouillon…',
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -59,6 +59,7 @@ Règles de lecture :
|
||||
| `editor.references.reorder_hint` | Pour réorganiser, affichez l'ordre de la fiche sans recherche. | To reorder, show the sheet order without a search. | Onglet Références, sous la barre d'outils quand « Monter » et « Descendre » sont absents | nouveau | |
|
||||
| `editor.references.no_result` | Aucune référence ne contient « {q} ». | No reference contains “{q}”. | Onglet Références, état sans résultat | nouveau | {q} est le texte tapé, rogné, repris tel quel (`$&` reste littéral). L'état n'est pas une région live : la ligne de décompte annonce déjà « 0 référence sur N ». |
|
||||
| `editor.references.no_result_scope` | La recherche porte sur la citation, le DOI et l'URL. | The search covers the citation, the DOI and the URL. | Onglet Références, état sans résultat | nouveau | |
|
||||
| `editor.references.outside_search` | Ne correspond pas à la recherche | Does not match the search | Onglet Références, ligne sous l'en-tête d'une tuile affichée hors recherche (épinglée : en édition, après « Terminer », en lecture seule) ; décrit le bouton d'en-tête (`aria-describedby`) | nouveau | EN provisoire. Sans effet sur le décompte ni sur l'état sans résultat. |
|
||||
|
||||
## 2. Clés retirées
|
||||
|
||||
|
||||
Reference in new issue
Block a user