Skip to content

Commit

Permalink
test(enter): add enter menu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Aug 17, 2024
1 parent 01dca9d commit fb2cc6f
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/basic-modules/__tests__/common/enter-menu.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @description enter menu test
* @author cycleccc
*/

import { Editor, Transforms } from 'slate'
import createEditor from '../../../../tests/utils/create-editor'
import EnterMenu from '../../src/modules/common/menu/EnterMenu'

describe('enter menu', () => {
const menu = new EnterMenu()
let editor: any
let startLocation: any

beforeEach(() => {
editor = createEditor()
startLocation = Editor.start(editor, [])
})

afterEach(() => {
editor = null
startLocation = null
})

it('get value', () => {
expect(menu.getValue(editor)).toBe('')
})

it('is active', () => {
expect(menu.isActive(editor)).toBeFalsy()
})

it('is disabled', () => {
editor.deselect()
expect(menu.isDisabled(editor)).toBeTruthy()
editor.select(startLocation)
expect(menu.isDisabled(editor)).toBeFalsy()
editor.insertText('hello')
editor.select([])
expect(menu.isDisabled(editor)).toBeTruthy()
})

it('exec', () => {
editor.deselect()
expect(menu.exec(editor, '')).toBeUndefined()
editor.select(startLocation)
menu.exec(editor, '')
expect(editor.children).toStrictEqual([
{ children: [{ text: '' }], type: 'paragraph' },
{ children: [{ text: '' }], type: 'paragraph' },
])
})
})

0 comments on commit fb2cc6f

Please sign in to comment.