feat(editor): a reference made in the citations draft saves with it
This commit is contained in:
1 parent
8c3fcca0b9
commit
70eb2fcbb4
15 files changed
+671
-162
No files matched your search
@@ -1,12 +1,24 @@
|
||||
/** Rev 5 Task 12: the citations draft, held as additions and removals. */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Reference } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
addId,
|
||||
applyEdits,
|
||||
citationCommands,
|
||||
NO_EDITS,
|
||||
putCreated,
|
||||
removeId,
|
||||
sameEdits,
|
||||
} from '@/editor/references/citationEdits'
|
||||
|
||||
const value = (id: string, citation: string): Reference => ({
|
||||
id,
|
||||
type: 'book',
|
||||
citation,
|
||||
doi: null,
|
||||
url: null,
|
||||
})
|
||||
|
||||
describe('citation edits', () => {
|
||||
it('applies removals and additions to the current list, each id once', () => {
|
||||
const edits = addId(removeId(NO_EDITS, 'a'), 'b')
|
||||
@@ -26,4 +38,40 @@ describe('citation edits', () => {
|
||||
const gone = removeId(NO_EDITS, 'a')
|
||||
expect(removeId(gone, 'a')).toBe(gone)
|
||||
})
|
||||
|
||||
it('a created reference joins the draft with its id; a second put replaces it', () => {
|
||||
const once = putCreated(NO_EDITS, value('ref-n', 'Neuf'))
|
||||
expect(once).toEqual({
|
||||
added: ['ref-n'],
|
||||
removed: [],
|
||||
created: [value('ref-n', 'Neuf')],
|
||||
})
|
||||
const twice = putCreated(once, value('ref-n', 'Neuf 2'))
|
||||
expect(twice.created).toEqual([value('ref-n', 'Neuf 2')])
|
||||
expect(twice.added).toEqual(['ref-n'])
|
||||
expect(sameEdits(once, twice)).toBe(false)
|
||||
})
|
||||
|
||||
it('removing a created id drops it entirely', () => {
|
||||
const edits = putCreated(addId(NO_EDITS, 'b'), value('ref-n', 'Neuf'))
|
||||
expect(removeId(edits, 'ref-n')).toEqual(addId(NO_EDITS, 'b'))
|
||||
})
|
||||
|
||||
it('the save: an insert per created reference under a minted id, then the update', () => {
|
||||
const edits = putCreated(removeId(NO_EDITS, 'a'), value('ref-n', 'Neuf'))
|
||||
const minted = ['ref-m']
|
||||
const commands = citationCommands(
|
||||
edits,
|
||||
['a', 'c'],
|
||||
(ids) => ({ op: 'remove', key: { kind: 'reference', id: ids.join() } }),
|
||||
() => minted.shift()!,
|
||||
)
|
||||
expect(commands).toEqual([
|
||||
{
|
||||
op: 'insert',
|
||||
element: { kind: 'reference', value: value('ref-m', 'Neuf') },
|
||||
},
|
||||
{ op: 'remove', key: { kind: 'reference', id: 'c,ref-m' } },
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user