|
1 | 1 | import { mount } from '@vue/test-utils'; |
2 | 2 | import Statistic from '@tdesign/components/statistic'; |
| 3 | +import { COLOR_MAP } from '@tdesign/common-js/statistic/utils'; |
3 | 4 |
|
4 | 5 | describe('Statistic', () => { |
5 | 6 | describe(':props', () => { |
@@ -110,5 +111,51 @@ describe('Statistic', () => { |
110 | 111 | expect(trendIconElement.exists()).toBe(true); |
111 | 112 | expect(trendIconElement.element.tagName).toBe('svg'); |
112 | 113 | }); |
| 114 | + |
| 115 | + it('color:#ff0000', () => { |
| 116 | + const wrapper = mount(Statistic, { |
| 117 | + propsData: { |
| 118 | + title: 'Total Sales', |
| 119 | + value: 1000, |
| 120 | + color: '#ff0000', |
| 121 | + }, |
| 122 | + }); |
| 123 | + |
| 124 | + const contentElement = wrapper.find('.t-statistic-content'); |
| 125 | + expect(contentElement.exists()).toBe(true); |
| 126 | + expect(contentElement.attributes('style')).toContain('color: rgb(255, 0, 0)'); |
| 127 | + }); |
| 128 | + |
| 129 | + it('color:yellow', () => { |
| 130 | + const wrapper = mount(Statistic, { |
| 131 | + propsData: { |
| 132 | + title: 'Total Sales', |
| 133 | + value: 1000, |
| 134 | + color: 'yellow', |
| 135 | + }, |
| 136 | + }); |
| 137 | + |
| 138 | + const contentElement = wrapper.find('.t-statistic-content'); |
| 139 | + expect(contentElement.exists()).toBe(true); |
| 140 | + expect(contentElement.attributes('style')).toContain('color: yellow'); |
| 141 | + }); |
| 142 | + |
| 143 | + it('colors: colorKeys', async () => { |
| 144 | + Object.keys(COLOR_MAP).map((color) => { |
| 145 | + const wrapper = mount(Statistic, { |
| 146 | + props: { |
| 147 | + title: 'Total Sales', |
| 148 | + value: 1000, |
| 149 | + color, |
| 150 | + }, |
| 151 | + }); |
| 152 | + |
| 153 | + const contentElement = wrapper.find('.t-statistic-content'); |
| 154 | + const vm = wrapper.vm as any; |
| 155 | + expect(contentElement.exists()).toBe(true); |
| 156 | + const expectedColor = COLOR_MAP[color as keyof typeof COLOR_MAP]; |
| 157 | + expect(vm.contentStyle).toEqual({ color: expectedColor }); |
| 158 | + }); |
| 159 | + }); |
113 | 160 | }); |
114 | 161 | }); |
0 commit comments