Skip to content

Commit

Permalink
test(vdom): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Aug 19, 2024
1 parent 2768f18 commit e879409
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/basic-modules/__tests__/code-block/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Editor, Transforms } from 'slate'
import createEditor from '../../../../tests/utils/create-editor'
import withCodeBlock from '../../src/modules/code-block/plugin'
import { isDataTransfer } from '../../../core/src/utils/dom'

// 模拟 DataTransfer
class MyDataTransfer {
Expand Down
3 changes: 2 additions & 1 deletion packages/basic-modules/__tests__/color/color-menus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Editor, Transforms } from 'slate'
import createEditor from '../../../../tests/utils/create-editor'
import ColorMenu from '../../src/modules/color/menu/ColorMenu'
import BgColorMenu from '../../src/modules/color/menu/BgColorMenu'
import { isHTMLElememt } from '../../../../packages/core/src/utils/dom'

describe('color menus', () => {
let editor: any
Expand Down Expand Up @@ -68,7 +69,7 @@ describe('color menus', () => {
it('get panel content elem', () => {
menus.forEach(({ menu }) => {
const elem = menu.getPanelContentElem(editor)
expect(elem instanceof HTMLElement).toBeTruthy()
expect(isHTMLElememt(elem)).toBeTruthy()
})
})
it('should handle click event and add mark to editor', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Editor, Transforms } from 'slate'
import createEditor from '../../../../tests/utils/create-editor'
import EmotionMenu from '../../src/modules/emotion/menu/EmotionMenu'
import { isHTMLElememt } from '../../../../packages/core/src/utils/dom'

describe('font family menu', () => {
const menu = new EmotionMenu()
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('font family menu', () => {

it('get panel content elem', () => {
const elem = menu.getPanelContentElem(editor)
expect(elem instanceof HTMLElement).toBeTruthy()
expect(isHTMLElememt(elem)).toBeTruthy()
document.body.appendChild(elem)

const li = elem.querySelector('li') as HTMLLIElement
Expand Down
5 changes: 3 additions & 2 deletions packages/table-module/__tests__/menu/insert-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { TABLE_SVG } from '../../src/constants/svg'
import locale from '../../src/locale/zh-CN'
import * as slate from 'slate'
import * as core from '@wangeditor-next/core'
import $, { DOMElement } from '../../src/utils/dom'
import $ from '../../src/utils/dom'
import { isDOMElement } from './../../../core/src/utils/dom'

function setEditorSelection(
editor: core.IDomEditor,
Expand Down Expand Up @@ -111,7 +112,7 @@ describe('Table Module Insert Table Menu', () => {
const insertTableMenu = new InsertTable()
const editor = createEditor()

expect(insertTableMenu.getPanelContentElem(editor) instanceof DOMElement).toBeTruthy()
expect(isDOMElement(insertTableMenu.getPanelContentElem(editor))).toBeTruthy()
expect(insertTableMenu.getPanelContentElem(editor).className).toBe('w-e-panel-content-table')
})

Expand Down
8 changes: 4 additions & 4 deletions packages/table-module/src/module/column-resize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import throttle from 'lodash.throttle'
import { Element as SlateElement, Transforms, Editor } from 'slate'
import { DomEditor, IDomEditor } from '@wangeditor-next/core'
import { IDomEditor, isHTMLElememt } from '@wangeditor-next/core'
import { TableElement } from './custom-types'
import { isOfType } from '../utils'
import $ from '../utils/dom'
Expand Down Expand Up @@ -40,7 +40,7 @@ export function getColumnWidthRatios(columnWidths: number[]) {
*/
let resizeObserver: ResizeObserver | null = null
export function observerTableResize(editor: IDomEditor, elm: Node | undefined) {
if (elm instanceof HTMLElement) {
if (isHTMLElememt(elm)) {
const table = elm.querySelector('table')
if (table) {
resizeObserver = new ResizeObserver(([{ contentRect }]) => {
Expand Down Expand Up @@ -183,7 +183,7 @@ export function handleCellBorderVisible(editor: IDomEditor, elemNode: SlateEleme
// Cell Border 宽度为 10px
const { clientX, target } = e
// 当单元格合并的时候,鼠标在 cell 中间,则不显示 cell border
if (target instanceof HTMLElement) {
if (isHTMLElememt(target)) {
const rect = target.getBoundingClientRect()

if (clientX > rect.x + 5 && clientX < rect.x + rect.width - 5) {
Expand All @@ -197,7 +197,7 @@ export function handleCellBorderVisible(editor: IDomEditor, elemNode: SlateEleme
return
}
}
if (target instanceof HTMLElement) {
if (isHTMLElememt(target)) {
const parent = target.closest('.table')
if (parent) {
const { clientX } = e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @author luochao
*/

import { isHTMLElememt } from '../../../../packages/core/src/utils/dom'
import createEditor from '../../../../tests/utils/create-editor'
import InsertVideoMenu from '../../src/module/menu/InsertVideoMenu'
import * as core from '@wangeditor-next/core'
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('videoModule module', () => {
})

test('InsertVideoMenu invoke getModalContentElem should return HTML element', () => {
expect(insertVideoMenu.getModalContentElem(editor) instanceof HTMLElement).toBe(true)
expect(isHTMLElememt(insertVideoMenu.getModalContentElem(editor))).toBe(true)
})
})
})

0 comments on commit e879409

Please sign in to comment.