Tldraw/packages/tldraw/src/test/commands/getInitialMetaForShape.test.ts

24 wiersze
700 B
TypeScript

import { createShapeId } from '@tldraw/editor'
import { TestEditor } from '../TestEditor'
let editor: TestEditor
beforeEach(() => {
editor = new TestEditor()
})
it('Sets shape meta by default to an empty object', () => {
const id = createShapeId()
editor.createShapes([{ id, type: 'geo' }])
editor.select(id)
expect(editor.getOnlySelectedShape()!.meta).toStrictEqual({})
})
it('Sets shape meta', () => {
editor.getInitialMetaForShape = (shape) => ({ firstThreeCharactersOfId: shape.id.slice(0, 3) })
const id = createShapeId()
editor.createShapes([{ id, type: 'geo' }])
editor.select(id)
expect(editor.getOnlySelectedShape()!.meta).toStrictEqual({ firstThreeCharactersOfId: 'sha' })
})