Skip to content

Commit 9b2ffc7

Browse files
authored
test(table): add table utils has-common test (#526)
* test(table): add table utils has-common test * chore: add global test type
1 parent 93752fe commit 9b2ffc7

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @description has common test
3+
*/
4+
5+
import * as core from '@wangeditor-next/core'
6+
import * as slate from 'slate'
7+
8+
import createEditor from '../../../../tests/utils/create-editor'
9+
import { hasCommon } from '../../src/utils/has-common'
10+
11+
function setEditorSelection(
12+
editor: core.IDomEditor,
13+
selection: slate.Selection = {
14+
anchor: { path: [0, 0], offset: 0 },
15+
focus: { path: [0, 0], offset: 0 },
16+
},
17+
) {
18+
editor.selection = selection
19+
}
20+
21+
describe('hasCommon', () => {
22+
const editor = createEditor()
23+
24+
setEditorSelection(editor)
25+
26+
it('should return true if paths have a common ancestor of type table', () => {
27+
const path1 = [1, 0, 0]
28+
const path2 = [1, 0, 1]
29+
30+
const elem = {
31+
type: 'table',
32+
width: 'auto',
33+
children: [
34+
{
35+
type: 'table-row',
36+
children: [
37+
{
38+
type: 'table-cell',
39+
children: [
40+
{
41+
text: '',
42+
},
43+
],
44+
isHeader: true,
45+
},
46+
{
47+
type: 'table-cell',
48+
children: [
49+
{
50+
text: '',
51+
},
52+
],
53+
isHeader: true,
54+
},
55+
],
56+
},
57+
{
58+
type: 'table-row',
59+
children: [
60+
{
61+
type: 'table-cell',
62+
children: [
63+
{
64+
text: '',
65+
},
66+
],
67+
},
68+
{
69+
type: 'table-cell',
70+
children: [
71+
{
72+
text: '',
73+
},
74+
],
75+
},
76+
],
77+
},
78+
],
79+
columnWidths: [
80+
60,
81+
60,
82+
],
83+
scrollWidth: 120,
84+
height: 62,
85+
}
86+
87+
editor.insertNode(elem) // 插入 divider
88+
const result = hasCommon(editor, [path1, path2], 'tr')
89+
90+
expect(result).toBe(true)
91+
})
92+
93+
it('should return false if paths do not have a common ancestor of type table', () => {
94+
const path1 = [0]
95+
const path2 = [1, 0, 1]
96+
const result = hasCommon(editor, [path1, path2], 'table')
97+
98+
expect(result).toBe(false)
99+
})
100+
})

tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"packages/*/dist"
2828
]
2929
},
30+
"types": [
31+
"vitest/globals"
32+
]
3033
},
3134
"exclude": [
3235
"node_modules",
@@ -35,6 +38,7 @@
3538
],
3639
"include": [
3740
"./tests/setup/index.ts",
38-
"./packages/custom-types.d.ts"
41+
"./packages/custom-types.d.ts",
42+
"**/__tests__/**/*",
3943
]
4044
}

0 commit comments

Comments
 (0)