Skip to content

Commit

Permalink
add two test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yinquan committed Sep 13, 2020
1 parent 130b1d8 commit bcae5f8
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/unit/TWTree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ describe('basic', ()=>{
expect(node3.children[1].id).toBe(6)
expect(node3.children[2].id).toBe(5)
})

it('method: sort (node = null)', async ()=>{
let wrapper = mount(TWTree, {
propsData: {
tree: commonTree
}
})
await wrapper.vm.$nextTick()

let node3 = wrapper.vm.getById(3)
node3.children[0].title = 'aaaaa'
node3.children[1].title = 'ccccc'
node3.children[2].title = 'bbbbb'

let node1 = wrapper.vm.getById(1)
wrapper.vm.sort(null, true)

expect(node3.children[0].id).toBe(4)
expect(node3.children[1].id).toBe(6)
expect(node3.children[2].id).toBe(5)
})

it('methods: search, clearSearchResult', async ()=>{
let wrapper = mount(TWTree, {
Expand Down Expand Up @@ -1253,6 +1274,58 @@ describe('directory', ()=>{
expect(node3.children.length).toBe(2)
expect(node3.children[1].title).toMatch('world')
})

it('method: fnBeforeExpand', async ()=>{
let wrapper = mount(TWTree, {
propsData: {
tree: directoryTree,
defaultAttrs: {
directoryState: 'collapsed'
},
fnBeforeExpand: function() {
return false
}
}
})
await wrapper.vm.$nextTick()

expect(wrapper.vm.getById(1).directoryState).toMatch('collapsed')
wrapper.vm.expand(wrapper.vm.getById(1))
expect(wrapper.vm.getById(1).directoryState).toMatch('collapsed')
for (let item of wrapper.vm.items) {
if (item.id === 1) {
expect(item.__.isVisible).toBeTruthy()
} else {
expect(item.__.isVisible).toBeFalsy()
}
}
})

it('method: fnBeforeCollapse', async ()=>{
let wrapper = mount(TWTree, {
propsData: {
tree: directoryTree,
defaultAttrs: {
directoryState: 'expanded'
},
fnBeforeCollapse: function() {
return false
}
}
})
await wrapper.vm.$nextTick()

expect(wrapper.vm.getById(1).directoryState).toMatch('expanded')
wrapper.vm.collapse(wrapper.vm.getById(1))
expect(wrapper.vm.getById(1).directoryState).toMatch('expanded')
for (let item of wrapper.vm.items) {
if (item.__.parent !== null && item.__.parent.id === 3) {
expect(item.__.isVisible).toBeFalsy()
} else {
expect(item.__.isVisible).toBeTruthy()
}
}
})
})

describe('drag and drop', ()=>{
Expand Down

0 comments on commit bcae5f8

Please sign in to comment.