fix(cascader-panel): default value doesn't work in lazy mode (#2338)

fix #2312
This commit is contained in:
Simona
2021-06-25 09:38:09 +08:00
committed by GitHub
parent a57727bfa4
commit 1fb35d43eb
2 changed files with 32 additions and 3 deletions

View File

@@ -560,7 +560,7 @@ describe('CascaderPanel.vue', () => {
expect(wrapper.vm.value).toEqual([1, 2])
})
test('lazy load with default value', async () => {
test('lazy load with default primitive value', async () => {
const wrapper = mount(CascaderPanel, {
props: {
props: {
@@ -578,6 +578,35 @@ describe('CascaderPanel.vue', () => {
expect(wrapper.find(`.is-active`).text()).toBe('option2')
})
test('lazy load with default object value', async () => {
const wrapper = mount(CascaderPanel, {
props: {
props: {
lazy: true,
lazyLoad(node, resolve) {
const { level } = node
setTimeout(() => {
const nodes = Array.from({ length: level + 1 })
.map(() => ({
value: { id: ++id },
label: `option${id}`,
leaf: level >= 1,
}))
resolve(nodes)
}, 1000)
},
},
modelValue: [{ id: 1 }, { id: 2 }],
},
})
jest.runAllTimers()
await nextTick()
expect(wrapper.findAll(MENU).length).toBe(2)
expect(wrapper.find(`.is-active`).text()).toBe('option2')
})
test('no loaded nodes should not be checked', async () => {
const wrapper = _mount({
template: `

View File

@@ -59,7 +59,7 @@ export default class Store {
if (!value && value !== 0) return null
const nodes = this.getFlattedNodes(leafOnly)
.filter(node => node.value === value || isEqual(node.pathValues, value))
.filter(node => isEqual(node.value, value) || isEqual(node.pathValues, value))
return nodes[0] || null
}
@@ -68,7 +68,7 @@ export default class Store {
if (!node) return null
const nodes = this.getFlattedNodes(false)
.filter(({ value, level }) => node.value === value && node.level === level)
.filter(({ value, level }) => isEqual(node.value, value) && node.level === level)
return nodes[0] || null
}