|
| 1 | +import {afterEach, describe, expect, it} from 'vitest' |
| 2 | +import {enableAutoUnmount, mount} from '@vue/test-utils' |
| 3 | +import BFormGroup from './BFormGroup.vue' |
| 4 | +import BCol from '../BCol.vue' |
| 5 | + |
| 6 | +describe('form-group', () => { |
| 7 | + enableAutoUnmount(afterEach) |
| 8 | + |
| 9 | + it('tag is fieldset by default', () => { |
| 10 | + const wrapper = mount(BFormGroup) |
| 11 | + expect(wrapper.element.tagName).toBe('FIELDSET') |
| 12 | + }) |
| 13 | + |
| 14 | + it('does not have child legend by default', () => { |
| 15 | + const wrapper = mount(BFormGroup) |
| 16 | + const $legend = wrapper.find('legend') |
| 17 | + expect($legend.exists()).toBe(false) |
| 18 | + }) |
| 19 | + |
| 20 | + it('has child legend when prop label', () => { |
| 21 | + const wrapper = mount(BFormGroup, { |
| 22 | + props: {label: 'foobar'}, |
| 23 | + }) |
| 24 | + const $legend = wrapper.find('legend') |
| 25 | + expect($legend.exists()).toBe(true) |
| 26 | + }) |
| 27 | + |
| 28 | + it('child legend has attr id to be defined by default', () => { |
| 29 | + const wrapper = mount(BFormGroup, { |
| 30 | + props: {label: 'foobar'}, |
| 31 | + }) |
| 32 | + const $legend = wrapper.get('legend') |
| 33 | + expect($legend.attributes('id')).toBeDefined() |
| 34 | + }) |
| 35 | + |
| 36 | + it('has child div by default', () => { |
| 37 | + const wrapper = mount(BFormGroup) |
| 38 | + const $div = wrapper.find('div') |
| 39 | + expect($div.exists()).toBe(true) |
| 40 | + }) |
| 41 | + |
| 42 | + it('child div has child BCol when prop labelCols', () => { |
| 43 | + const wrapper = mount(BFormGroup, { |
| 44 | + props: {labelCols: '4'}, |
| 45 | + }) |
| 46 | + const $div = wrapper.get('div') |
| 47 | + const $col = $div.findComponent(BCol) |
| 48 | + expect($col.exists()).toBe(true) |
| 49 | + }) |
| 50 | + |
| 51 | + it('child div has child BCol when prop labelColsSm', () => { |
| 52 | + const wrapper = mount(BFormGroup, { |
| 53 | + props: {labelColsSm: '4'}, |
| 54 | + }) |
| 55 | + const $div = wrapper.get('div') |
| 56 | + const $col = $div.findComponent(BCol) |
| 57 | + expect($col.exists()).toBe(true) |
| 58 | + }) |
| 59 | + |
| 60 | + it('child div has child BCol when prop labelColsMd', () => { |
| 61 | + const wrapper = mount(BFormGroup, { |
| 62 | + props: {labelColsMd: '4'}, |
| 63 | + }) |
| 64 | + const $div = wrapper.get('div') |
| 65 | + const $col = $div.findComponent(BCol) |
| 66 | + expect($col.exists()).toBe(true) |
| 67 | + }) |
| 68 | + |
| 69 | + it('child div has child BCol when prop labelColsLg', () => { |
| 70 | + const wrapper = mount(BFormGroup, { |
| 71 | + props: {labelColsLg: '4'}, |
| 72 | + }) |
| 73 | + const $div = wrapper.get('div') |
| 74 | + const $col = $div.findComponent(BCol) |
| 75 | + expect($col.exists()).toBe(true) |
| 76 | + }) |
| 77 | + |
| 78 | + it('child div has child BCol when prop labelColsXl', () => { |
| 79 | + const wrapper = mount(BFormGroup, { |
| 80 | + props: {labelColsXl: '4'}, |
| 81 | + }) |
| 82 | + const $div = wrapper.get('div') |
| 83 | + const $col = $div.findComponent(BCol) |
| 84 | + expect($col.exists()).toBe(true) |
| 85 | + }) |
| 86 | + |
| 87 | + it('child div BCol child is given prop tag to be legend when prop labelCols', () => { |
| 88 | + const wrapper = mount(BFormGroup, { |
| 89 | + props: {label: 'foobar', labelCols: '4'}, |
| 90 | + }) |
| 91 | + const $div = wrapper.get('div') |
| 92 | + const $col = $div.getComponent(BCol) |
| 93 | + expect($col.props('tag')).toBe('legend') |
| 94 | + }) |
| 95 | + |
| 96 | + it('child div BCol child is given prop labelCols', () => { |
| 97 | + const wrapper = mount(BFormGroup, { |
| 98 | + props: {label: 'foobar', labelCols: '4'}, |
| 99 | + }) |
| 100 | + const $div = wrapper.get('div') |
| 101 | + const $col = $div.getComponent(BCol) |
| 102 | + expect($col.props('cols')).toBe(4) |
| 103 | + }) |
| 104 | + |
| 105 | + it('child div BCol child is given prop labelColsSm to be prop sm', () => { |
| 106 | + const wrapper = mount(BFormGroup, { |
| 107 | + props: {label: 'foobar', labelColsSm: '4'}, |
| 108 | + }) |
| 109 | + const $div = wrapper.get('div') |
| 110 | + const $col = $div.getComponent(BCol) |
| 111 | + expect($col.props('sm')).toBe(4) |
| 112 | + }) |
| 113 | + |
| 114 | + it('child div BCol child is given prop labelColsMd to be prop md', () => { |
| 115 | + const wrapper = mount(BFormGroup, { |
| 116 | + props: {label: 'foobar', labelColsMd: '4'}, |
| 117 | + }) |
| 118 | + const $div = wrapper.get('div') |
| 119 | + const $col = $div.getComponent(BCol) |
| 120 | + expect($col.props('md')).toBe(4) |
| 121 | + }) |
| 122 | + |
| 123 | + it('child div BCol child is given prop labelColsLg to be prop lg', () => { |
| 124 | + const wrapper = mount(BFormGroup, { |
| 125 | + props: {label: 'foobar', labelColsLg: '4'}, |
| 126 | + }) |
| 127 | + const $div = wrapper.get('div') |
| 128 | + const $col = $div.getComponent(BCol) |
| 129 | + expect($col.props('lg')).toBe(4) |
| 130 | + }) |
| 131 | + |
| 132 | + it('child div BCol child is given prop labelColsXl to be prop xl', () => { |
| 133 | + const wrapper = mount(BFormGroup, { |
| 134 | + props: {labelColsXl: '4'}, |
| 135 | + }) |
| 136 | + const $div = wrapper.get('div') |
| 137 | + const $col = $div.getComponent(BCol) |
| 138 | + expect($col.props('xl')).toBe(4) |
| 139 | + }) |
| 140 | + |
| 141 | + it('child div BCol child is given class text-{type} when prop labelAlign', () => { |
| 142 | + const wrapper = mount(BFormGroup, { |
| 143 | + props: {label: 'foobar', labelAlign: '5', labelCols: '2'}, |
| 144 | + }) |
| 145 | + const $div = wrapper.get('div') |
| 146 | + const $col = $div.getComponent(BCol) |
| 147 | + expect($col.classes()).toContain('text-5') |
| 148 | + }) |
| 149 | + |
| 150 | + it('child div BCol child is given class text-{type} when prop labelAlignSm', () => { |
| 151 | + const wrapper = mount(BFormGroup, { |
| 152 | + props: {label: 'foobar', labelAlignSm: '5', labelCols: '2'}, |
| 153 | + }) |
| 154 | + const $div = wrapper.get('div') |
| 155 | + const $col = $div.getComponent(BCol) |
| 156 | + expect($col.classes()).toContain('text-sm-5') |
| 157 | + }) |
| 158 | + |
| 159 | + it('child div BCol child is given class text-{type} when prop labelAlignMd', () => { |
| 160 | + const wrapper = mount(BFormGroup, { |
| 161 | + props: {label: 'foobar', labelAlignMd: '5', labelCols: '2'}, |
| 162 | + }) |
| 163 | + const $div = wrapper.get('div') |
| 164 | + const $col = $div.getComponent(BCol) |
| 165 | + expect($col.classes()).toContain('text-md-5') |
| 166 | + }) |
| 167 | + |
| 168 | + it('child div BCol child is given class text-{type} when prop labelAlignLg', () => { |
| 169 | + const wrapper = mount(BFormGroup, { |
| 170 | + props: {label: 'foobar', labelAlignLg: '5', labelCols: '2'}, |
| 171 | + }) |
| 172 | + const $div = wrapper.get('div') |
| 173 | + const $col = $div.getComponent(BCol) |
| 174 | + expect($col.classes()).toContain('text-lg-5') |
| 175 | + }) |
| 176 | + |
| 177 | + it('child div BCol child is given class text-{type} when prop labelAlignXl', () => { |
| 178 | + const wrapper = mount(BFormGroup, { |
| 179 | + props: {label: 'foobar', labelAlignXl: '5', labelCols: '2'}, |
| 180 | + }) |
| 181 | + const $div = wrapper.get('div') |
| 182 | + const $col = $div.getComponent(BCol) |
| 183 | + expect($col.classes()).toContain('text-xl-5') |
| 184 | + }) |
| 185 | + |
| 186 | + it('child legend is given class text-{type} when prop labelAlign', () => { |
| 187 | + const wrapper = mount(BFormGroup, { |
| 188 | + props: {label: 'foobar', labelAlign: '5'}, |
| 189 | + }) |
| 190 | + const $legend = wrapper.get('legend') |
| 191 | + expect($legend.classes()).toContain('text-5') |
| 192 | + }) |
| 193 | + |
| 194 | + it('child legend is given class text-sm-{type} when prop labelAlignSm ', () => { |
| 195 | + const wrapper = mount(BFormGroup, { |
| 196 | + props: {label: 'foobar', labelAlignSm: '5'}, |
| 197 | + }) |
| 198 | + const $legend = wrapper.get('legend') |
| 199 | + expect($legend.classes()).toContain('text-sm-5') |
| 200 | + }) |
| 201 | + |
| 202 | + it('child legend is given class text-md-{type} when prop labelAlignMd', () => { |
| 203 | + const wrapper = mount(BFormGroup, { |
| 204 | + props: {label: 'foobar', labelAlignMd: '5'}, |
| 205 | + }) |
| 206 | + const $legend = wrapper.get('legend') |
| 207 | + expect($legend.classes()).toContain('text-md-5') |
| 208 | + }) |
| 209 | + |
| 210 | + it('child legend is given class text-lg-{type} when prop labelAlignLg ', () => { |
| 211 | + const wrapper = mount(BFormGroup, { |
| 212 | + props: {label: 'foobar', labelAlignLg: '5'}, |
| 213 | + }) |
| 214 | + const $legend = wrapper.get('legend') |
| 215 | + expect($legend.classes()).toContain('text-lg-5') |
| 216 | + }) |
| 217 | + |
| 218 | + it('child legend is given class text-xl-{type} when prop labelAlignXl ', () => { |
| 219 | + const wrapper = mount(BFormGroup, { |
| 220 | + props: {label: 'foobar', labelAlignXl: '5'}, |
| 221 | + }) |
| 222 | + const $legend = wrapper.get('legend') |
| 223 | + expect($legend.classes()).toContain('text-xl-5') |
| 224 | + }) |
| 225 | +}) |
0 commit comments