fix(editor): Task 3 round 1, literal journey, pin, limits, notice

This commit is contained in:
bchanot committed 2026-11-13 20:38:04 +01:00
1 parent 8b42816270
commit 3bb3603115
9 files changed
+295 -97

No files matched your search

@@ -9,7 +9,7 @@ import {
within,
} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { ReferenceType } from '@faunosteo/core-wasm/types'
import type { ElementKey, ReferenceType } from '@faunosteo/core-wasm/types'
import { targetOfKey } from '@/editor/navigation'
import { useLocaleStore } from '@/state/localeStore'
import { edit, insert } from '../helpers/editorFixtures'
@@ -20,6 +20,8 @@ import {
store,
} from '../helpers/editorHarness'
import ReferencesHost from '../helpers/referencesHost'
import { PlaceVisibleContext } from '@/lib/placeVisibility'
import type { EditorNavigation } from '@/editor/useEditorNavigation'
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
vi.mock('@faunosteo/supabase', async (orig) => ({
@@ -411,6 +413,90 @@ describe('the tile outside the search (C3)', () => {
})
})
describe('no pin while a finding filter is set (R2F-6)', () => {
const category: ElementKey = {
kind: 'finding',
zone_id: 'zone-a',
path: ['fcat-a'],
}
let nav: EditorNavigation
const hosted = async () => {
await openReady({ text: sortText() })
const user = userEvent.setup()
render(<ReferencesHost onNav={(n) => (nav = n)} />)
return user
}
it('the tile edited under a filter leaves no pin once the filter is removed', async () => {
const user = await hosted()
await user.selectOptions(sortBox(), 'citation')
act(() => nav.showAllReferences(category))
expect(order()).toEqual(['r5', 'r2', 'r1'])
await startEdit(user, 'r2')
await cancelDialog(user)
act(() => nav.references.clearFilter())
expect(order()).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
})
it('a pin from before the filter does not come back after it', async () => {
const user = await hosted()
await user.selectOptions(sortBox(), 'citation')
await startEdit(user, 'r1')
await cancelDialog(user)
act(() => nav.showAllReferences(category))
act(() => nav.references.clearFilter())
await user.selectOptions(sortBox(), 'citation')
expect(order()).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
})
it('a tile edited out of the search is not kept under a filter', async () => {
const user = await hosted()
act(() => nav.showAllReferences(category))
await user.type(search(), 'alpha')
expect(order()).toEqual(['r5'])
await startEdit(user, 'r5')
await saveCitation(user, 'Autre titre')
expect(order()).toEqual([])
})
})
describe('the added-reference notice', () => {
it('goes when the user leaves the References tab', async () => {
await openReady({ text: sortText() })
const user = userEvent.setup()
let nav!: EditorNavigation
const { rerender } = render(
<PlaceVisibleContext value>
<ReferencesHost onNav={(n) => (nav = n)} />
</PlaceVisibleContext>,
)
await user.click(
screen.getByRole('button', { name: 'Ajouter une référence' }),
)
const dialog = screen.getByRole('dialog', { name: 'Nouvelle référence' })
await user.selectOptions(within(dialog).getByLabelText('Type'), 'book')
await user.type(within(dialog).getByLabelText('Citation'), 'Nouvelle')
await user.click(
within(dialog).getByRole('button', { name: 'Ajouter la référence' }),
)
await waitFor(() =>
expect(screen.getByText('Référence ajoutée : Nouvelle')).toBeVisible(),
)
rerender(
<PlaceVisibleContext value={false}>
<ReferencesHost onNav={(n) => (nav = n)} />
</PlaceVisibleContext>,
)
rerender(
<PlaceVisibleContext value>
<ReferencesHost onNav={(n) => (nav = n)} />
</PlaceVisibleContext>,
)
expect(screen.queryByText(/Référence ajoutée/)).toBeNull()
expect(nav).toBeDefined()
})
})
describe('after a dialog closes, the view is unchanged (R2F-5)', () => {
it('keeps scroll position inputs: search, sort, open tiles', async () => {
const { user } = await mount()