feat(editor): search, sort, count and add in the Références tab
Search (citation, DOI, URL) with « Effacer la recherche » and Escape;
« Trier par » sheet order, citation (locale collator), citation count,
type (business order); every sort stable on stored order, display only:
document, stored order, ids and history unchanged (unit + e2e). Count
« {n} références » / « {n} sur {total} » counts matching references
only. « Monter » / « Descendre » only in sheet order without search
(A1). « Ajouter une référence » resets search and sort and appends a
draft tile in edit; a tile in edit stays pinned while sorted or
searched; tile state pruned of absent ids. Reset path ready for « Tout
afficher » (R2.4).
Gates: typecheck, lint, test:run (app 1452), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 115
passed / 102 skipped / 2 failed: editor-structures (test-side, fixed,
rerun with editor-references 12 passed / 11 skipped) and admin.spec A0
« Target crashed » during axe on the rights screen (not R2: that
screen renders every grant, 1 282 accumulated e2e fixtures; reported as
an open risk); full-row guard: no pre-existing row changed in any table.
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-tab.test.tsx | `#tab-reference-new-citation` present on load | null until « Ajouter une référence » |
| same | no match text « Aucune référence ne correspond. » | notice « Aucune référence ne contient « zzz ». » |
| same | add: form always visible, add clears the search, `getByText('Nouvelle source')` | click « Ajouter une référence » first; new tile header open, focused, search empty, 4 tiles |
| same | « a refused add keeps the search » | REMOVED (P24: add resets the search at once); replaced by « draft opens with citation focused, refused add keeps the draft, no write » |
| editor-tabs-lists.test.tsx | add form directly | click « Ajouter une référence » before the form assertions (same assertions after) |
| editor-keep-alive.test.tsx | form survives tab round trip | same, after opening the draft |
| editor-no-loss.test.tsx | reference form keeps typed text | same, after opening the draft |
| e2e editor-shell.spec (2), editor-shell-crossing.spec, editor-structures.spec | fill `#tab-reference-new-*` directly; `getByText(citation)` visible | open the draft first; structures asserts the new header is focused |
| e2e editor-references.spec keyboard walk | focus search, Tab reaches header 0 | focus « Ajouter une référence » (search, sort, add precede the headers) |
Other readers of `editor.reference.add`/new ids: grep of src, tests, e2e incl. editor-equine found none left unlisted. editor-equine is not affected ("updated, not run": nothing to update).
## i18n (fr / en)
Added: `editor.references.add` Ajouter une référence / Add a reference; `add_help` Type et citation obligatoires. / Type and citation required.; `clear_search` Effacer la recherche / Clear the search; `sort_by` Trier par / Sort by; `sort.sheet|citation|count|type` Ordre de la fiche, Citation (A → Z), Nombre de citations, Type / Sheet order, Citation (A → Z), Number of citations, Type; `count_one|other` {count} référence(s) / reference(s); `count_of_one|other` {count} référence(s) sur {total} / {count} reference(s) of {total}; `reorder_hint` Pour réorganiser, affichez l'ordre de la fiche sans recherche. / To reorder, show the sheet order without a search.; `no_result` Aucune référence ne contient « {q} ». / No reference contains “{q}”.; `no_result_scope` La recherche porte sur la citation, le DOI et l'URL. / The search covers the citation, the DOI and the URL. (REVUE sentence split in two keys so the first half is bold).
Changed: none. Removed: none (`editor.references.no_match` kept, the panel's EmptyLine still uses it).
This commit is contained in:
1 parent
c21995b3fb
commit
3baac4dbb5
26 files changed
+1544
-219
No files matched your search
@@ -13,7 +13,10 @@ import {
|
||||
openEditor,
|
||||
openTab,
|
||||
place,
|
||||
saveDraft,
|
||||
seedDraft,
|
||||
serverDocument,
|
||||
serverRevision,
|
||||
standardShape,
|
||||
} from '../support/editor'
|
||||
|
||||
@@ -59,9 +62,9 @@ function shape(document: Record<string, unknown>) {
|
||||
family.reference_ids = ['ref-doi']
|
||||
}
|
||||
|
||||
async function open(page: Page) {
|
||||
async function open(page: Page, seedShape = shape) {
|
||||
const actor = await editorActor('fr')
|
||||
const seed = await seedDraft(actor, { shape: shape })
|
||||
const seed = await seedDraft(actor, { shape: seedShape })
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
return { actor, seed }
|
||||
}
|
||||
@@ -187,8 +190,9 @@ test.describe('reference tiles, edit mode', () => {
|
||||
test.setTimeout(120_000)
|
||||
await open(page)
|
||||
await openTab(page, dict, 'references')
|
||||
// The toolbar's last stop (search, sort, add) precedes the first header.
|
||||
await page
|
||||
.getByRole('searchbox', { name: dict['editor.references.search'] })
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.focus()
|
||||
for (let at = 0; at < 3; at++) {
|
||||
await page.keyboard.press('Tab')
|
||||
@@ -223,6 +227,216 @@ test.describe('reference tiles, edit mode', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Four references with distinct orders. Stored: Zèbre 10, zebre 9, Alpha, Étude.
|
||||
* Citation A → Z: Alpha, Étude, zebre 9, Zèbre 10. Citations: zebre 9 two (family and
|
||||
* node), Alpha one, the others none. Types: book, journal, legal, web.
|
||||
*/
|
||||
function sortShape(document: Record<string, unknown>) {
|
||||
standardShape(document)
|
||||
const reference = (id: string, type: string, citation: string) => ({
|
||||
id,
|
||||
type,
|
||||
citation,
|
||||
url: null,
|
||||
doi: null,
|
||||
})
|
||||
document.references = [
|
||||
reference('ref-z', 'web', 'Zèbre 10'),
|
||||
reference('ref-y', 'journal', 'zebre 9'),
|
||||
reference('ref-a', 'book', 'Alpha'),
|
||||
reference('ref-e', 'legal', 'Étude'),
|
||||
]
|
||||
const zone = (document.finding_zones as { categories: unknown[] }[])[0]
|
||||
const family = zone.categories[0] as {
|
||||
reference_ids: string[]
|
||||
children: { reference_ids: string[] }[]
|
||||
}
|
||||
family.reference_ids = ['ref-y']
|
||||
family.children[0].reference_ids = ['ref-y', 'ref-a']
|
||||
}
|
||||
|
||||
const SORTED = {
|
||||
sheet: ['Zèbre 10', 'zebre 9', 'Alpha', 'Étude'],
|
||||
citation: ['Alpha', 'Étude', 'zebre 9', 'Zèbre 10'],
|
||||
count: ['zebre 9', 'Alpha', 'Zèbre 10', 'Étude'],
|
||||
type: ['Alpha', 'zebre 9', 'Étude', 'Zèbre 10'],
|
||||
} as const
|
||||
|
||||
/** The citations of the tiles in display order (the header's first text node). */
|
||||
const shownCitations = (page: Page) =>
|
||||
headers(page).evaluateAll((buttons) =>
|
||||
buttons.map((button) => button.querySelector('span')?.textContent ?? ''),
|
||||
)
|
||||
|
||||
test.describe('reference tiles, search, sort and add', () => {
|
||||
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
test.skip(
|
||||
isPhone(info),
|
||||
'editing needs >= 1 024 px; the phone twin is below',
|
||||
) // floor-guard: allow C16 editing needs >= 1024 px; read-only twin in this file
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
const toolbar = (page: Page) => ({
|
||||
search: libraryRoot(page).getByRole('searchbox', {
|
||||
name: dict['editor.references.search'],
|
||||
}),
|
||||
sort: libraryRoot(page).getByLabel(dict['editor.references.sort_by']),
|
||||
clear: libraryRoot(page).getByRole('button', {
|
||||
name: dict['editor.references.clear_search'],
|
||||
}),
|
||||
})
|
||||
|
||||
test('four sorts, search, clear, no result, move buttons; the server never changes', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
const { actor, seed } = await open(page, sortShape)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const before = await serverDocument(seed.draftId)
|
||||
const revision = await serverRevision(seed.draftId)
|
||||
await openTab(page, dict, 'references')
|
||||
const bar = toolbar(page)
|
||||
await expect(
|
||||
libraryRoot(page).getByText('4 références', { exact: true }),
|
||||
).toBeVisible()
|
||||
for (const [sort, expected] of Object.entries(SORTED)) {
|
||||
await bar.sort.selectOption(sort)
|
||||
await expect.poll(() => shownCitations(page)).toEqual(expected)
|
||||
}
|
||||
await expectAccessible(page, 'the type sort')
|
||||
|
||||
// Search: count line, hint instead of the move buttons, clear, Escape.
|
||||
await bar.sort.selectOption('sheet')
|
||||
await headers(page).first().click()
|
||||
const down = libraryRoot(page).getByRole('button', {
|
||||
name: dict['editor.action.move_down'],
|
||||
})
|
||||
await expect(down).toBeVisible()
|
||||
await bar.search.fill('zebre')
|
||||
await expect(
|
||||
libraryRoot(page).getByText('2 références sur 4', { exact: true }),
|
||||
).toBeVisible()
|
||||
await expect(down).toHaveCount(0)
|
||||
await expect(
|
||||
libraryRoot(page).getByText(dict['editor.references.reorder_hint']),
|
||||
).toBeVisible()
|
||||
await expectAccessible(page, 'a search in progress')
|
||||
await bar.clear.click()
|
||||
await expect(bar.search).toHaveValue('')
|
||||
await expect(bar.search).toBeFocused()
|
||||
await expect(down).toBeVisible()
|
||||
await bar.search.fill('alpha')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(bar.search).toHaveValue('')
|
||||
|
||||
// No result, then the notice's own clear button.
|
||||
await bar.search.fill('radiographie')
|
||||
const notice = libraryRoot(page).getByRole('status').filter({
|
||||
hasText: 'radiographie',
|
||||
})
|
||||
await expect(notice).toContainText('Aucune référence ne contient')
|
||||
await expectAccessible(page, 'the no result notice')
|
||||
await notice
|
||||
.getByRole('button', { name: dict['editor.references.clear_search'] })
|
||||
.click()
|
||||
await expect(bar.search).toBeFocused()
|
||||
await expect(headers(page)).toHaveCount(4)
|
||||
|
||||
// Display only: nothing was saved, the server holds the same document and revision.
|
||||
expect(await serverDocument(seed.draftId)).toEqual(before)
|
||||
expect(await serverRevision(seed.draftId)).toBe(revision)
|
||||
})
|
||||
|
||||
test('add a reference, save it, then delete an uncited one', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
const { actor, seed } = await open(page, sortShape)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
await openTab(page, dict, 'references')
|
||||
const bar = toolbar(page)
|
||||
await bar.sort.selectOption('count')
|
||||
await bar.search.fill('alpha')
|
||||
await libraryRoot(page)
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.click()
|
||||
await expect(bar.search).toHaveValue('')
|
||||
await expect(bar.sort).toHaveValue('sheet')
|
||||
const citation = libraryRoot(page).getByLabel(
|
||||
dict['editor.reference.citation'],
|
||||
)
|
||||
await expect(citation).toBeFocused()
|
||||
// The focus scrolled the toolbar under the sticky header: axe judges what is covered.
|
||||
await libraryRoot(page).getByRole('searchbox').scrollIntoViewIfNeeded()
|
||||
await expectAccessible(page, 'the draft tile')
|
||||
await libraryRoot(page)
|
||||
.getByLabel(dict['editor.reference.type'])
|
||||
.selectOption('manual')
|
||||
await citation.fill('Nouvelle source')
|
||||
await libraryRoot(page)
|
||||
.getByRole('button', { name: dict['editor.reference.add'] })
|
||||
.click()
|
||||
await expect(headers(page)).toHaveCount(5)
|
||||
const added = headers(page).last()
|
||||
await expect(added).toContainText('Nouvelle source')
|
||||
await expect(added).toHaveAttribute('aria-expanded', 'true')
|
||||
await expect(added).toBeFocused()
|
||||
await saveDraft(page, dict, seed.revision + 1)
|
||||
const saved = await serverDocument<{ references: { citation: string }[] }>(
|
||||
seed.draftId,
|
||||
)
|
||||
expect(saved.references.map((r) => r.citation)).toEqual([
|
||||
...SORTED.sheet,
|
||||
'Nouvelle source',
|
||||
])
|
||||
|
||||
// Delete an uncited reference (Étude): the dialog confirms, the tile goes.
|
||||
await headers(page).nth(3).click()
|
||||
await tileAt(page, 3)
|
||||
.getByRole('button', { name: dict['editor.action.delete'] })
|
||||
.click()
|
||||
await page
|
||||
.getByRole('dialog')
|
||||
.getByRole('button', { name: dict['editor.delete.confirm'] })
|
||||
.click()
|
||||
await expect(headers(page)).toHaveCount(4)
|
||||
await expect(libraryRoot(page).getByText('Étude')).toHaveCount(0)
|
||||
})
|
||||
|
||||
test('a tile in edit keeps its place under a sort and under a 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)
|
||||
await bar.sort.selectOption('citation')
|
||||
await headers(page).nth(3).click()
|
||||
await tileAt(page, 3)
|
||||
.getByRole('button', { name: dict['editor.references.edit'] })
|
||||
.click()
|
||||
await bar.sort.selectOption('count')
|
||||
await expect(
|
||||
tileAt(page, 3).getByLabel(dict['editor.reference.citation']),
|
||||
).toBeVisible()
|
||||
await bar.search.fill('alpha')
|
||||
await expect(headers(page)).toHaveCount(2)
|
||||
await expect(
|
||||
libraryRoot(page).getByLabel(dict['editor.reference.citation']),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('reference tiles, read-only at 375 px', () => {
|
||||
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
@@ -242,6 +456,29 @@ test.describe('reference tiles, read-only at 375 px', () => {
|
||||
await expect(headers(page)).toHaveCount(3)
|
||||
const box = await headers(page).first().boundingBox()
|
||||
expect(box?.height ?? 0).toBeGreaterThanOrEqual(44)
|
||||
// Board 27: search and sort are 44 px targets, there is no « Ajouter » and no hint.
|
||||
const root = libraryRoot(page)
|
||||
const search = root.getByRole('searchbox')
|
||||
const sort = root.getByLabel(dict['editor.references.sort_by'])
|
||||
for (const control of [search, sort]) {
|
||||
expect((await control.boundingBox())?.height ?? 0).toBeGreaterThanOrEqual(
|
||||
44,
|
||||
)
|
||||
}
|
||||
await expect(
|
||||
root.getByRole('button', { name: dict['editor.references.add'] }),
|
||||
).toHaveCount(0)
|
||||
await sort.selectOption('citation')
|
||||
await search.fill('source')
|
||||
await expect(headers(page)).toHaveCount(1)
|
||||
await expect(
|
||||
root.getByText(dict['editor.references.reorder_hint']),
|
||||
).toHaveCount(0)
|
||||
await root
|
||||
.getByRole('button', { name: dict['editor.references.clear_search'] })
|
||||
.click()
|
||||
await sort.selectOption('sheet')
|
||||
await expect(headers(page)).toHaveCount(3)
|
||||
await expectNoHorizontalOverflow(page, 'the closed tiles at 375 px')
|
||||
await expectAccessible(page, 'the closed tiles at 375 px')
|
||||
await headers(page).nth(1).click()
|
||||
|
||||
@@ -196,6 +196,9 @@ test.describe('editor shell, width crossing (H)', () => {
|
||||
}) => {
|
||||
await open(page)
|
||||
await openTab(page, dict, 'references')
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.click()
|
||||
await keepsTypedValue(
|
||||
page,
|
||||
page.locator('#tab-reference-new-citation'),
|
||||
|
||||
@@ -98,6 +98,9 @@ test.describe('editor shell, kept places (B2a)', () => {
|
||||
}) => {
|
||||
await open(page)
|
||||
await openTab(page, dict, 'references')
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.click()
|
||||
await page.locator('#tab-reference-new-citation').fill('Smith 1999')
|
||||
await openTab(page, dict, 'general')
|
||||
await openTab(page, dict, 'references')
|
||||
@@ -128,6 +131,9 @@ test.describe('editor shell, kept places (B2a)', () => {
|
||||
await open(page)
|
||||
// An edit first, so « Enregistrer » is enabled: a reference added in its tab.
|
||||
await openTab(page, dict, 'references')
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.click()
|
||||
await page.locator('#tab-reference-new-type').selectOption('book')
|
||||
await page.locator('#tab-reference-new-citation').fill('Smith 1999')
|
||||
await page
|
||||
|
||||
@@ -80,12 +80,17 @@ test.describe('editor structures (A4)', () => {
|
||||
// « Référence A » stays first: it is cited by « Constat A »).
|
||||
await openTab(page, dict, 'references')
|
||||
for (const citation of ['Première référence', 'Seconde référence']) {
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.references.add'] })
|
||||
.click()
|
||||
await page.locator('#tab-reference-new-type').selectOption('book')
|
||||
await page.locator('#tab-reference-new-citation').fill(citation)
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.reference.add'] })
|
||||
.click()
|
||||
await expect(page.getByText(citation)).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('button', { name: new RegExp(`^${citation}`) }),
|
||||
).toBeFocused()
|
||||
}
|
||||
const tiles = page.locator('[id^="tab-reference-"][id$="-header"]')
|
||||
const tileOf = (citation: string) =>
|
||||
@@ -102,12 +107,17 @@ test.describe('editor structures (A4)', () => {
|
||||
await expect(tiles).toHaveCount(1)
|
||||
await search.fill('')
|
||||
await expect(tiles).toHaveCount(3)
|
||||
await tiles.filter({ hasText: 'Seconde référence' }).click()
|
||||
// An added tile stays open (P24): no click, a click would close it.
|
||||
await expect(
|
||||
tiles.filter({ hasText: 'Seconde référence' }),
|
||||
).toHaveAttribute('aria-expanded', 'true')
|
||||
await tileOf('Seconde référence')
|
||||
.getByRole('button', { name: dict['editor.action.move_up'] })
|
||||
.click()
|
||||
await expect(tiles.nth(1)).toContainText('Seconde référence')
|
||||
await tiles.filter({ hasText: 'Première référence' }).click()
|
||||
await expect(
|
||||
tiles.filter({ hasText: 'Première référence' }),
|
||||
).toHaveAttribute('aria-expanded', 'true')
|
||||
await tileOf('Première référence')
|
||||
.getByRole('button', { name: dict['editor.action.delete'] })
|
||||
.click()
|
||||
|
||||
Reference in new issue
Block a user