feat(editor): one tab order, vertical Plus list with the error count

This commit is contained in:
bchanot committed 2026-11-15 15:52:28 +01:00
1 parent b41c24b29d
commit ff21b0315e
11 files changed
+155 -75

No files matched your search

@@ -28,14 +28,10 @@ async function stateOf(text: string) {
describe('initialTab', () => {
it('opens an empty new draft on Général', async () => {
expect(initialTab(await stateOf(emptyText()), 'wide')).toBe('general')
expect(initialTab(await stateOf(emptyText()))).toBe('general')
})
it('opens a draft with a measured view on Annotations', async () => {
expect(initialTab(await stateOf(baseText()), 'wide')).toBe('annotations')
})
it('keeps Annotations on a tier that does not list Général', async () => {
expect(initialTab(await stateOf(emptyText()), 'small')).toBe('annotations')
expect(initialTab(await stateOf(baseText()))).toBe('annotations')
})
})
+2 -2
View File
@@ -106,11 +106,11 @@ describe('tabsFor', () => {
'references',
'verification',
])
expect(tabsFor('small').shown).toEqual(['annotations', 'verification'])
expect(tabsFor('small').shown).toEqual(['general', 'annotations'])
expect(tabsFor('small').more).toEqual([
'general',
'findings',
'references',
'verification',
])
})
})
+26 -4
View File
@@ -49,7 +49,7 @@ function Page({
/>
<button type="button">outside</button>
</div>
<button type="button" onClick={() => setActive('general')}>
<button type="button" onClick={() => setActive('findings')}>
elsewhere
</button>
</div>
@@ -92,11 +92,33 @@ describe('the overlay', () => {
expect(more()).toHaveAttribute('aria-expanded', 'false')
await gone()
await user.click(more())
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
await user.click(screen.getByRole('tab', { name: 'Général' }))
expect(more()).toHaveAttribute('aria-expanded', 'false')
})
})
describe('the vertical list', () => {
it('stacks the entries in tab order, the active one marked', async () => {
const { user } = mount()
await user.click(more())
expect(list()).toHaveClass('flex-col')
const rows = [...list()!.querySelectorAll('button')]
expect(rows.map((row) => row.id)).toEqual([
'editor-tab-findings',
'editor-tab-references',
'editor-tab-verification',
])
expect(list()!.querySelector('[aria-current]')).toBeNull()
rows.forEach((row) => expect(row).toHaveClass('min-h-12', 'w-full'))
await user.click(rows[0])
await user.click(more())
const current = list()!.querySelectorAll('[aria-current="true"]')
expect(current).toHaveLength(1)
expect(current[0].id).toBe('editor-tab-findings')
expect(current[0].querySelector('svg')).not.toBeNull()
})
})
describe('the panel takes the focus after a pick', () => {
it('Enter on an entry focuses the panel of that tab once the list is gone', async () => {
const { user } = mount()
@@ -184,8 +206,8 @@ describe('outside presses', () => {
it('a press inside the row closes the menu and goes on to act', async () => {
const { user } = mount()
await user.click(more())
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute(
await user.click(screen.getByRole('tab', { name: 'Général' }))
expect(screen.getByRole('tab', { name: 'Général' })).toHaveAttribute(
'aria-selected',
'true',
)
+4 -3
View File
@@ -256,10 +256,11 @@ describe('the guards of a width change', () => {
expect(document.activeElement).toBe(tab('Général'))
})
it('the focus of a typed field goes to « Plus » when the shown tab left the row', async () => {
it('the focus of an editing control goes to « Plus » when the shown tab left the row', async () => {
const user = await mount()
await user.click(tab('Général'))
await user.click(byId('general-name-fr'))
await user.click(tab('Références'))
const add = button('Ajouter une référence')
act(() => add.focus())
cross(500)
expect(document.activeElement).toBe(button('Plus'))
})
+4 -4
View File
@@ -155,24 +155,24 @@ describe('tabs', () => {
expect(screen.queryByRole('button', { name: 'Plus' })).toBeNull()
})
it('below 640 px: two tabs and « Plus » listing Général, Constats and Références', async () => {
it('below 640 px: two tabs and « Plus » listing Constats, Références and Vérification', async () => {
const user = userEvent.setup()
mountDraft({ width: 375 })
await ready()
const shown = within(screen.getByRole('tablist')).getAllByRole('tab')
expect(shown.map((tab) => tab.textContent)).toEqual([
'Général',
'Annotations',
'Vérification',
])
await user.click(screen.getByRole('button', { name: 'Plus' }))
const more = document.getElementById('editor-tabs-more') as HTMLElement
const rest = within(more).getAllByRole('button')
expect(rest.map((b) => b.textContent)).toEqual([
'Général',
'Constats',
'Références',
'Vérification',
])
await user.click(rest[1])
await user.click(rest[0])
expect(screen.getByTestId('editor-tab-findings')).toBeInTheDocument()
await waitFor(() =>
expect(document.getElementById('editor-tabs-more')).toBeNull(),
+20 -3
View File
@@ -51,9 +51,7 @@ describe('the Vérification tab badge', () => {
])('says « n erreur(s) » for %i blocking error(s)', async (count, name) => {
await openReady()
render(<EditorTabs active="general" tier="wide" onSelect={vi.fn()} />)
reportIssues(
Array.from({ length: count }, (_, at) => issue('error', at)),
)
reportIssues(Array.from({ length: count }, (_, at) => issue('error', at)))
expect(verificationTab()).toHaveTextContent(new RegExp(`^${name}$`))
})
@@ -76,3 +74,22 @@ describe('the Vérification tab badge', () => {
)
})
})
describe('« Plus » carries the count while Vérification sits under it', () => {
const plus = () => screen.getByRole('button', { name: /^Plus/ })
it('shows the count at the small tier, nothing at zero', async () => {
await openReady()
render(<EditorTabs active="general" tier="small" onSelect={vi.fn()} />)
reportIssues([])
expect(plus()).toHaveTextContent(/^Plus$/)
reportIssues([issue('error', 0), issue('error', 1)])
expect(plus()).toHaveTextContent(/^Plus 2 erreurs$/)
})
it('wide rows have no Plus button', async () => {
await openReady()
render(<EditorTabs active="general" tier="wide" onSelect={vi.fn()} />)
expect(screen.queryByRole('button', { name: /^Plus/ })).toBeNull()
})
})