Files
faunosteo/apps/app/tests/unit/editor-citation-edits.test.ts
T
bchanot 3dc5820e3a feat(editor): edit mode of the references dialog
« Modifier » turns the references dialog into a draft of adds and removes,
saved as one update on the current citations. A new layer, citations,
guards it between the finding and the reference dialogs: close, Back,
POP refusal and the leave cascade ask it. « Modifier la référence » and
« Nouvelle référence » stack the reference dialog over it; a creation it
started joins its draft.
2026-11-15 16:39:43 +01:00

30 lines
986 B
TypeScript

/** Rev 5 Task 12: the citations draft, held as additions and removals. */
import { describe, expect, it } from 'vitest'
import {
addId,
applyEdits,
NO_EDITS,
removeId,
} from '@/editor/references/citationEdits'
describe('citation edits', () => {
it('applies removals and additions to the current list, each id once', () => {
const edits = addId(removeId(NO_EDITS, 'a'), 'b')
expect(applyEdits(['a', 'c'], edits)).toEqual(['c', 'b'])
expect(applyEdits(['a', 'b'], edits)).toEqual(['b'])
expect(applyEdits([], edits)).toEqual(['b'])
})
it('a removal then a citation of the same id is no change at all', () => {
expect(addId(removeId(NO_EDITS, 'a'), 'a')).toEqual(NO_EDITS)
expect(removeId(addId(NO_EDITS, 'n'), 'n')).toEqual(NO_EDITS)
})
it('a repeat is ignored', () => {
const once = addId(NO_EDITS, 'b')
expect(addId(once, 'b')).toBe(once)
const gone = removeId(NO_EDITS, 'a')
expect(removeId(gone, 'a')).toBe(gone)
})
})