-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(table): add table utils has-common test (#526)
* test(table): add table utils has-common test * chore: add global test type
- Loading branch information
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/table-module/__tests__/utils/has-common.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* @description has common test | ||
*/ | ||
|
||
import * as core from '@wangeditor-next/core' | ||
import * as slate from 'slate' | ||
|
||
import createEditor from '../../../../tests/utils/create-editor' | ||
import { hasCommon } from '../../src/utils/has-common' | ||
|
||
function setEditorSelection( | ||
editor: core.IDomEditor, | ||
selection: slate.Selection = { | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [0, 0], offset: 0 }, | ||
}, | ||
) { | ||
editor.selection = selection | ||
} | ||
|
||
describe('hasCommon', () => { | ||
const editor = createEditor() | ||
|
||
setEditorSelection(editor) | ||
|
||
it('should return true if paths have a common ancestor of type table', () => { | ||
const path1 = [1, 0, 0] | ||
const path2 = [1, 0, 1] | ||
|
||
const elem = { | ||
type: 'table', | ||
width: 'auto', | ||
children: [ | ||
{ | ||
type: 'table-row', | ||
children: [ | ||
{ | ||
type: 'table-cell', | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
isHeader: true, | ||
}, | ||
{ | ||
type: 'table-cell', | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
isHeader: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'table-row', | ||
children: [ | ||
{ | ||
type: 'table-cell', | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'table-cell', | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
columnWidths: [ | ||
60, | ||
60, | ||
], | ||
scrollWidth: 120, | ||
height: 62, | ||
} | ||
|
||
editor.insertNode(elem) // 插入 divider | ||
const result = hasCommon(editor, [path1, path2], 'tr') | ||
|
||
expect(result).toBe(true) | ||
}) | ||
|
||
it('should return false if paths do not have a common ancestor of type table', () => { | ||
const path1 = [0] | ||
const path2 = [1, 0, 1] | ||
const result = hasCommon(editor, [path1, path2], 'table') | ||
|
||
expect(result).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters