From 17090ff24a86ef53b669dbd8e5f6002d8d7fdd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=20Cai?= Date: Mon, 25 Nov 2024 19:08:03 +0800 Subject: [PATCH] test(Select): add collapsedItems test --- .../__snapshots__/index.test.jsx.snap | 289 ++++++++++++++++++ src/select/__tests__/index.test.jsx | 230 +++++++++----- 2 files changed, 440 insertions(+), 79 deletions(-) diff --git a/src/select/__tests__/__snapshots__/index.test.jsx.snap b/src/select/__tests__/__snapshots__/index.test.jsx.snap index 7f8e6839e6..ff15b46abf 100644 --- a/src/select/__tests__/__snapshots__/index.test.jsx.snap +++ b/src/select/__tests__/__snapshots__/index.test.jsx.snap @@ -112,6 +112,71 @@ exports[`Select > :props > :clearable 1`] = ` `; +exports[`Select > :props > :collapsedItems 1`] = ` +
+
+ +
+
+ +
+ + +
+ + + 请选择 + + + + + + + + +
+ +
+ + + +
+
+`; + exports[`Select > :props > :creatable 1`] = `
:props > :size 1`] = `
`; +exports[`Select > Select Option > :props > :disabled 1`] = ` +
+
+ +
+
+ + + + + + + + + + + +
+ +
+ + + +
+
+`; + +exports[`Select > Select Option > :props > :label 1`] = ` +
+
+ +
+
+ + + + + + + + + + + +
+ +
+ + + +
+
+`; + +exports[`Select > Select Option > :props > :value 1`] = ` +
+
+ +
+
+ + + + + + + + + + + +
+ +
+ + + +
+
+`; + +exports[`Select > Select OptionGroup > :props > :value 1`] = ` +
+
+ +
+
+ + + + + + + + + + + +
+ +
+ + + +
+
+`; + exports[`Select Option > :props > :disabled 1`] = `
{ }); expect(wrapper.element).toMatchSnapshot(); }); + + it(':collapsedItems', async () => { + const collapsedItems = (h, { collapsedSelectedItems, onClose }) => { + if (!(collapsedSelectedItems instanceof Array)) return null; + const count = collapsedSelectedItems.length; + + if (count <= 0) return null; + return ( + { + return ( + <> + {collapsedSelectedItems.map((item, index) => ( + onClose({ e: context.e, index: 1 + index })} + > + {item.label} + + ))} + + ); + }, + }} + > + Function - More({count}) + + ); + }; + + const currentOptions = [ + { label: '架构云', value: '1' }, + { label: '大数据', value: '2' }, + { label: '区块链', value: '3' }, + ]; + const currentValues = ['1', '2', '3']; + + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + + const tags = wrapper.findAll('.t-tag'); + // 默认 + expect(tags.length).toBe(2); + expect(tags[0].text()).toBe('架构云'); + expect(tags[1].text()).toBe('Function - More(2)'); + // // collapsedItems popup 展示 + // await tags[1].trigger('mouseenter'); + + // await wrapper.vm.$nextTick(); + // await mockDelay(300); + + // const queryAllTags = document.querySelector('.t-tag'); + // expect(queryAllTags).toBeTruthy(); + // expect(queryAllTags.length).toBe(4); + }); }); describe('@event', () => { @@ -202,85 +274,84 @@ describe('Select', () => { }); }); }); -}); -describe('Select Option', () => { - // test props api - describe(':props', () => { - it(':value', () => { - const value = '1'; - const wrapper = mount({ - render() { - return ( - - ); - }, + describe('Select Option', () => { + // test props api + describe(':props', () => { + it(':value', () => { + const value = '1'; + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + expect(wrapper.element).toMatchSnapshot(); }); - expect(wrapper.element).toMatchSnapshot(); - }); - it(':label', () => { - const value = '1'; - const wrapper = mount({ - render() { - return ( - - ); - }, + it(':label', () => { + const value = '1'; + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + expect(wrapper.element).toMatchSnapshot(); }); - expect(wrapper.element).toMatchSnapshot(); - }); - it(':disabled', () => { - const value = '1'; - const wrapper = mount({ - render() { - return ( - - ); - }, + it(':disabled', () => { + const value = '1'; + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + expect(wrapper.element).toMatchSnapshot(); }); - expect(wrapper.element).toMatchSnapshot(); }); }); -}); -describe('Select OptionGroup', () => { - // test props api - describe(':props', () => { - it(':value', () => { - const value = '1'; - const wrapper = mount({ - render() { - return ( - - ); - }, + describe('Select OptionGroup', () => { + // test props api + describe(':props', () => { + it(':value', () => { + const value = '1'; + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + expect(wrapper.element).toMatchSnapshot(); }); - expect(wrapper.element).toMatchSnapshot(); }); - }); - describe(':base', () => { - it('v-for and option works fine', async () => { - const Comp = { - components: { - TSelect: Select, - TOptionGroup: OptionGroup, - TOption: Option, - }, - template: ` + describe(':base', () => { + it('v-for and option works fine', async () => { + const Comp = { + components: { + TSelect: Select, + TOptionGroup: OptionGroup, + TOption: Option, + }, + template: ` @@ -296,19 +367,20 @@ describe('Select OptionGroup', () => { `, - }; + }; - const wrapper = mount(Comp); - await wrapper.setProps({ popupProps: { visible: true } }); + const wrapper = mount(Comp); + await wrapper.setProps({ popupProps: { visible: true } }); - const panelNode = document.querySelector('.t-select__list'); - const groupNode = document.querySelectorAll('.t-select-option-group'); - expect(groupNode.length).toBe(3); - groupNode.forEach((item) => { - const option = item.querySelectorAll('.t-select-option'); - expect(option.length).toBe(3); + const panelNode = document.querySelector('.t-select__list'); + const groupNode = document.querySelectorAll('.t-select-option-group'); + expect(groupNode.length).toBe(3); + groupNode.forEach((item) => { + const option = item.querySelectorAll('.t-select-option'); + expect(option.length).toBe(3); + }); + panelNode.parentNode.removeChild(panelNode); }); - panelNode.parentNode.removeChild(panelNode); }); }); });