From 82e459fa85ad3180148a83bb254dbeca25ff45ee Mon Sep 17 00:00:00 2001 From: lwj <674416404@qq.com> Date: Mon, 4 Aug 2025 21:35:14 +0800 Subject: [PATCH 1/3] test(list): update test case --- .../list/__tests__/list-item-meta.test.tsx | 178 ++++++++++++++++++ .../list/__tests__/list-item.test.tsx | 95 ++++++++++ .../components/list/__tests__/list.test.tsx | 155 +-------------- 3 files changed, 281 insertions(+), 147 deletions(-) create mode 100644 packages/components/list/__tests__/list-item-meta.test.tsx create mode 100644 packages/components/list/__tests__/list-item.test.tsx diff --git a/packages/components/list/__tests__/list-item-meta.test.tsx b/packages/components/list/__tests__/list-item-meta.test.tsx new file mode 100644 index 0000000000..a14c3b03cb --- /dev/null +++ b/packages/components/list/__tests__/list-item-meta.test.tsx @@ -0,0 +1,178 @@ +import { List, ListItem, ListItemMeta } from '@tdesign/components/list'; +import { mount } from '@vue/test-utils'; + +describe('ListItemMeta', () => { + describe('props', () => { + it('description[string]', () => { + const wrapper = mount(() => ( + + + + + + + + + )); + const descriptions = wrapper.findAll('.t-list-item__meta .t-list-item__meta-description'); + expect(descriptions.length).toBe(2); + expect(descriptions[0].text()).toBe('描述一'); + expect(descriptions[1].text()).toBe('描述二'); + }); + + it('description[slot]', () => { + const wrapper = mount(() => ( + + + '描述一' }}> + + + '描述二' }}> + + + )); + const descriptions = wrapper.findAll('.t-list-item__meta .t-list-item__meta-description'); + expect(descriptions.length).toBe(2); + expect(descriptions[0].text()).toBe('描述一'); + expect(descriptions[1].text()).toBe('描述二'); + }); + + it('description[function]', () => { + const wrapper = mount(() => ( + + + '描述一'}> + + + '描述二'}> + + + )); + const descriptions = wrapper.findAll('.t-list-item__meta .t-list-item__meta-description'); + expect(descriptions.length).toBe(2); + expect(descriptions[0].text()).toBe('描述一'); + expect(descriptions[1].text()).toBe('描述二'); + }); + + it('title[string]', () => { + const wrapper = mount(() => ( + + + + + + + + + )); + const titles = wrapper.findAll('.t-list-item__meta .t-list-item__meta-title'); + expect(titles.length).toBe(2); + expect(titles[0].text()).toBe('标题一'); + expect(titles[1].text()).toBe('标题一'); + }); + + it('title[slot]', () => { + const wrapper = mount(() => ( + + + '标题一' }} description="描述一"> + + + '标题二' }} description="描述二"> + + + )); + const titles = wrapper.findAll('.t-list-item__meta .t-list-item__meta-title'); + expect(titles.length).toBe(2); + expect(titles[0].text()).toBe('标题一'); + expect(titles[1].text()).toBe('标题二'); + }); + + it('title[function]', () => { + const wrapper = mount(() => ( + + + '标题一'} description="描述一"> + + + '标题二'} description="描述二"> + + + )); + const titles = wrapper.findAll('.t-list-item__meta .t-list-item__meta-title'); + expect(titles.length).toBe(2); + expect(titles[0].text()).toBe('标题一'); + expect(titles[1].text()).toBe('标题二'); + }); + + it('image[string]', () => { + const imageUrl = 'https://tdesign.gtimg.com/site/avatar.jpg'; + const wrapper = mount(() => ( + + + + + + + + + )); + const images = wrapper.findAll('.t-list-item__meta .t-list-item__meta-avatar img'); + expect(images.length).toBe(2); + expect(images[0].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + expect(images[1].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + }); + + it('image[slot]', () => { + const wrapper = mount(() => { + return ( + + + }} + title="标题一" + description="描述一" + /> + + + }} + title="标题二" + description="描述二" + /> + + + ); + }); + const images = wrapper.findAll('.t-list-item__meta .t-list-item__meta-avatar img'); + expect(images.length).toBe(2); + expect(images[0].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + expect(images[1].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + }); + + it('image[function]', () => { + const wrapper = mount(() => ( + + + } + title="标题一" + description="描述一" + > + + + } + title="标题二" + description="描述二" + > + + + )); + const images = wrapper.findAll('.t-list-item__meta .t-list-item__meta-avatar img'); + expect(images.length).toBe(2); + expect(images[0].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + expect(images[1].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); + }); + }); +}); diff --git a/packages/components/list/__tests__/list-item.test.tsx b/packages/components/list/__tests__/list-item.test.tsx new file mode 100644 index 0000000000..29a0c15895 --- /dev/null +++ b/packages/components/list/__tests__/list-item.test.tsx @@ -0,0 +1,95 @@ +import { List, ListItem } from '@tdesign/components/list'; +import { mount } from '@vue/test-utils'; + +describe('ListItem', () => { + describe('props', () => { + it('action[string]', () => { + const wrapper = mount(() => ( + + 描述性文字 + + )); + expect(wrapper.find('.t-list-item .t-list-item__action').text()).toBe('操作'); + }); + + it('action[slot]', () => { + const wrapper = mount(() => ( + + '操作' }}>描述性文字 + + )); + expect(wrapper.find('.t-list-item .t-list-item__action').text()).toBe('操作'); + }); + + it('action[function]', () => { + const wrapper = mount(() => ( + + '操作'}>描述性文字 + + )); + expect(wrapper.find('.t-list-item .t-list-item__action').text()).toBe('操作'); + }); + it('content[string]', () => { + const wrapper = mount(() => ( + + + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + + it('content[slot]', () => { + const wrapper = mount(() => ( + + '描述性文字' }}> + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + + it('content[function]', () => { + const wrapper = mount(() => ( + + '描述性文字'}> + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + it('default[string]', () => { + const wrapper = mount(() => ( + + + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + it('default[slot]', () => { + const wrapper = mount(() => ( + + '描述性文字' }}> + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + it('default[function]', () => { + const wrapper = mount(() => ( + + '描述性文字'}> + + )); + const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); + expect(item.exists()).toBeTruthy(); + expect(item.text()).toBe('描述性文字'); + }); + }); +}); diff --git a/packages/components/list/__tests__/list.test.tsx b/packages/components/list/__tests__/list.test.tsx index 49765420f8..0563d3f385 100644 --- a/packages/components/list/__tests__/list.test.tsx +++ b/packages/components/list/__tests__/list.test.tsx @@ -1,12 +1,11 @@ -// @ts-nocheck import { mount } from '@vue/test-utils'; -import { describe, expect, vi, it } from 'vitest'; -import { List, ListItem, ListItemMeta } from '@tdesign/components/list'; +import { describe, expect, it } from 'vitest'; +import { List, ListItem, ListProps } from '@tdesign/components/list'; describe('List', () => { - describe(':props', () => { - it(':size', () => { - const sizeList = ['small', 'medium', 'large']; + describe('props', () => { + it('size[string]', () => { + const sizeList: Array = ['small', 'medium', 'large']; sizeList.forEach((size) => { const wrapper = mount(() => ( @@ -64,91 +63,9 @@ describe('List', () => { expect(stripes.length).toBe(1); }); }); -}); - -describe('ListItem', () => { - describe(':props', () => { - it(':action', () => { - const slots = { - action: () => ( - <> - 操作一 - 操作二 - 操作三 - - ), - }; - const wrapper = mount(() => ( - - 描述性文字一 - 描述性文字二 - - )); - const [item] = wrapper.findAll('.t-list-item .t-list-item__action'); - const spans = item.findAll('span'); - expect(item.element.children.length).toBe(3); - expect(spans[0].text()).toBe('操作一'); - expect(spans[1].text()).toBe('操作二'); - expect(spans[2].text()).toBe('操作三'); - }); - - it(':content', () => { - const slots = { - content: () => <>描述一, - }; - const wrapper = mount(() => ( - - - 描述性文字二 - - )); - const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); - expect(item.exists()).toBeTruthy(); - expect(item.text()).toBe('描述一'); - }); - - it(':default', () => { - const slots = { - content: () => <>描述一, - }; - const wrapper = mount(() => ( - - - 描述性文字二 - - )); - const [item] = wrapper.findAll('.t-list-item .t-list-item-main'); - expect(item.exists()).toBeTruthy(); - expect(item.text()).toBe('描述一'); - }); - - it(':asyncLoading:loading', () => { - const wrapper = mount(() => ( - - 描述性文字一 - 描述性文字二 - - )); - const loading = wrapper.find('.t-list .t-list__load--loading'); - expect(loading.exists()).toBeTruthy(); - expect(loading.find('span').text()).toBe('正在加载中,请稍等'); - }); - it(':asyncLoading:load-more', () => { - const wrapper = mount(() => ( - - 描述性文字一 - 描述性文字二 - - )); - const loadMore = wrapper.find('.t-list .t-list__load--load-more'); - expect(loadMore.exists()).toBeTruthy(); - expect(loadMore.find('span').text()).toBe('点击加载更多'); - }); - }); - - describe(':events', () => { - it(':onLoadMore', async () => { + describe('events', () => { + it('onLoadMore', async () => { const fn = vi.fn(); const wrapper = mount(() => ( @@ -161,7 +78,7 @@ describe('ListItem', () => { expect(fn).toBeCalled(); }); - it(':onScroll', async () => { + it('onScroll', async () => { const fn = vi.fn(); const wrapper = mount(() => ( @@ -189,59 +106,3 @@ describe('ListItem', () => { }); }); }); - -describe('ListItemMeta', () => { - describe(':props', () => { - it(':description', () => { - const wrapper = mount(() => ( - - - - - - - - - )); - const descriptions = wrapper.findAll('.t-list-item__meta .t-list-item__meta-description'); - expect(descriptions.length).toBe(2); - expect(descriptions[0].text()).toBe('描述一'); - expect(descriptions[1].text()).toBe('描述二'); - }); - - it(':title', () => { - const wrapper = mount(() => ( - - - - - - - - - )); - const titles = wrapper.findAll('.t-list-item__meta .t-list-item__meta-title'); - expect(titles.length).toBe(2); - expect(titles[0].text()).toBe('标题一'); - expect(titles[1].text()).toBe('标题一'); - }); - - it(':image', () => { - const imageUrl = 'https://tdesign.gtimg.com/site/avatar.jpg'; - const wrapper = mount(() => ( - - - - - - - - - )); - const images = wrapper.findAll('.t-list-item__meta .t-list-item__meta-avatar img'); - expect(images.length).toBe(2); - expect(images[0].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); - expect(images[1].element.getAttribute('src')).toBe('https://tdesign.gtimg.com/site/avatar.jpg'); - }); - }); -}); From bf51c9de647e02157e5fcefd8a028c4b943da644 Mon Sep 17 00:00:00 2001 From: lwj <674416404@qq.com> Date: Wed, 6 Aug 2025 00:33:42 +0800 Subject: [PATCH 2/3] test(list): update test case --- .../components/list/__tests__/list.test.tsx | 82 +++++++++++++++---- 1 file changed, 65 insertions(+), 17 deletions(-) diff --git a/packages/components/list/__tests__/list.test.tsx b/packages/components/list/__tests__/list.test.tsx index 0563d3f385..60dec42086 100644 --- a/packages/components/list/__tests__/list.test.tsx +++ b/packages/components/list/__tests__/list.test.tsx @@ -4,20 +4,43 @@ import { List, ListItem, ListProps } from '@tdesign/components/list'; describe('List', () => { describe('props', () => { - it('size[string]', () => { - const sizeList: Array = ['small', 'medium', 'large']; - sizeList.forEach((size) => { - const wrapper = mount(() => ( - - 描述性文字一 - 描述性文字二 - - )); - expect(wrapper.classes()).toContain(`t-size-${size.slice(0, 1)}`); - }); + it('footer[string]', () => { + const wrapper = mount(() => ( + + 描述性文字一 + 描述性文字二 + + )); + const footer = wrapper.find('.t-list__footer'); + expect(footer.exists()).toBeTruthy(); + expect(footer.text()).toBe('footer'); + }); + + it('footer[slot]', () => { + const wrapper = mount(() => ( + 'footer' }}> + 描述性文字一 + 描述性文字二 + + )); + const footer = wrapper.find('.t-list__footer'); + expect(footer.exists()).toBeTruthy(); + expect(footer.text()).toBe('footer'); + }); + + it('footer[function]', () => { + const wrapper = mount(() => ( + 'footer'}> + 描述性文字一 + 描述性文字二 + + )); + const footer = wrapper.find('.t-list__footer'); + expect(footer.exists()).toBeTruthy(); + expect(footer.text()).toBe('footer'); }); - it(':header', () => { + it('header[string]', () => { const wrapper = mount(() => ( 描述性文字一 @@ -29,16 +52,41 @@ describe('List', () => { expect(header.text()).toBe('header'); }); - it(':footer', () => { + it('header[slot]', () => { const wrapper = mount(() => ( - + 'header' }}> 描述性文字一 描述性文字二 )); - const footer = wrapper.find('.t-list__footer'); - expect(footer.exists()).toBeTruthy(); - expect(footer.text()).toBe('footer'); + const header = wrapper.find('.t-list__header'); + expect(header.exists()).toBeTruthy(); + expect(header.text()).toBe('header'); + }); + + it('header[function]', () => { + const wrapper = mount(() => ( + 'header'}> + 描述性文字一 + 描述性文字二 + + )); + const header = wrapper.find('.t-list__header'); + expect(header.exists()).toBeTruthy(); + expect(header.text()).toBe('header'); + }); + + it('size[string]', () => { + const sizeList: Array = ['small', 'medium', 'large']; + sizeList.forEach((size) => { + const wrapper = mount(() => ( + + 描述性文字一 + 描述性文字二 + + )); + expect(wrapper.classes()).toContain(`t-size-${size.slice(0, 1)}`); + }); }); it(':split', () => { From 9a2d06264d9ecff231a6445d5e603bb9540c2e63 Mon Sep 17 00:00:00 2001 From: lwj <674416404@qq.com> Date: Thu, 7 Aug 2025 23:14:25 +0800 Subject: [PATCH 3/3] test(list): update test case --- .../components/list/__tests__/list.test.tsx | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/packages/components/list/__tests__/list.test.tsx b/packages/components/list/__tests__/list.test.tsx index 60dec42086..4936ee8d85 100644 --- a/packages/components/list/__tests__/list.test.tsx +++ b/packages/components/list/__tests__/list.test.tsx @@ -4,6 +4,64 @@ import { List, ListItem, ListProps } from '@tdesign/components/list'; describe('List', () => { describe('props', () => { + it('asyncLoading[string]', () => { + const wrapperLoading = mount(() => ( + + 描述性文字一 + 描述性文字二 + + )); + const loading = wrapperLoading.find('.t-list .t-list__load--loading'); + expect(loading.exists()).toBeTruthy(); + expect(loading.find('span').text()).toBe('正在加载中,请稍等'); + + const wrapperLoadingMore = mount(() => ( + + 描述性文字一 + 描述性文字二 + + )); + const loadingMore = wrapperLoadingMore.find('.t-list .t-list__load--loading'); + expect(loadingMore.exists()).toBeTruthy(); + expect(loadingMore.find('span').text()).toBe('正在加载中,请稍等'); + }); + + it('asyncLoading[slot]', () => { + const wrapperLoading = mount(() => ( + '自定义正在加载中' }}> + 描述性文字一 + 描述性文字二 + + )); + const loading = wrapperLoading.find('.t-list .t-list__load'); + expect(loading.exists()).toBeTruthy(); + expect(loading.text()).toBe('自定义正在加载中'); + }); + + it('async-loading[slot]', () => { + const wrapperLoading = mount(() => ( + '自定义正在加载中' }}> + 描述性文字一 + 描述性文字二 + + )); + const loading = wrapperLoading.find('.t-list .t-list__load'); + expect(loading.exists()).toBeTruthy(); + expect(loading.text()).toBe('自定义正在加载中'); + }); + + it('asyncLoading[function]', () => { + const wrapper = mount(() => ( + '自定义正在加载中'}> + 描述性文字一 + 描述性文字二 + + )); + const loading = wrapper.find('.t-list .t-list__load'); + expect(loading.exists()).toBeTruthy(); + expect(loading.text()).toBe('自定义正在加载中'); + }); + it('footer[string]', () => { const wrapper = mount(() => ( @@ -76,6 +134,8 @@ describe('List', () => { expect(header.text()).toBe('header'); }); + it('scroll[object]', () => {}); + it('size[string]', () => { const sizeList: Array = ['small', 'medium', 'large']; sizeList.forEach((size) => { @@ -89,7 +149,7 @@ describe('List', () => { }); }); - it(':split', () => { + it('split[boolean]', () => { const wrapper = mount(() => ( 描述性文字一 @@ -100,7 +160,7 @@ describe('List', () => { expect(split.exists()).toBeTruthy(); }); - it(':stripe', () => { + it('stripe[boolean]', () => { const wrapper = mount(() => ( 描述性文字一