element-plus/packages/components/cascader-panel/__tests__/cascader-panel.spec.ts

761 lines
19 KiB
TypeScript
Raw Normal View History

2020-10-30 23:26:33 +08:00
import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { Check, Loading } from '@element-plus/icons-vue'
2020-10-30 23:26:33 +08:00
import CascaderPanel from '../src/index.vue'
const NORMAL_OPTIONS = [
{
value: 'beijing',
label: 'Beijing',
children: [],
leaf: true,
},
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
},
{
value: 'ningbo',
label: 'Ningbo',
},
],
},
{
value: 'shanghai',
label: 'Shanghai',
children: [
// for test nodes in different levels have same value
{
value: 'shanghai',
label: 'Shanghai',
},
],
},
{
value: 'guangdong',
label: 'Guangdong',
children: [],
},
2020-10-30 23:26:33 +08:00
]
const DISABLED_OPTIONS = [
{
value: 'beijing',
label: 'beijing',
disabled: true,
},
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
disabled: true,
children: [
{
value: 'nanjing',
label: 'Nanjing',
},
],
},
]
const CUSTOM_PROPS_OPTIONS = [
{
id: 'beijing',
name: 'Beijing',
areas: [],
},
{
id: 'zhejiang',
name: 'Zhejiang',
areas: [
{
id: 'hangzhou',
name: 'Hangzhou',
},
{
id: 'ningbo',
name: 'Ningbo',
invalid: true,
},
],
},
]
const MENU = '.el-cascader-menu'
const NODE = '.el-cascader-node'
const VALID_NODE = '.el-cascader-node:not(.is-disabled)'
epic: refactor icons (#3492) * refactor(components): el-alert icon (#3441) * refactor(components): el-alert icon * fix: el-alert test * fix: [el-alert] lint error * feat(utils): add icon util * refactor(components): el-alert icon * refactor(utils): icon * test: update alert test * refactor: remove el-icon in util * refactor(components): el-notification icon (#3512) * chore: temp save changes * refactor: update icon * fix: var * docs: update icon * fix: type class error * style: remove unused class * fix: update icon type * docs: update icon * fix: update iconComponent * refactor(components): el-dialog icon (#3505) * refactor(components): [el-dialog] icon * fix: typo * refactor: dialog icon ref * refactor: dialog icon * style: update close button size * refactor(components): el-message-box icon (#3507) * refactor(components): message-box icon * refactor(components): message icon * fix: test * refactor: update ref * fix: test * docs: update icon * fix: delete unused code * docs: update type * fix: update close button size * fix: type * fix: icon type class * fix: icon type * fix: update type class * refactor(components): el-popconfirm icon (#3513) * refactor(components): el-popconfirm icon * fix: space styles * docs: update example * docs: update example for trigger event * refactor(components): el-page-header icon (#3518) * refactor(components): el-page-header icon * docs: update icon * fix: space errors * refactor(components): el-steps icon (#3520) * refactor(components): el-backtop icon (#3514) * refactor(components): el-backtop icon * fix: update font size * refactor(components): el-button icon (#3536) * refactor(components): el-button icon * fix: update example * refactor(components): el-button icon * refactor: style simplify Co-authored-by: imswk <syfzxx@vip.qq.com> * refactor(components): el-tree icon (#3590) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-avatar icon (#3599) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-carousel icon (#3602) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-progress icon (#3607) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-result icon (#3609) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-timeline icon (#3646) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-table icon (#3611) Co-authored-by: qianjie <qianjie@patsnap.com> * chore: add vue to gitignore * fix: buildProp error * refactor(components): el-pagination icon (#3605) * test: el-menu deprecated icon font (#3794) * test: el-loading deprecated icon font (#3795) * chore: Update changelog 1.1.0-beta.20 (#3838) * fix: about custom extension of table column (#3437) * refactor(components): el-autocomplete icon (#3783) * refactor(components): el-dropdown icon (#3517) * refactor(components): el-dropdown icon * fix: arrow down icon size * style: revert * fix: font-size * refactor(components): el-link icon (#3538) * refactor(components): el-link icon * refactor: update example * fix: import icons * docs: add tip * refactor: update link icon * fix: icon align * fix: typo * refactor(components): el-select icon (#3780) * refactor(components): el-input icon (#3565) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * docs: icon usage * fix: input style * fix: add scoped * docs: fix icon * fix: icon align * fix: icon align * fix: typo * fix: typo * refactor(components): el-input-number icon (#3566) * refactor(components): el-input-number icon * fix: icon align * refactor(components): el-tag icon (#3793) * refactor(components): el-tag icon * fix: icon align * fix: icon margin * refactor(components): el-switch icon (#3787) * refactor(components): el-switch icon * fix: icon align * docs: add icon usage * refactor(components): el-collapse icon (#3788) * refactor(components): el-collapse icon * docs: update icon demo * fix: typo * refactor(components): el-uplod icon (#3598) * refactor(components): el-uplod icon * docs: update icon useage * docs: fix icon * docs: fix icon * docs: update upload-filled icon * fix: icon align * fix: item icon align * refactor(components): el-select-v2 icon (#3781) * refactor(components): el-select-v2 icon * revert: play/main.ts * fix: icon style * fix: icon solt * refactor(components): el-cascader icon (#3785) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-cascader icon * refactor(components): el-tag icon * fix: icon align * fix: icon margin * docs: icon usage * fix: input style * fix: add scoped * test: remove unuesd code * fix: cascader-panel * fix: icon style * fix: icon animation * refactor(components): el-drawer icon (#3796) * refactor(components): el-drawer icon * fix: close icon size * fix: close icon align * refactor(components): el-transfer icon (#3792) * refactor(components): el-transfer icon * fix: icon align * refactor(components): el-image-viewer icon (#3797) * refactor(components): el-image-view icon * fix: icon size * docs: update domo * style: format vue * fix: fullscreen icon * Add cursor for icons Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * refactor(components): rate-icon (#3891) * refactor(components): el-rate icon * docs: update example * docs: update * test: update * docs: update * fix: variable rename * fix: demo update * fix: allow half bug * refactor(components): el-time-picker icon (#3834) * refactor(components): el-button icon * refactor(components): date-picker icon * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-time-select icon * fix: icon width * docs: icon usage * fix: input style * fix: add scoped * fix: icon size * docs: icon display * fix: icon in button * docs: fix error * refactor(components): el-time-picker icon * fix: var * fix: icon align * test: delete unused code * test: fix error * fix: remove unused code * docs: fix typo * docs: update icon * fix: default prefix icon * fix: range picker icon align * Update cursor for picker Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * fix(components): el-input close icon * chore: delete fonts * fix: copy full style Co-authored-by: imswk <syfzxx@vip.qq.com> Co-authored-by: bastarder <85257684@qq.com> Co-authored-by: qianjie <qianjie@patsnap.com> Co-authored-by: Element <wallement@gmail.com> Co-authored-by: Alan Wang <948467222@qq.com> Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-10-27 23:17:13 +08:00
const EXPAND_ARROW = '.arrow-right.el-cascader-node__postfix'
2020-10-30 23:26:33 +08:00
const CHECKBOX = '.el-checkbox__input'
const RADIO = '.el-radio__input'
let id = 0
epic: refactor icons (#3492) * refactor(components): el-alert icon (#3441) * refactor(components): el-alert icon * fix: el-alert test * fix: [el-alert] lint error * feat(utils): add icon util * refactor(components): el-alert icon * refactor(utils): icon * test: update alert test * refactor: remove el-icon in util * refactor(components): el-notification icon (#3512) * chore: temp save changes * refactor: update icon * fix: var * docs: update icon * fix: type class error * style: remove unused class * fix: update icon type * docs: update icon * fix: update iconComponent * refactor(components): el-dialog icon (#3505) * refactor(components): [el-dialog] icon * fix: typo * refactor: dialog icon ref * refactor: dialog icon * style: update close button size * refactor(components): el-message-box icon (#3507) * refactor(components): message-box icon * refactor(components): message icon * fix: test * refactor: update ref * fix: test * docs: update icon * fix: delete unused code * docs: update type * fix: update close button size * fix: type * fix: icon type class * fix: icon type * fix: update type class * refactor(components): el-popconfirm icon (#3513) * refactor(components): el-popconfirm icon * fix: space styles * docs: update example * docs: update example for trigger event * refactor(components): el-page-header icon (#3518) * refactor(components): el-page-header icon * docs: update icon * fix: space errors * refactor(components): el-steps icon (#3520) * refactor(components): el-backtop icon (#3514) * refactor(components): el-backtop icon * fix: update font size * refactor(components): el-button icon (#3536) * refactor(components): el-button icon * fix: update example * refactor(components): el-button icon * refactor: style simplify Co-authored-by: imswk <syfzxx@vip.qq.com> * refactor(components): el-tree icon (#3590) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-avatar icon (#3599) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-carousel icon (#3602) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-progress icon (#3607) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-result icon (#3609) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-timeline icon (#3646) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-table icon (#3611) Co-authored-by: qianjie <qianjie@patsnap.com> * chore: add vue to gitignore * fix: buildProp error * refactor(components): el-pagination icon (#3605) * test: el-menu deprecated icon font (#3794) * test: el-loading deprecated icon font (#3795) * chore: Update changelog 1.1.0-beta.20 (#3838) * fix: about custom extension of table column (#3437) * refactor(components): el-autocomplete icon (#3783) * refactor(components): el-dropdown icon (#3517) * refactor(components): el-dropdown icon * fix: arrow down icon size * style: revert * fix: font-size * refactor(components): el-link icon (#3538) * refactor(components): el-link icon * refactor: update example * fix: import icons * docs: add tip * refactor: update link icon * fix: icon align * fix: typo * refactor(components): el-select icon (#3780) * refactor(components): el-input icon (#3565) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * docs: icon usage * fix: input style * fix: add scoped * docs: fix icon * fix: icon align * fix: icon align * fix: typo * fix: typo * refactor(components): el-input-number icon (#3566) * refactor(components): el-input-number icon * fix: icon align * refactor(components): el-tag icon (#3793) * refactor(components): el-tag icon * fix: icon align * fix: icon margin * refactor(components): el-switch icon (#3787) * refactor(components): el-switch icon * fix: icon align * docs: add icon usage * refactor(components): el-collapse icon (#3788) * refactor(components): el-collapse icon * docs: update icon demo * fix: typo * refactor(components): el-uplod icon (#3598) * refactor(components): el-uplod icon * docs: update icon useage * docs: fix icon * docs: fix icon * docs: update upload-filled icon * fix: icon align * fix: item icon align * refactor(components): el-select-v2 icon (#3781) * refactor(components): el-select-v2 icon * revert: play/main.ts * fix: icon style * fix: icon solt * refactor(components): el-cascader icon (#3785) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-cascader icon * refactor(components): el-tag icon * fix: icon align * fix: icon margin * docs: icon usage * fix: input style * fix: add scoped * test: remove unuesd code * fix: cascader-panel * fix: icon style * fix: icon animation * refactor(components): el-drawer icon (#3796) * refactor(components): el-drawer icon * fix: close icon size * fix: close icon align * refactor(components): el-transfer icon (#3792) * refactor(components): el-transfer icon * fix: icon align * refactor(components): el-image-viewer icon (#3797) * refactor(components): el-image-view icon * fix: icon size * docs: update domo * style: format vue * fix: fullscreen icon * Add cursor for icons Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * refactor(components): rate-icon (#3891) * refactor(components): el-rate icon * docs: update example * docs: update * test: update * docs: update * fix: variable rename * fix: demo update * fix: allow half bug * refactor(components): el-time-picker icon (#3834) * refactor(components): el-button icon * refactor(components): date-picker icon * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-time-select icon * fix: icon width * docs: icon usage * fix: input style * fix: add scoped * fix: icon size * docs: icon display * fix: icon in button * docs: fix error * refactor(components): el-time-picker icon * fix: var * fix: icon align * test: delete unused code * test: fix error * fix: remove unused code * docs: fix typo * docs: update icon * fix: default prefix icon * fix: range picker icon align * Update cursor for picker Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * fix(components): el-input close icon * chore: delete fonts * fix: copy full style Co-authored-by: imswk <syfzxx@vip.qq.com> Co-authored-by: bastarder <85257684@qq.com> Co-authored-by: qianjie <qianjie@patsnap.com> Co-authored-by: Element <wallement@gmail.com> Co-authored-by: Alan Wang <948467222@qq.com> Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-10-27 23:17:13 +08:00
console.warn = function () {
// noop
}
const _mount: typeof mount = (options) =>
mount({
components: {
CascaderPanel,
},
...options,
})
2020-10-30 23:26:33 +08:00
const lazyLoad = (node, resolve) => {
const { level } = node
setTimeout(() => {
const nodes = Array.from({ length: level + 1 }).map(() => ({
value: ++id,
label: `option${id}`,
leaf: level >= 1,
}))
2020-10-30 23:26:33 +08:00
resolve(nodes)
}, 1000)
}
beforeEach(() => {
id = 0
})
jest.useFakeTimers()
describe('CascaderPanel.vue', () => {
test('expand and check', async () => {
const handleChange = jest.fn()
const handleExpandChange = jest.fn()
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
@change="handleChange"
@expand-change="handleExpandChange"
/>
`,
data() {
return {
options: NORMAL_OPTIONS,
value: [],
}
},
methods: {
handleChange,
handleExpandChange,
},
})
const options = wrapper.findAll(NODE)
const [bjNode, zjNode, , gdNode] = options
2020-10-30 23:26:33 +08:00
expect(wrapper.findAll(MENU).length).toBe(1)
expect(options.length).toBe(4)
2020-10-30 23:26:33 +08:00
expect(bjNode.text()).toBe('Beijing')
expect(bjNode.find(EXPAND_ARROW).exists()).toBe(false)
expect(zjNode.find(EXPAND_ARROW).exists()).toBe(true)
expect(gdNode.find(EXPAND_ARROW).exists()).toBe(false)
2020-10-30 23:26:33 +08:00
await zjNode.trigger('click')
const menus = wrapper.findAll(MENU)
const hzNode = menus[1].find(NODE)
expect(menus.length).toBe(2)
expect(handleExpandChange).toBeCalledTimes(1)
await hzNode.trigger('click')
// won't trigger when expanding node not change
expect(handleExpandChange).toBeCalledTimes(1)
expect(handleChange).toBeCalledTimes(1)
expect(wrapper.vm.value).toEqual(['zhejiang', 'hangzhou'])
await bjNode.trigger('click')
expect(wrapper.findAll(MENU).length).toBe(1)
expect(handleExpandChange).toBeCalledTimes(2)
expect(handleChange).toBeCalledTimes(2)
expect(wrapper.vm.value).toEqual(['beijing'])
await gdNode.trigger('click')
expect(wrapper.findAll(MENU).length).toBe(1)
expect(handleExpandChange).toBeCalledTimes(3)
expect(handleChange).toBeCalledTimes(3)
expect(wrapper.vm.value).toEqual(['guangdong'])
2020-10-30 23:26:33 +08:00
})
test('with default value', async () => {
const wrapper = mount(CascaderPanel, {
props: {
modelValue: ['zhejiang', 'hangzhou'],
options: NORMAL_OPTIONS,
},
})
await nextTick()
const menus = wrapper.findAll(MENU)
const [, zjNode, shNode] = menus[0].findAll(NODE)
const hzNode = menus[1].find(NODE)
expect(menus.length).toBe(2)
expect(zjNode.classes('in-active-path')).toBe(true)
expect(hzNode.classes('is-active')).toBe(true)
epic: refactor icons (#3492) * refactor(components): el-alert icon (#3441) * refactor(components): el-alert icon * fix: el-alert test * fix: [el-alert] lint error * feat(utils): add icon util * refactor(components): el-alert icon * refactor(utils): icon * test: update alert test * refactor: remove el-icon in util * refactor(components): el-notification icon (#3512) * chore: temp save changes * refactor: update icon * fix: var * docs: update icon * fix: type class error * style: remove unused class * fix: update icon type * docs: update icon * fix: update iconComponent * refactor(components): el-dialog icon (#3505) * refactor(components): [el-dialog] icon * fix: typo * refactor: dialog icon ref * refactor: dialog icon * style: update close button size * refactor(components): el-message-box icon (#3507) * refactor(components): message-box icon * refactor(components): message icon * fix: test * refactor: update ref * fix: test * docs: update icon * fix: delete unused code * docs: update type * fix: update close button size * fix: type * fix: icon type class * fix: icon type * fix: update type class * refactor(components): el-popconfirm icon (#3513) * refactor(components): el-popconfirm icon * fix: space styles * docs: update example * docs: update example for trigger event * refactor(components): el-page-header icon (#3518) * refactor(components): el-page-header icon * docs: update icon * fix: space errors * refactor(components): el-steps icon (#3520) * refactor(components): el-backtop icon (#3514) * refactor(components): el-backtop icon * fix: update font size * refactor(components): el-button icon (#3536) * refactor(components): el-button icon * fix: update example * refactor(components): el-button icon * refactor: style simplify Co-authored-by: imswk <syfzxx@vip.qq.com> * refactor(components): el-tree icon (#3590) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-avatar icon (#3599) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-carousel icon (#3602) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-progress icon (#3607) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-result icon (#3609) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-timeline icon (#3646) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-table icon (#3611) Co-authored-by: qianjie <qianjie@patsnap.com> * chore: add vue to gitignore * fix: buildProp error * refactor(components): el-pagination icon (#3605) * test: el-menu deprecated icon font (#3794) * test: el-loading deprecated icon font (#3795) * chore: Update changelog 1.1.0-beta.20 (#3838) * fix: about custom extension of table column (#3437) * refactor(components): el-autocomplete icon (#3783) * refactor(components): el-dropdown icon (#3517) * refactor(components): el-dropdown icon * fix: arrow down icon size * style: revert * fix: font-size * refactor(components): el-link icon (#3538) * refactor(components): el-link icon * refactor: update example * fix: import icons * docs: add tip * refactor: update link icon * fix: icon align * fix: typo * refactor(components): el-select icon (#3780) * refactor(components): el-input icon (#3565) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * docs: icon usage * fix: input style * fix: add scoped * docs: fix icon * fix: icon align * fix: icon align * fix: typo * fix: typo * refactor(components): el-input-number icon (#3566) * refactor(components): el-input-number icon * fix: icon align * refactor(components): el-tag icon (#3793) * refactor(components): el-tag icon * fix: icon align * fix: icon margin * refactor(components): el-switch icon (#3787) * refactor(components): el-switch icon * fix: icon align * docs: add icon usage * refactor(components): el-collapse icon (#3788) * refactor(components): el-collapse icon * docs: update icon demo * fix: typo * refactor(components): el-uplod icon (#3598) * refactor(components): el-uplod icon * docs: update icon useage * docs: fix icon * docs: fix icon * docs: update upload-filled icon * fix: icon align * fix: item icon align * refactor(components): el-select-v2 icon (#3781) * refactor(components): el-select-v2 icon * revert: play/main.ts * fix: icon style * fix: icon solt * refactor(components): el-cascader icon (#3785) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-cascader icon * refactor(components): el-tag icon * fix: icon align * fix: icon margin * docs: icon usage * fix: input style * fix: add scoped * test: remove unuesd code * fix: cascader-panel * fix: icon style * fix: icon animation * refactor(components): el-drawer icon (#3796) * refactor(components): el-drawer icon * fix: close icon size * fix: close icon align * refactor(components): el-transfer icon (#3792) * refactor(components): el-transfer icon * fix: icon align * refactor(components): el-image-viewer icon (#3797) * refactor(components): el-image-view icon * fix: icon size * docs: update domo * style: format vue * fix: fullscreen icon * Add cursor for icons Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * refactor(components): rate-icon (#3891) * refactor(components): el-rate icon * docs: update example * docs: update * test: update * docs: update * fix: variable rename * fix: demo update * fix: allow half bug * refactor(components): el-time-picker icon (#3834) * refactor(components): el-button icon * refactor(components): date-picker icon * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-time-select icon * fix: icon width * docs: icon usage * fix: input style * fix: add scoped * fix: icon size * docs: icon display * fix: icon in button * docs: fix error * refactor(components): el-time-picker icon * fix: var * fix: icon align * test: delete unused code * test: fix error * fix: remove unused code * docs: fix typo * docs: update icon * fix: default prefix icon * fix: range picker icon align * Update cursor for picker Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * fix(components): el-input close icon * chore: delete fonts * fix: copy full style Co-authored-by: imswk <syfzxx@vip.qq.com> Co-authored-by: bastarder <85257684@qq.com> Co-authored-by: qianjie <qianjie@patsnap.com> Co-authored-by: Element <wallement@gmail.com> Co-authored-by: Alan Wang <948467222@qq.com> Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-10-27 23:17:13 +08:00
expect(hzNode.findComponent(Check).exists()).toBe(true)
2020-10-30 23:26:33 +08:00
await wrapper.setProps({ modelValue: ['beijing'] })
expect(wrapper.findAll(MENU).length).toBe(1)
expect(wrapper.find(NODE).classes('is-active')).toBe(true)
// leaf node should be checked
await wrapper.setProps({ modelValue: ['shanghai', 'shanghai'] })
const secondMenu = wrapper.findAll(MENU)[1]
expect(shNode.classes('is-active')).toBe(false)
expect(secondMenu.find(NODE).classes('is-active')).toBe(true)
// leaf node should be checked
await wrapper.setProps({ modelValue: null })
expect(wrapper.find('is-active').exists()).toBe(false)
})
test('disabled options', async () => {
const handleChange = jest.fn()
const handleExpandChange = jest.fn()
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
@change="handleChange"
@expand-change="handleExpandChange"
/>
`,
data() {
return {
options: DISABLED_OPTIONS,
value: [],
}
},
methods: {
handleChange,
handleExpandChange,
},
})
const [bjNode, zjNode, jsNode] = wrapper.findAll(NODE)
expect(wrapper.findAll(VALID_NODE).length).toBe(1)
await bjNode.trigger('click')
expect(handleChange).not.toBeCalled()
expect(handleExpandChange).not.toBeCalled()
await jsNode.trigger('click')
expect(handleExpandChange).not.toBeCalled()
await zjNode.trigger('click')
expect(wrapper.findAll(MENU).length).toBe(2)
expect(handleExpandChange).toBeCalledTimes(1)
})
test('options change', async () => {
const wrapper = mount(CascaderPanel, {
props: {
options: NORMAL_OPTIONS,
},
})
expect(wrapper.find(NODE).exists()).toBe(true)
await wrapper.setProps({ options: null })
expect(wrapper.find(NODE).exists()).toBe(false)
})
test('expand by hover', async () => {
const wrapper = mount(CascaderPanel, {
props: {
options: DISABLED_OPTIONS,
props: {
expandTrigger: 'hover',
},
},
})
const [zjNode, jsNode] = wrapper.findAll(NODE).slice(1)
await jsNode.trigger('mouseenter')
expect(wrapper.findAll(MENU).length).toBe(1)
await zjNode.trigger('mouseenter')
expect(wrapper.findAll(MENU).length).toBe(2)
})
test('emit value only', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: NORMAL_OPTIONS,
props: { emitPath: false },
value: 'shanghai',
}
},
})
await nextTick()
const shNode = wrapper.findAll(MENU)[1].find(NODE)
expect(shNode.classes('is-active')).toBe(true)
await wrapper.find(NODE).trigger('click')
expect(wrapper.vm.value).toBe('beijing')
})
test('emit value only, issue 1531', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: [
{
value: 0,
label: 'label one',
},
{
value: 1,
label: 'label two',
},
],
props: { emitPath: false },
value: null,
}
},
})
await nextTick()
const shNode = wrapper.findAll(MENU)[0].find(NODE)
expect(shNode.classes('is-active')).toBe(false)
await wrapper.findAll(NODE)[0].trigger('click')
expect(wrapper.vm.value).toBe(0)
await wrapper.findAll(NODE)[1].trigger('click')
expect(wrapper.vm.value).toBe(1)
})
2020-10-30 23:26:33 +08:00
test('multiple mode', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: NORMAL_OPTIONS,
props: { multiple: true },
value: [],
}
},
})
const zjNode = wrapper.findAll(NODE)[1]
const zjCheckbox = zjNode.find(CHECKBOX)
expect(zjCheckbox.exists()).toBe(true)
await zjNode.trigger('click')
const secondMenu = wrapper.findAll(MENU)[1]
const [hzCheckbox, nbCheckbox] = secondMenu.findAll(CHECKBOX)
await hzCheckbox.find('input').trigger('click')
expect(hzCheckbox.classes('is-checked')).toBe(true)
expect(zjCheckbox.classes('is-indeterminate')).toBe(true)
expect(wrapper.vm.value).toEqual([['zhejiang', 'hangzhou']])
await nbCheckbox.find('input').trigger('click')
expect(zjCheckbox.classes('is-checked')).toBe(true)
expect(wrapper.vm.value).toEqual([
['zhejiang', 'hangzhou'],
['zhejiang', 'ningbo'],
])
2020-10-30 23:26:33 +08:00
await zjCheckbox.find('input').trigger('click')
expect(zjCheckbox.classes('is-checked')).toBe(false)
expect(nbCheckbox.classes('is-checked')).toBe(false)
expect(nbCheckbox.classes('is-checked')).toBe(false)
expect(wrapper.vm.value).toEqual([])
})
test('multiple mode with disabled default value', async () => {
const wrapper = mount(CascaderPanel, {
props: {
options: DISABLED_OPTIONS,
props: { multiple: true },
modelValue: [['beijing']],
},
})
await nextTick()
const bjNode = wrapper.find(NODE)
const bjCheckbox = wrapper.find(CHECKBOX)
expect(bjNode.classes('is-disabled')).toBe(true)
expect(bjCheckbox.classes('is-disabled')).toBe(true)
expect(bjCheckbox.classes('is-checked')).toBe(true)
})
test('check strictly in single mode', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: NORMAL_OPTIONS,
props: { checkStrictly: true },
value: [],
}
},
})
const zjRadio = wrapper.findAll(RADIO)[1]
expect(zjRadio.exists()).toBe(true)
await zjRadio.find('input').trigger('click')
expect(wrapper.vm.value).toEqual(['zhejiang'])
})
test('check strictly in single mode with disabled options', async () => {
const wrapper = mount(CascaderPanel, {
props: {
options: DISABLED_OPTIONS,
props: { checkStrictly: true },
},
})
const [bjNode, , jsNode] = wrapper.findAll(NODE)
const bjRadio = bjNode.find(RADIO)
// leaf nodes should add a disabled style for that they are not expandable
// but non-leaf nodes are not
expect(bjNode.classes('is-disabled')).toBe(true)
expect(jsNode.classes('is-disabled')).toBe(false)
expect(bjRadio.classes('is-disabled')).toBe(true)
expect(bjRadio.find('input[disabled]').exists()).toBe(true)
await jsNode.trigger('click')
expect(wrapper.findAll(MENU).length).toEqual(2)
})
test('check strictly in multiple mode', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: NORMAL_OPTIONS,
props: { checkStrictly: true, multiple: true },
value: [['shanghai']],
}
},
})
const shNode = wrapper.findAll(NODE)[2]
const [, zjCheckbox, shCheckbox] = wrapper.findAll(CHECKBOX)
await nextTick()
await shNode.trigger('click')
const shCheckbox2 = wrapper.findAll(MENU)[1].find(CHECKBOX)
expect(shCheckbox.classes('is-checked')).toBe(true)
expect(shCheckbox2.classes('is-checked')).toBe(false)
await zjCheckbox.find('input').trigger('click')
expect(wrapper.vm.value).toEqual([['shanghai'], ['zhejiang']])
})
test('custom props', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:options="options"
:props="props"
/>
`,
data() {
return {
options: CUSTOM_PROPS_OPTIONS,
props: {
value: 'id',
label: 'name',
children: 'areas',
disabled: 'invalid',
leaf: (data: typeof CUSTOM_PROPS_OPTIONS[0]) => !data.areas?.length,
},
value: [],
}
},
})
const [bjNode, zjNode] = wrapper.findAll(NODE)
expect(bjNode.text()).toBe('Beijing')
expect(bjNode.find(EXPAND_ARROW).exists()).toBe(false)
await zjNode.trigger('click')
const [hzNode, nbNode] = wrapper.findAll(MENU)[1].findAll(NODE)
expect(hzNode.exists()).toBe(true)
expect(nbNode.classes('is-disabled')).toBe(true)
await hzNode.trigger('click')
expect(wrapper.vm.value).toEqual(['zhejiang', 'hangzhou'])
})
test('lazy load', async () => {
const wrapper = _mount({
template: `
<cascader-panel
v-model="value"
:props="props"
/>
`,
data() {
return {
value: [],
props: {
lazy: true,
lazyLoad,
},
}
},
})
jest.runAllTimers()
await nextTick()
const firstOption = wrapper.find(NODE)
expect(firstOption.exists()).toBe(true)
await firstOption.trigger('click')
epic: refactor icons (#3492) * refactor(components): el-alert icon (#3441) * refactor(components): el-alert icon * fix: el-alert test * fix: [el-alert] lint error * feat(utils): add icon util * refactor(components): el-alert icon * refactor(utils): icon * test: update alert test * refactor: remove el-icon in util * refactor(components): el-notification icon (#3512) * chore: temp save changes * refactor: update icon * fix: var * docs: update icon * fix: type class error * style: remove unused class * fix: update icon type * docs: update icon * fix: update iconComponent * refactor(components): el-dialog icon (#3505) * refactor(components): [el-dialog] icon * fix: typo * refactor: dialog icon ref * refactor: dialog icon * style: update close button size * refactor(components): el-message-box icon (#3507) * refactor(components): message-box icon * refactor(components): message icon * fix: test * refactor: update ref * fix: test * docs: update icon * fix: delete unused code * docs: update type * fix: update close button size * fix: type * fix: icon type class * fix: icon type * fix: update type class * refactor(components): el-popconfirm icon (#3513) * refactor(components): el-popconfirm icon * fix: space styles * docs: update example * docs: update example for trigger event * refactor(components): el-page-header icon (#3518) * refactor(components): el-page-header icon * docs: update icon * fix: space errors * refactor(components): el-steps icon (#3520) * refactor(components): el-backtop icon (#3514) * refactor(components): el-backtop icon * fix: update font size * refactor(components): el-button icon (#3536) * refactor(components): el-button icon * fix: update example * refactor(components): el-button icon * refactor: style simplify Co-authored-by: imswk <syfzxx@vip.qq.com> * refactor(components): el-tree icon (#3590) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-avatar icon (#3599) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-carousel icon (#3602) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-progress icon (#3607) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-result icon (#3609) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-timeline icon (#3646) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-table icon (#3611) Co-authored-by: qianjie <qianjie@patsnap.com> * chore: add vue to gitignore * fix: buildProp error * refactor(components): el-pagination icon (#3605) * test: el-menu deprecated icon font (#3794) * test: el-loading deprecated icon font (#3795) * chore: Update changelog 1.1.0-beta.20 (#3838) * fix: about custom extension of table column (#3437) * refactor(components): el-autocomplete icon (#3783) * refactor(components): el-dropdown icon (#3517) * refactor(components): el-dropdown icon * fix: arrow down icon size * style: revert * fix: font-size * refactor(components): el-link icon (#3538) * refactor(components): el-link icon * refactor: update example * fix: import icons * docs: add tip * refactor: update link icon * fix: icon align * fix: typo * refactor(components): el-select icon (#3780) * refactor(components): el-input icon (#3565) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * docs: icon usage * fix: input style * fix: add scoped * docs: fix icon * fix: icon align * fix: icon align * fix: typo * fix: typo * refactor(components): el-input-number icon (#3566) * refactor(components): el-input-number icon * fix: icon align * refactor(components): el-tag icon (#3793) * refactor(components): el-tag icon * fix: icon align * fix: icon margin * refactor(components): el-switch icon (#3787) * refactor(components): el-switch icon * fix: icon align * docs: add icon usage * refactor(components): el-collapse icon (#3788) * refactor(components): el-collapse icon * docs: update icon demo * fix: typo * refactor(components): el-uplod icon (#3598) * refactor(components): el-uplod icon * docs: update icon useage * docs: fix icon * docs: fix icon * docs: update upload-filled icon * fix: icon align * fix: item icon align * refactor(components): el-select-v2 icon (#3781) * refactor(components): el-select-v2 icon * revert: play/main.ts * fix: icon style * fix: icon solt * refactor(components): el-cascader icon (#3785) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-cascader icon * refactor(components): el-tag icon * fix: icon align * fix: icon margin * docs: icon usage * fix: input style * fix: add scoped * test: remove unuesd code * fix: cascader-panel * fix: icon style * fix: icon animation * refactor(components): el-drawer icon (#3796) * refactor(components): el-drawer icon * fix: close icon size * fix: close icon align * refactor(components): el-transfer icon (#3792) * refactor(components): el-transfer icon * fix: icon align * refactor(components): el-image-viewer icon (#3797) * refactor(components): el-image-view icon * fix: icon size * docs: update domo * style: format vue * fix: fullscreen icon * Add cursor for icons Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * refactor(components): rate-icon (#3891) * refactor(components): el-rate icon * docs: update example * docs: update * test: update * docs: update * fix: variable rename * fix: demo update * fix: allow half bug * refactor(components): el-time-picker icon (#3834) * refactor(components): el-button icon * refactor(components): date-picker icon * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-time-select icon * fix: icon width * docs: icon usage * fix: input style * fix: add scoped * fix: icon size * docs: icon display * fix: icon in button * docs: fix error * refactor(components): el-time-picker icon * fix: var * fix: icon align * test: delete unused code * test: fix error * fix: remove unused code * docs: fix typo * docs: update icon * fix: default prefix icon * fix: range picker icon align * Update cursor for picker Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * fix(components): el-input close icon * chore: delete fonts * fix: copy full style Co-authored-by: imswk <syfzxx@vip.qq.com> Co-authored-by: bastarder <85257684@qq.com> Co-authored-by: qianjie <qianjie@patsnap.com> Co-authored-by: Element <wallement@gmail.com> Co-authored-by: Alan Wang <948467222@qq.com> Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-10-27 23:17:13 +08:00
expect(firstOption.findComponent(Loading).exists()).toBe(true)
2020-10-30 23:26:33 +08:00
jest.runAllTimers()
await nextTick()
epic: refactor icons (#3492) * refactor(components): el-alert icon (#3441) * refactor(components): el-alert icon * fix: el-alert test * fix: [el-alert] lint error * feat(utils): add icon util * refactor(components): el-alert icon * refactor(utils): icon * test: update alert test * refactor: remove el-icon in util * refactor(components): el-notification icon (#3512) * chore: temp save changes * refactor: update icon * fix: var * docs: update icon * fix: type class error * style: remove unused class * fix: update icon type * docs: update icon * fix: update iconComponent * refactor(components): el-dialog icon (#3505) * refactor(components): [el-dialog] icon * fix: typo * refactor: dialog icon ref * refactor: dialog icon * style: update close button size * refactor(components): el-message-box icon (#3507) * refactor(components): message-box icon * refactor(components): message icon * fix: test * refactor: update ref * fix: test * docs: update icon * fix: delete unused code * docs: update type * fix: update close button size * fix: type * fix: icon type class * fix: icon type * fix: update type class * refactor(components): el-popconfirm icon (#3513) * refactor(components): el-popconfirm icon * fix: space styles * docs: update example * docs: update example for trigger event * refactor(components): el-page-header icon (#3518) * refactor(components): el-page-header icon * docs: update icon * fix: space errors * refactor(components): el-steps icon (#3520) * refactor(components): el-backtop icon (#3514) * refactor(components): el-backtop icon * fix: update font size * refactor(components): el-button icon (#3536) * refactor(components): el-button icon * fix: update example * refactor(components): el-button icon * refactor: style simplify Co-authored-by: imswk <syfzxx@vip.qq.com> * refactor(components): el-tree icon (#3590) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-avatar icon (#3599) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-carousel icon (#3602) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-progress icon (#3607) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-result icon (#3609) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-timeline icon (#3646) Co-authored-by: qianjie <qianjie@patsnap.com> * refactor(components): el-table icon (#3611) Co-authored-by: qianjie <qianjie@patsnap.com> * chore: add vue to gitignore * fix: buildProp error * refactor(components): el-pagination icon (#3605) * test: el-menu deprecated icon font (#3794) * test: el-loading deprecated icon font (#3795) * chore: Update changelog 1.1.0-beta.20 (#3838) * fix: about custom extension of table column (#3437) * refactor(components): el-autocomplete icon (#3783) * refactor(components): el-dropdown icon (#3517) * refactor(components): el-dropdown icon * fix: arrow down icon size * style: revert * fix: font-size * refactor(components): el-link icon (#3538) * refactor(components): el-link icon * refactor: update example * fix: import icons * docs: add tip * refactor: update link icon * fix: icon align * fix: typo * refactor(components): el-select icon (#3780) * refactor(components): el-input icon (#3565) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * docs: icon usage * fix: input style * fix: add scoped * docs: fix icon * fix: icon align * fix: icon align * fix: typo * fix: typo * refactor(components): el-input-number icon (#3566) * refactor(components): el-input-number icon * fix: icon align * refactor(components): el-tag icon (#3793) * refactor(components): el-tag icon * fix: icon align * fix: icon margin * refactor(components): el-switch icon (#3787) * refactor(components): el-switch icon * fix: icon align * docs: add icon usage * refactor(components): el-collapse icon (#3788) * refactor(components): el-collapse icon * docs: update icon demo * fix: typo * refactor(components): el-uplod icon (#3598) * refactor(components): el-uplod icon * docs: update icon useage * docs: fix icon * docs: fix icon * docs: update upload-filled icon * fix: icon align * fix: item icon align * refactor(components): el-select-v2 icon (#3781) * refactor(components): el-select-v2 icon * revert: play/main.ts * fix: icon style * fix: icon solt * refactor(components): el-cascader icon (#3785) * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-cascader icon * refactor(components): el-tag icon * fix: icon align * fix: icon margin * docs: icon usage * fix: input style * fix: add scoped * test: remove unuesd code * fix: cascader-panel * fix: icon style * fix: icon animation * refactor(components): el-drawer icon (#3796) * refactor(components): el-drawer icon * fix: close icon size * fix: close icon align * refactor(components): el-transfer icon (#3792) * refactor(components): el-transfer icon * fix: icon align * refactor(components): el-image-viewer icon (#3797) * refactor(components): el-image-view icon * fix: icon size * docs: update domo * style: format vue * fix: fullscreen icon * Add cursor for icons Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * refactor(components): rate-icon (#3891) * refactor(components): el-rate icon * docs: update example * docs: update * test: update * docs: update * fix: variable rename * fix: demo update * fix: allow half bug * refactor(components): el-time-picker icon (#3834) * refactor(components): el-button icon * refactor(components): date-picker icon * refactor(components): input icon * docs: update example * refactor(components): el-select icon * refactor(components): el-time-select icon * fix: icon width * docs: icon usage * fix: input style * fix: add scoped * fix: icon size * docs: icon display * fix: icon in button * docs: fix error * refactor(components): el-time-picker icon * fix: var * fix: icon align * test: delete unused code * test: fix error * fix: remove unused code * docs: fix typo * docs: update icon * fix: default prefix icon * fix: range picker icon align * Update cursor for picker Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> * fix(components): el-input close icon * chore: delete fonts * fix: copy full style Co-authored-by: imswk <syfzxx@vip.qq.com> Co-authored-by: bastarder <85257684@qq.com> Co-authored-by: qianjie <qianjie@patsnap.com> Co-authored-by: Element <wallement@gmail.com> Co-authored-by: Alan Wang <948467222@qq.com> Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-10-27 23:17:13 +08:00
expect(firstOption.findComponent(Loading).exists()).toBe(false)
2020-10-30 23:26:33 +08:00
const secondMenu = wrapper.findAll(MENU)[1]
expect(secondMenu.exists()).toBe(true)
await secondMenu.find(NODE).trigger('click')
expect(wrapper.vm.value).toEqual([1, 2])
})
test('lazy load with default primitive value', async () => {
2020-10-30 23:26:33 +08:00
const wrapper = mount(CascaderPanel, {
props: {
props: {
lazy: true,
lazyLoad,
},
modelValue: [1, 2],
},
})
jest.runAllTimers()
await nextTick()
expect(wrapper.findAll(MENU).length).toBe(2)
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: `
<cascader-panel
:props="props"
/>
`,
data() {
return {
props: {
multiple: true,
lazy: true,
lazyLoad(node, resolve) {
const { level } = node
setTimeout(() => {
const nodes = Array.from({ length: level + 1 }).map(() => {
++id
return {
value: id,
label: `option${id}`,
leaf: id === 3,
}
})
resolve(nodes)
}, 1000)
},
},
}
},
})
jest.runAllTimers()
await nextTick()
const firstMenu = wrapper.findAll(MENU)[0]
const firstOption = wrapper.find(NODE)
await firstOption.trigger('click')
jest.runAllTimers()
await nextTick()
await firstMenu.find(CHECKBOX).find('input').trigger('click')
const secondMenu = wrapper.findAll(MENU)[1]
expect(secondMenu.exists()).toBe(true)
expect(firstMenu.find(CHECKBOX).classes('is-checked')).toBe(false)
expect(firstMenu.find(CHECKBOX).classes('is-indeterminate')).toBe(true)
expect(secondMenu.findAll(CHECKBOX)[0].classes('is-checked')).toBe(false)
expect(secondMenu.findAll(CHECKBOX)[0].classes('is-indeterminate')).toBe(
false
)
expect(secondMenu.findAll(CHECKBOX)[1].classes('is-checked')).toBe(true)
expect(secondMenu.findAll(CHECKBOX)[1].classes('is-indeterminate')).toBe(
false
)
})
test('no loaded nodes with checkStrictly should be selectable', async () => {
const wrapper = _mount({
template: `
<cascader-panel
:props="props"
/>
`,
data() {
return {
props: {
checkStrictly: true,
lazy: true,
lazyLoad(node, resolve) {
const { level } = node
setTimeout(() => {
const nodes = Array.from({ length: level + 1 }).map(() => ({
value: ++id,
label: `Option - ${id}`,
leaf: level >= 2,
}))
resolve(nodes)
}, 1000)
},
},
}
},
})
jest.runAllTimers()
await nextTick()
const firstMenu = wrapper.findAll(MENU)[0]
await firstMenu.find(RADIO).trigger('click')
expect(firstMenu.find(RADIO).classes('is-checked')).toBe(true)
expect(firstMenu.find(RADIO).classes('is-indeterminate')).toBe(false)
jest.runAllTimers()
await nextTick()
let secondMenu = wrapper.findAll(MENU)[1]
expect(secondMenu).toBeUndefined()
await firstMenu.find(NODE).trigger('click')
jest.runAllTimers()
await nextTick()
secondMenu = wrapper.findAll(MENU)[1]
await secondMenu.find(NODE).trigger('click')
expect(secondMenu.find(RADIO).classes('is-checked')).toBe(false)
expect(secondMenu.find(RADIO).classes('is-indeterminate')).toBe(false)
})
2020-10-30 23:26:33 +08:00
test('getCheckedNodes and clearCheckedNodes', () => {
const wrapper = mount(CascaderPanel, {
props: {
options: NORMAL_OPTIONS,
props: { multiple: true },
2020-10-30 23:26:33 +08:00
modelValue: [['shanghai', 'shanghai']],
},
})
const vm = wrapper.vm as any
expect(vm.getCheckedNodes().length).toBe(2)
expect(vm.getCheckedNodes(true).length).toBe(1)
vm.clearCheckedNodes()
expect(vm.getCheckedNodes().length).toBe(0)
})
test('options async load with default value', async () => {
const wrapper = mount(CascaderPanel, {
props: {
options: [],
modelValue: ['shanghai', 'shanghai'],
},
})
const vm = wrapper.vm as any
expect(vm.getCheckedNodes().length).toBe(0)
await wrapper.setProps({ options: NORMAL_OPTIONS })
expect(vm.getCheckedNodes(true).length).toBe(1)
})
2020-10-30 23:26:33 +08:00
})