feat(editor): tell the practitioner when a restored draft was rebased on a different sheet
This commit is contained in:
1 parent
5ed4a4b620
commit
e8f1734424
5 files changed
+64
-5
No files matched your search
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* The editor route on the bundled sheet: the click chain end to end (DOM
|
||||
* click on a generated marker → service → store), the detail view by its
|
||||
* localized name, the sheet status line, the disclaimer once per session.
|
||||
* localized name, the sheet status line, the disclaimer once per session,
|
||||
* the draft restore (silent on the same sheet, one alert after a rebase).
|
||||
*/
|
||||
import {
|
||||
describe,
|
||||
@@ -40,6 +41,7 @@ beforeEach(() => {
|
||||
sessionStorage.clear()
|
||||
sessionStorage.setItem(DISCLAIMER_FLAG, '1')
|
||||
window.scrollTo = vi.fn() as unknown as typeof window.scrollTo
|
||||
vi.stubGlobal('alert', vi.fn())
|
||||
useReportStore.setState({ report: null, activeObservationIndex: 0 })
|
||||
useReportStore.getState().hydrateReport(
|
||||
minimalReport(sheet, {
|
||||
@@ -58,6 +60,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
const zonesOf = (i = 0) =>
|
||||
@@ -199,7 +202,7 @@ describe('EditorRoute on the canonical sheet', () => {
|
||||
expect(sessionStorage.getItem(DISCLAIMER_FLAG)).toBe('1')
|
||||
})
|
||||
|
||||
it('restores the per-tab draft when the store is empty, migrating a v2 one', async () => {
|
||||
it('restores the per-tab draft when the store is empty, silently on the same sheet', async () => {
|
||||
const report = useReportStore.getState().report!
|
||||
useReportStore.setState({ report: null })
|
||||
sessionStorage.setItem(
|
||||
@@ -208,5 +211,40 @@ describe('EditorRoute on the canonical sheet', () => {
|
||||
)
|
||||
await mount()
|
||||
expect(useReportStore.getState().report?.id).toBe(report.id)
|
||||
expect(window.alert).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('a draft from another sheet is rebased, its lost zone flagged, and announced once with the count', async () => {
|
||||
const report = useReportStore.getState().report!
|
||||
useReportStore.setState({ report: null })
|
||||
const foreign = {
|
||||
...report,
|
||||
sheet: { ...report.sheet, documentSha256: '0'.repeat(64) },
|
||||
observations: [
|
||||
{
|
||||
...report.observations[0]!,
|
||||
zones: [
|
||||
{
|
||||
annotationId: 'ghost-zone',
|
||||
viewId: 'main',
|
||||
labelFrSnapshot: 'Zone disparue',
|
||||
labelEnSnapshot: 'Vanished zone',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
sessionStorage.setItem('osteo:draft', JSON.stringify(foreign))
|
||||
await mount()
|
||||
const restored = useReportStore.getState().report!
|
||||
expect(restored.sheet).toEqual(sheet.sheet.ref)
|
||||
expect(restored.observations[0]!.zones[0]).toMatchObject({
|
||||
annotationId: 'ghost-zone',
|
||||
unresolved: true,
|
||||
})
|
||||
expect(window.alert).toHaveBeenCalledTimes(1)
|
||||
expect(window.alert).toHaveBeenCalledWith(
|
||||
fr['editor.draft_rebased'].replace('{count}', '1'),
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user