|
1 | 1 | import { mount } from '@vue/test-utils'; |
2 | 2 | import { Tag } from '../index'; |
3 | 3 | import { ref } from 'vue'; |
| 4 | +import { useNamespace } from '../../shared/hooks/use-namespace'; |
| 5 | + |
| 6 | +const ns = useNamespace('tag', true); |
| 7 | +const baseClass = ns.b(); |
| 8 | +const itemClass = ns.e('item'); |
| 9 | + |
| 10 | +const nsNoDot = useNamespace('tag', false); |
| 11 | +const primaryClass = nsNoDot.m('primary'); |
| 12 | +const lgClass = nsNoDot.m('lg'); |
4 | 13 |
|
5 | 14 | describe('tag test', () => { |
6 | 15 | it('init render', async () => { |
7 | 16 | const wrapper = mount(Tag); |
8 | | - expect(wrapper.find('.devui-tag').exists()).toBeTruthy(); |
| 17 | + expect(wrapper.find(baseClass).exists()).toBeTruthy(); |
9 | 18 | }); |
10 | 19 | it('props type', () => { |
11 | 20 | const wrapper = mount(Tag, { |
12 | 21 | propsData: { |
13 | 22 | type: 'primary', |
14 | 23 | }, |
15 | 24 | }); |
16 | | - expect(wrapper.find('.devui-tag .devui-tag-item').classes()).toContain('devui-tag-primary'); |
| 25 | + const itemTag = wrapper.find(itemClass); |
| 26 | + expect(itemTag.classes()).toContain(primaryClass); |
17 | 27 | }); |
18 | 28 | it('props color', () => { |
19 | 29 | const wrapper = mount(Tag, { |
20 | 30 | propsData: { |
21 | 31 | color: 'red-w98', // #f66f6a rgb(246, 111, 106) |
22 | 32 | }, |
23 | 33 | }); |
24 | | - expect(wrapper.find('.devui-tag .devui-tag-item').attributes('style')).toContain('rgb(246, 111, 106)'); |
| 34 | + expect(wrapper.find(itemClass).attributes('style')).toContain('rgb(246, 111, 106)'); |
25 | 35 | }); |
26 | 36 | it('props color custom', () => { |
27 | 37 | const wrapper = mount(Tag, { |
28 | 38 | propsData: { |
29 | 39 | color: '#aa2116', // rgb(170, 33, 22) |
30 | 40 | }, |
31 | 41 | }); |
32 | | - expect(wrapper.find('.devui-tag .devui-tag-item').attributes('style')).toContain('rgb(170, 33, 22)'); |
| 42 | + expect(wrapper.find(itemClass).attributes('style')).toContain('rgb(170, 33, 22)'); |
33 | 43 | }); |
34 | 44 | it('props titleContent', () => { |
35 | 45 | const titleContent = 'tagTitle test'; |
36 | 46 | const wrapper = mount(Tag, { |
37 | 47 | props: { titleContent }, |
38 | 48 | }); |
39 | | - expect(wrapper.get('.devui-tag .devui-tag-item').attributes('title')).toBe(titleContent); |
| 49 | + expect(wrapper.get(itemClass).attributes('title')).toBe(titleContent); |
40 | 50 | }); |
41 | 51 | it('props deletable show', async () => { |
42 | 52 | const wrapper = mount(Tag, { |
@@ -77,9 +87,9 @@ describe('tag test', () => { |
77 | 87 | color: 'red-w98', // 对应颜色:rgb(246, 111, 106) |
78 | 88 | }, |
79 | 89 | }); |
80 | | - expect(wrapper.find('.devui-tag .devui-tag-item').attributes('style')).toContain('color: rgb(246, 111, 106);'); |
| 90 | + expect(wrapper.find(itemClass).attributes('style')).toContain('color: rgb(246, 111, 106);'); |
81 | 91 | await wrapper.setProps({ checked: true }); |
82 | | - expect(wrapper.find('.devui-tag .devui-tag-item').attributes('style')).toContain('background-color: rgb(246, 111, 106);'); |
| 92 | + expect(wrapper.find(itemClass).attributes('style')).toContain('background-color: rgb(246, 111, 106);'); |
83 | 93 | expect(wrapper.emitted('checkedChange').length).toBeGreaterThan(0); |
84 | 94 | }); |
85 | 95 | it('event checkedChange', async () => { |
@@ -113,4 +123,14 @@ describe('tag test', () => { |
113 | 123 | }); |
114 | 124 | expect(wrapper.find('i').classes()).toContain('icon-like'); |
115 | 125 | }); |
| 126 | + |
| 127 | + it('Tag size work', () => { |
| 128 | + const wrapper = mount(Tag, { |
| 129 | + propsData: { |
| 130 | + size: 'lg', |
| 131 | + }, |
| 132 | + }); |
| 133 | + const itemTag = wrapper.find(itemClass); |
| 134 | + expect(itemTag.classes()).toContain(lgClass); |
| 135 | + }); |
116 | 136 | }); |
0 commit comments