mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(cascader-panel): default value doesn't work in lazy mode (#2338)
fix #2312
This commit is contained in:
@@ -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: `
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user