feat(app): editable sheet preview, edit wrappers, cleaning preview and ids
This commit is contained in:
1 parent
2f824a947c
commit
173be5949a
10 files changed
+663
-13
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { newElementId } from '@/editor/ids'
|
||||
import { sameDocument } from '@/editor/core/sameDocument'
|
||||
|
||||
describe('newElementId', () => {
|
||||
it('is the prefix and ten characters of a-z2-7', () => {
|
||||
for (const prefix of [
|
||||
'view',
|
||||
'anno',
|
||||
'cat',
|
||||
'ref',
|
||||
'zone',
|
||||
'fcat',
|
||||
'node',
|
||||
] as const) {
|
||||
expect(newElementId(prefix)).toMatch(
|
||||
new RegExp(`^${prefix}-[a-z2-7]{10}$`),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('does not repeat in a thousand draws', () => {
|
||||
const ids = new Set(
|
||||
Array.from({ length: 1000 }, () => newElementId('anno')),
|
||||
)
|
||||
expect(ids.size).toBe(1000)
|
||||
})
|
||||
})
|
||||
|
||||
describe('sameDocument', () => {
|
||||
it('ignores key order at any depth', () => {
|
||||
expect(
|
||||
sameDocument(
|
||||
'{"a":1,"b":{"c":[1,2],"d":null}}',
|
||||
'{"b":{"d":null,"c":[1,2]},"a":1}',
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps array order and values significant', () => {
|
||||
expect(sameDocument('{"a":[1,2]}', '{"a":[2,1]}')).toBe(false)
|
||||
expect(sameDocument('{"a":1}', '{"a":1,"b":null}')).toBe(false)
|
||||
expect(sameDocument('{"a":1}', '{"a":"1"}')).toBe(false)
|
||||
expect(sameDocument('[]', '{}')).toBe(false)
|
||||
})
|
||||
|
||||
it('compares a non-JSON text as a string', () => {
|
||||
expect(sameDocument('x', 'x')).toBe(true)
|
||||
expect(sameDocument('x', '{}')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user