Skip to content

Commit bcae5f8

Browse files
author
yinquan
committed
add two test cases
1 parent 130b1d8 commit bcae5f8

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/unit/TWTree.spec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,27 @@ describe('basic', ()=>{
351351
expect(node3.children[1].id).toBe(6)
352352
expect(node3.children[2].id).toBe(5)
353353
})
354+
355+
it('method: sort (node = null)', async ()=>{
356+
let wrapper = mount(TWTree, {
357+
propsData: {
358+
tree: commonTree
359+
}
360+
})
361+
await wrapper.vm.$nextTick()
362+
363+
let node3 = wrapper.vm.getById(3)
364+
node3.children[0].title = 'aaaaa'
365+
node3.children[1].title = 'ccccc'
366+
node3.children[2].title = 'bbbbb'
367+
368+
let node1 = wrapper.vm.getById(1)
369+
wrapper.vm.sort(null, true)
370+
371+
expect(node3.children[0].id).toBe(4)
372+
expect(node3.children[1].id).toBe(6)
373+
expect(node3.children[2].id).toBe(5)
374+
})
354375

355376
it('methods: search, clearSearchResult', async ()=>{
356377
let wrapper = mount(TWTree, {
@@ -1253,6 +1274,58 @@ describe('directory', ()=>{
12531274
expect(node3.children.length).toBe(2)
12541275
expect(node3.children[1].title).toMatch('world')
12551276
})
1277+
1278+
it('method: fnBeforeExpand', async ()=>{
1279+
let wrapper = mount(TWTree, {
1280+
propsData: {
1281+
tree: directoryTree,
1282+
defaultAttrs: {
1283+
directoryState: 'collapsed'
1284+
},
1285+
fnBeforeExpand: function() {
1286+
return false
1287+
}
1288+
}
1289+
})
1290+
await wrapper.vm.$nextTick()
1291+
1292+
expect(wrapper.vm.getById(1).directoryState).toMatch('collapsed')
1293+
wrapper.vm.expand(wrapper.vm.getById(1))
1294+
expect(wrapper.vm.getById(1).directoryState).toMatch('collapsed')
1295+
for (let item of wrapper.vm.items) {
1296+
if (item.id === 1) {
1297+
expect(item.__.isVisible).toBeTruthy()
1298+
} else {
1299+
expect(item.__.isVisible).toBeFalsy()
1300+
}
1301+
}
1302+
})
1303+
1304+
it('method: fnBeforeCollapse', async ()=>{
1305+
let wrapper = mount(TWTree, {
1306+
propsData: {
1307+
tree: directoryTree,
1308+
defaultAttrs: {
1309+
directoryState: 'expanded'
1310+
},
1311+
fnBeforeCollapse: function() {
1312+
return false
1313+
}
1314+
}
1315+
})
1316+
await wrapper.vm.$nextTick()
1317+
1318+
expect(wrapper.vm.getById(1).directoryState).toMatch('expanded')
1319+
wrapper.vm.collapse(wrapper.vm.getById(1))
1320+
expect(wrapper.vm.getById(1).directoryState).toMatch('expanded')
1321+
for (let item of wrapper.vm.items) {
1322+
if (item.__.parent !== null && item.__.parent.id === 3) {
1323+
expect(item.__.isVisible).toBeFalsy()
1324+
} else {
1325+
expect(item.__.isVisible).toBeTruthy()
1326+
}
1327+
}
1328+
})
12561329
})
12571330

12581331
describe('drag and drop', ()=>{

0 commit comments

Comments
 (0)