feat(editor): session tag in history, confirm before leaving

This commit is contained in:
bchanot committed 2026-11-14 14:47:43 +01:00
1 parent 4018344ffc
commit 07bebbc855
19 files changed
+844 -76

No files matched your search

+21 -3
View File
@@ -10,6 +10,7 @@ import {
import userEvent from '@testing-library/user-event'
import type { Location, NavigateFunction } from 'react-router-dom'
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
import { resolveSessionTag } from '@/editor/history/sessionTag'
import { defaultView } from '@/editor/navigation'
import { useLocaleStore } from '@/state/localeStore'
import { emptyText } from '../helpers/editorFixtures'
@@ -48,12 +49,15 @@ const foreign = (patch: Partial<HistoryEntry>) => ({
view: defaultView('findings'),
below: null,
sheetId: SHEET,
userId: USER,
tag: TAG,
...patch,
},
})
beforeEach(() => {
/** The session tag of USER in this tab (criterion 22). */
let TAG: string
beforeEach(async () => {
TAG = await resolveSessionTag(USER)
useLocaleStore.setState({ locale: 'fr' })
serverHas(emptyText(), 3, false)
})
@@ -75,7 +79,7 @@ describe('mount', () => {
expect(written()?.view.tab).toBe(tabs[selected()])
expect(written()).toMatchObject({
sheetId: SHEET,
userId: USER,
tag: TAG,
below: null,
})
})
@@ -110,6 +114,20 @@ describe('mount', () => {
expect(selected()).not.toBe('Constats')
expect(written()?.id).not.toBe('old')
})
it('an entry of another session tag, or of the older shape, is foreign', async () => {
const older = foreign({}) as Record<string, Record<string, unknown>>
older[ENTRY_KEY] = { ...older[ENTRY_KEY], tag: undefined, userId: USER }
for (const state of [foreign({ tag: '0'.repeat(32) }), older]) {
mountDraft({ probe, entries: [{ pathname: path, state }] })
await ready()
await waitFor(() => expect(written()?.tag).toBe(TAG))
expect(selected()).not.toBe('Constats')
expect(written()?.id).not.toBe('old')
expect(JSON.stringify(written())).not.toContain(USER)
cleanup()
}
})
})
describe('tab and section moves', () => {