Skip to content

Commit

Permalink
fix: after loading children options of a checked node, should also ch…
Browse files Browse the repository at this point in the history
…eck these children options
  • Loading branch information
riophae committed Apr 8, 2018
1 parent 8b6e398 commit b5faf1e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/mixins/treeselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,12 @@ export default {
if (Array.isArray(rootOptions)) {
this.rootOptionsLoaded = true
this.initializeRootOptions(rootOptions)
this.completeSelectedNodeIdList()
this.buildSelectedNodeMap()
this.buildNodeCheckedStateMap()
} else {
this.initializeRootOptions([])
}

this.completeSelectedNodeIdList()
this.buildSelectedNodeMap()
this.buildNodeCheckedStateMap()
},

getValue() {
Expand Down Expand Up @@ -1143,6 +1142,8 @@ export default {
} else {
parentNode.children = this.normalize(parentNode, children)
parentNode.isLoaded = true
this.completeSelectedNodeIdList()
this.buildSelectedNodeMap()
this.buildNodeCheckedStateMap()
}
}
Expand Down
73 changes: 73 additions & 0 deletions test/unit/specs/Treeselect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3733,6 +3733,79 @@ describe('Props', () => {
jasmine.clock().uninstall()
done()
})

it('after loading children options of a checked node, should also check these children options', async done => {
const wrapper = mount(Treeselect, {
propsData: {
options: [ {
id: 'a',
label: 'a',
children: null,
} ],
multiple: true,
flat: false,
valueFormat: 'id',
valueConsistsOf: 'BRANCH_PRIORITY',
loadChildrenOptions(parentNode, callback) {
if (parentNode.id === 'a') {
callback(null, [ {
id: 'aa',
label: 'aa',
children: null,
}, {
id: 'ab',
label: 'ab',
} ])
}

if (parentNode.id === 'aa') {
callback(null, [ {
id: 'aaa',
label: 'aaa',
}, {
id: 'aab',
label: 'aab',
} ])
}
},
},
data: {
isOpen: true,
},
})
const { vm } = wrapper

vm.select(vm.nodeMap.a)
expect(vm.internalValue).toEqual([ 'a' ])
expect(vm.selectedNodeIds).toEqual([ 'a' ])
expect(vm.nodeCheckedStateMap).toEqual({
a: CHECKED,
})

vm.toggleExpanded(vm.nodeMap.a)
await vm.$nextTick()
expect(vm.internalValue).toEqual([ 'a' ])
expect(vm.selectedNodeIds).toEqual([ 'a', 'aa', 'ab' ])
expect(vm.nodeCheckedStateMap).toEqual({
a: CHECKED,
aa: CHECKED,
ab: CHECKED,
})

vm.toggleExpanded(vm.nodeMap.aa)
await vm.$nextTick()
expect(vm.internalValue).toEqual([ 'a' ])
expect(vm.selectedNodeIds).toEqual([ 'a', 'aa', 'ab', 'aaa', 'aab' ])
expect(vm.nodeCheckedStateMap).toEqual({
a: CHECKED,
aa: CHECKED,
ab: CHECKED,
aaa: CHECKED,
aab: CHECKED,
})

done()
})
})

describe('loadRootOptions', () => {
Expand Down

0 comments on commit b5faf1e

Please sign in to comment.