|
| 1 | +// @ts-nocheck |
| 2 | +import { mount } from '@vue/test-utils'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | +import { ref } from 'vue'; |
| 5 | +import { AppIcon } from 'tdesign-icons-vue-next'; |
| 6 | +import { Steps, StepItem } from '@tdesign/components/steps'; |
| 7 | + |
| 8 | +describe('StepItem', () => { |
| 9 | + describe('props', () => { |
| 10 | + it(':content[string]', () => { |
| 11 | + const wrapper = mount(() => ( |
| 12 | + <Steps> |
| 13 | + <StepItem title="登录" content="已完成状态"></StepItem> |
| 14 | + </Steps> |
| 15 | + )); |
| 16 | + const content = wrapper.find('.t-steps-item .t-steps-item__description'); |
| 17 | + expect(content.exists()).toBeTruthy(); |
| 18 | + expect(content.text()).toBe('已完成状态'); |
| 19 | + }); |
| 20 | + |
| 21 | + it(':content[slot/function]', () => { |
| 22 | + const wrapper = mount(() => ( |
| 23 | + <Steps> |
| 24 | + <StepItem title="登录" v-slots={{ content: () => '已完成状态' }}></StepItem> |
| 25 | + </Steps> |
| 26 | + )); |
| 27 | + const content = wrapper.find('.t-steps-item .t-steps-item__description'); |
| 28 | + expect(content.exists()).toBeTruthy(); |
| 29 | + expect(content.text()).toBe('已完成状态'); |
| 30 | + }); |
| 31 | + |
| 32 | + it(':default[string]', () => { |
| 33 | + const wrapper = mount(() => ( |
| 34 | + <Steps> |
| 35 | + <StepItem title="登录" default="已完成状态"></StepItem> |
| 36 | + </Steps> |
| 37 | + )); |
| 38 | + const content = wrapper.find('.t-steps-item .t-steps-item__description'); |
| 39 | + expect(content.exists()).toBeTruthy(); |
| 40 | + expect(content.text()).toBe('已完成状态'); |
| 41 | + }); |
| 42 | + |
| 43 | + it(':default[slot/function]', () => { |
| 44 | + const wrapper = mount(() => ( |
| 45 | + <Steps> |
| 46 | + <StepItem title="登录" v-slots={{ default: () => '已完成状态' }}></StepItem> |
| 47 | + </Steps> |
| 48 | + )); |
| 49 | + const content = wrapper.find('.t-steps-item .t-steps-item__description'); |
| 50 | + expect(content.exists()).toBeTruthy(); |
| 51 | + expect(content.text()).toBe('已完成状态'); |
| 52 | + }); |
| 53 | + |
| 54 | + it(':extra[string]', () => { |
| 55 | + const wrapper = mount(() => ( |
| 56 | + <Steps> |
| 57 | + <StepItem title="登录" default="已完成状态" extra="额外操作"></StepItem> |
| 58 | + </Steps> |
| 59 | + )); |
| 60 | + const extra = wrapper.find('.t-steps-item .t-steps-item__extra'); |
| 61 | + expect(extra.exists()).toBeTruthy(); |
| 62 | + expect(extra.text()).toBe('额外操作'); |
| 63 | + }); |
| 64 | + |
| 65 | + it(':extra[slot/function]', () => { |
| 66 | + const slots = { |
| 67 | + extra: () => <div class="extra">额外操作</div>, |
| 68 | + }; |
| 69 | + const wrapper = mount(() => ( |
| 70 | + <Steps> |
| 71 | + <StepItem title="登录" default="已完成状态" v-slots={slots}></StepItem> |
| 72 | + </Steps> |
| 73 | + )); |
| 74 | + const extra = wrapper.find('.t-steps-item .t-steps-item__extra .extra'); |
| 75 | + expect(extra.exists()).toBeTruthy(); |
| 76 | + expect(extra.text()).toBe('额外操作'); |
| 77 | + }); |
| 78 | + |
| 79 | + it(':icon[boolean]', () => { |
| 80 | + const wrapper = mount(() => ( |
| 81 | + <Steps> |
| 82 | + <StepItem title="登录" default="已完成状态" icon={false}></StepItem> |
| 83 | + </Steps> |
| 84 | + )); |
| 85 | + const item = wrapper.find('.t-steps-item .t-steps-item__icon .t-steps-item__icon--number'); |
| 86 | + expect(item.exists()).toBeFalsy(); |
| 87 | + }); |
| 88 | + |
| 89 | + it(':icon[slot/function]', () => { |
| 90 | + const renderIocn = () => <AppIcon />; |
| 91 | + const wrapper = mount(() => ( |
| 92 | + <Steps> |
| 93 | + <StepItem title="登录" default="已完成状态" icon={renderIocn}></StepItem> |
| 94 | + </Steps> |
| 95 | + )); |
| 96 | + const icon = wrapper.find('.t-steps-item .t-steps-item__icon'); |
| 97 | + expect(icon.exists()).toBeTruthy(); |
| 98 | + expect(icon.findComponent(AppIcon)).toBeTruthy(); |
| 99 | + }); |
| 100 | + |
| 101 | + it(':status[default/process/finish/error]', () => { |
| 102 | + const statusList = ['default', 'process', 'finish', 'error']; |
| 103 | + statusList.forEach((status) => { |
| 104 | + const wrapper = mount(() => ( |
| 105 | + <Steps> |
| 106 | + <StepItem title="登录" default="已完成状态" status={status}></StepItem> |
| 107 | + </Steps> |
| 108 | + )); |
| 109 | + const item = wrapper.find('.t-steps-item'); |
| 110 | + expect(item.classes()).toContain(`t-steps-item--${status}`); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + it(':title[string]', () => { |
| 115 | + const wrapper = mount(() => ( |
| 116 | + <Steps> |
| 117 | + <StepItem title="登录" default="已完成状态"></StepItem> |
| 118 | + </Steps> |
| 119 | + )); |
| 120 | + const title = wrapper.find('.t-steps-item .t-steps-item__title'); |
| 121 | + expect(title.exists()).toBeTruthy(); |
| 122 | + expect(title.text()).toBe('登录'); |
| 123 | + }); |
| 124 | + |
| 125 | + it(':title[slot/function]', () => { |
| 126 | + const wrapper = mount(() => ( |
| 127 | + <Steps> |
| 128 | + <StepItem v-slots={{ title: () => '登录' }} default="已完成状态"></StepItem> |
| 129 | + </Steps> |
| 130 | + )); |
| 131 | + const title = wrapper.find('.t-steps-item .t-steps-item__title'); |
| 132 | + expect(title.exists()).toBeTruthy(); |
| 133 | + expect(title.text()).toBe('登录'); |
| 134 | + }); |
| 135 | + |
| 136 | + it(':value[string/number]', async () => { |
| 137 | + const current = ref('b'); |
| 138 | + const onChange = (val) => { |
| 139 | + current.value = val; |
| 140 | + }; |
| 141 | + const wrapper = mount(() => ( |
| 142 | + <Steps defaultCurrent={current.value} onChange={onChange}> |
| 143 | + <StepItem title="登录" value="a"></StepItem> |
| 144 | + <StepItem title="支付" value="b"></StepItem> |
| 145 | + <StepItem title="支付" value="c"></StepItem> |
| 146 | + <StepItem title="支付" value="d"></StepItem> |
| 147 | + </Steps> |
| 148 | + )); |
| 149 | + const items = wrapper.findAll('.t-steps-item'); |
| 150 | + const inners = wrapper.findAll('.t-steps-item__inner'); |
| 151 | + expect(items[0].classes()).toContain('t-steps-item--finish'); |
| 152 | + expect(items[1].classes()).toContain('t-steps-item--process'); |
| 153 | + expect(items[2].classes()).toContain('t-steps-item--default'); |
| 154 | + await inners[2].trigger('click'); |
| 155 | + expect(items[0].classes()).toContain('t-steps-item--finish'); |
| 156 | + expect(items[1].classes()).toContain('t-steps-item--finish'); |
| 157 | + expect(items[2].classes()).toContain('t-steps-item--process'); |
| 158 | + expect(current.value).toBe('c'); |
| 159 | + }); |
| 160 | + }); |
| 161 | +}); |
0 commit comments