-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from TabSpace/develop
test(tree): tree 组件添加 filter 属性的测试
- Loading branch information
Showing
9 changed files
with
459 additions
and
376 deletions.
There are no files selected for viewing
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
Submodule _common
updated
9 files
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
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
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
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
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,37 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import Tree from '@/src/tree/index.ts'; | ||
import { delay } from './kit'; | ||
|
||
describe('Tree:api', () => { | ||
jest.useRealTimers(); | ||
describe('remove', () => { | ||
it('删除指定节点后,应当移除 dom 节点', async () => { | ||
const data = [ | ||
{ | ||
value: 't1', | ||
children: [ | ||
{ | ||
value: 't1.1', | ||
}, | ||
], | ||
}, | ||
{ | ||
value: 't2', | ||
}, | ||
]; | ||
const wrapper = mount({ | ||
render() { | ||
return <Tree ref="tree" data={data} expandAll />; | ||
}, | ||
}); | ||
expect(wrapper.find('[data-value="t1"]').exists()).toBe(true); | ||
expect(wrapper.find('[data-value="t1.1"]').exists()).toBe(true); | ||
expect(wrapper.find('[data-value="t2"]').exists()).toBe(true); | ||
|
||
wrapper.vm.$refs.tree.remove('t2'); | ||
await delay(10); | ||
|
||
expect(wrapper.find('[data-value="t2"]').exists()).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import Tree from '@/src/tree/index.ts'; | ||
import { delay } from './kit'; | ||
|
||
describe('Tree:filter', () => { | ||
jest.useRealTimers(); | ||
describe(':props.filter', () => { | ||
it('数据可过滤展示', async () => { | ||
const data = [ | ||
{ | ||
value: 't1', | ||
children: [ | ||
{ | ||
value: 't1.1', | ||
}, | ||
{ | ||
value: 't1.2', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const wrapper = mount({ | ||
data() { | ||
return { | ||
filter: null, | ||
}; | ||
}, | ||
created() { | ||
this.filter = (node) => node.value.indexOf('2') >= 0; | ||
}, | ||
render() { | ||
return <Tree data={data} expandAll filter={this.filter}></Tree>; | ||
}, | ||
}); | ||
|
||
await delay(10); | ||
|
||
const t1 = wrapper.find('[data-value="t1"]'); | ||
let t1d1 = wrapper.find('[data-value="t1.1"]'); | ||
const t1d2 = wrapper.find('[data-value="t1.2"]'); | ||
|
||
// t1.2 被命中, t1 被锁定, t1.1 隐藏 | ||
expect(t1.exists()).toBe(true); | ||
expect(t1.classes('t-tree__item--visible')).toBe(true); | ||
expect(t1.classes('t-is-disabled')).toBe(true); | ||
expect(t1d1.exists()).toBe(false); | ||
expect(t1d2.classes('t-tree__item--visible')).toBe(true); | ||
|
||
await wrapper.setData({ | ||
filter: (node) => node.value.indexOf('1.1') >= 0, | ||
}); | ||
|
||
await delay(10); | ||
|
||
// t1.1 被命中, t1 被锁定, t1.2 隐藏 | ||
t1d1 = wrapper.find('[data-value="t1.1"]'); | ||
expect(t1d1.exists()).toBe(true); | ||
expect(t1d1.classes('t-tree__item--visible')).toBe(true); | ||
expect(t1d2.classes('t-tree__item--visible')).toBe(false); | ||
|
||
await wrapper.setData({ | ||
filter: (node) => node.value.indexOf('1.3') >= 0, | ||
}); | ||
await delay(10); | ||
|
||
// 无命中,全部隐藏 | ||
expect(t1.classes('t-tree__item--visible')).toBe(false); | ||
expect(t1d1.classes('t-tree__item--visible')).toBe(false); | ||
expect(t1d2.classes('t-tree__item--visible')).toBe(false); | ||
|
||
await wrapper.setData({ | ||
filter: null, | ||
}); | ||
await delay(10); | ||
|
||
// 清除过滤器,全部显示 | ||
expect(t1.classes('t-tree__item--visible')).toBe(true); | ||
expect(t1d1.classes('t-tree__item--visible')).toBe(true); | ||
expect(t1d2.classes('t-tree__item--visible')).toBe(true); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.