|
| 1 | +import { describe, expect, it, vi } from 'vitest' |
| 2 | +import { Flex } from '@ant-design-vue/ui' |
| 3 | +import { mount } from '@vue/test-utils' |
| 4 | + |
| 5 | +describe('Flex', () => { |
| 6 | + it('should render correctly', () => { |
| 7 | + const wrapper = mount(Flex, { |
| 8 | + slots: { |
| 9 | + default: `<div>test</div>`, |
| 10 | + }, |
| 11 | + }); |
| 12 | + |
| 13 | + expect(wrapper.html()).toMatchSnapshot(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('Flex', () => { |
| 17 | + const wrapper = mount(Flex, { |
| 18 | + props: { |
| 19 | + justify: 'center' |
| 20 | + }, |
| 21 | + slots: { |
| 22 | + default: `<div>test</div>` |
| 23 | + }, |
| 24 | + }); |
| 25 | + |
| 26 | + const wrapper3 = mount(Flex, { |
| 27 | + props: { |
| 28 | + flex: '0 1 auto', |
| 29 | + }, |
| 30 | + slots: { |
| 31 | + default: `<div>test</div>`, |
| 32 | + }, |
| 33 | + }); |
| 34 | + |
| 35 | + expect(wrapper.classes('ant-flex')).toBeTruthy(); |
| 36 | + expect(wrapper.find('.ant-flex-justify-center')).toBeTruthy(); |
| 37 | + expect(wrapper3.classes('ant-flex')).toBeTruthy(); |
| 38 | + expect(wrapper3.element.style.flex).toBe('0 1 auto'); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('Props: gap', () => { |
| 42 | + it('support string', () => { |
| 43 | + const wrapper = mount(Flex, { |
| 44 | + props: { |
| 45 | + gap: 'inherit', |
| 46 | + }, |
| 47 | + slots: { |
| 48 | + default: `<div>test</div>`, |
| 49 | + }, |
| 50 | + }); |
| 51 | + expect(wrapper.classes('ant-flex')).toBeTruthy(); |
| 52 | + expect(wrapper.element.style.gap).toBe('inherit'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('support number', () => { |
| 56 | + const wrapper = mount(Flex, { |
| 57 | + props: { |
| 58 | + gap: '100', |
| 59 | + }, |
| 60 | + slots: { |
| 61 | + default: `<div>test</div>`, |
| 62 | + }, |
| 63 | + }); |
| 64 | + expect(wrapper.classes('ant-flex')).toBeTruthy(); |
| 65 | + expect(wrapper.element.style.gap).toBe('100px'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('support preset size', () => { |
| 69 | + const wrapper = mount(Flex, { |
| 70 | + props: { |
| 71 | + gap: 'small', |
| 72 | + }, |
| 73 | + slots: { |
| 74 | + default: `<div>test</div>`, |
| 75 | + }, |
| 76 | + }); |
| 77 | + |
| 78 | + expect(wrapper.classes('ant-flex')).toBeTruthy(); |
| 79 | + expect(wrapper.classes('ant-flex-gap-small')).toBeTruthy(); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + it('Component work', () => { |
| 84 | + const wrapper = mount(Flex, { |
| 85 | + slots: { |
| 86 | + default: `<div>test</div>` |
| 87 | + }, |
| 88 | + }); |
| 89 | + |
| 90 | + const wrapper2 = mount(Flex, { |
| 91 | + props: { |
| 92 | + componentTag: 'span' |
| 93 | + }, |
| 94 | + slots: { |
| 95 | + default: `<div>test</div>` |
| 96 | + }, |
| 97 | + }); |
| 98 | + |
| 99 | + expect(wrapper.find('.ant-flex').element.tagName).toBe('DIV'); |
| 100 | + expect(wrapper2.find('.ant-flex').element.tagName).toBe('SPAN'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('when vertical=true should stretch work', () => { |
| 104 | + const wrapper = mount(Flex, { |
| 105 | + props: { |
| 106 | + vertical: true |
| 107 | + }, |
| 108 | + slots: { |
| 109 | + default: `<div>test</div>` |
| 110 | + }, |
| 111 | + }); |
| 112 | + |
| 113 | + const wrapper2 = mount(Flex, { |
| 114 | + props: { |
| 115 | + vertical: true, |
| 116 | + align: 'center', |
| 117 | + }, |
| 118 | + slots: { |
| 119 | + default: `<div>test</div>`, |
| 120 | + }, |
| 121 | + }); |
| 122 | + |
| 123 | + expect(wrapper.find('.ant-flex-align-stretch')).toBeTruthy(); |
| 124 | + expect(wrapper2.find('.ant-flex-align-center')).toBeTruthy(); |
| 125 | + }); |
| 126 | + |
| 127 | + it('wrap prop shouled support boolean', () => { |
| 128 | + const wrapper = mount(Flex, { |
| 129 | + props: { |
| 130 | + wrap: 'wrap', |
| 131 | + }, |
| 132 | + slots: { |
| 133 | + default: `<div>test</div>`, |
| 134 | + }, |
| 135 | + }); |
| 136 | + |
| 137 | + const wrapper2 = mount(Flex, { |
| 138 | + props: { |
| 139 | + wrap: true, |
| 140 | + }, |
| 141 | + slots: { |
| 142 | + default: `<div>test</div>`, |
| 143 | + }, |
| 144 | + }); |
| 145 | + |
| 146 | + expect(wrapper.classes('ant-flex-wrap-wrap')).toBeTruthy(); |
| 147 | + expect(wrapper2.classes('ant-flex-wrap-wrap')).toBeTruthy(); |
| 148 | + }) |
| 149 | +}) |
0 commit comments