|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { ref } from 'vue'; |
| 3 | +import { |
| 4 | + useCancelButtonClass, |
| 5 | + useCardContainerClass, |
| 6 | + useDisplayContainerClass, |
| 7 | + useDisplayInputControlClasses, |
| 8 | + useDisplaySelectionControlClasses, |
| 9 | + useDisplayValueClass, |
| 10 | + useFieldContainerClass, |
| 11 | + useInlineFieldsContainerClass, |
| 12 | + usePrependAppendIconClasses, |
| 13 | + useSaveFieldsContainerClass, |
| 14 | +} from '../classes'; |
| 15 | + |
| 16 | + |
| 17 | +const cn = 'v-inline-fields'; |
| 18 | + |
| 19 | +describe('Classes Composable', () => { |
| 20 | + describe('useInlineFieldsContainerClass', () => { |
| 21 | + it('should include base classes', () => { |
| 22 | + const result = useInlineFieldsContainerClass({}); |
| 23 | + expect(result).toMatchObject({ |
| 24 | + [cn]: true, |
| 25 | + [`${cn}--container`]: true, |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should add cell class when cell is true and showField is false', () => { |
| 30 | + const result = useInlineFieldsContainerClass({ cell: true }); |
| 31 | + expect(result).toMatchObject({ [`${cn}--container-cell`]: true }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should add disabled class when disabled is true', () => { |
| 35 | + const result = useInlineFieldsContainerClass({ disabled: true }); |
| 36 | + expect(result).toMatchObject({ [`${cn}--container-disabled`]: true }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should accept a ref for disabled', () => { |
| 40 | + const result = useInlineFieldsContainerClass({ disabled: ref(true) }); |
| 41 | + expect(result).toMatchObject({ [`${cn}--container-disabled`]: true }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should add loading class when loading and loadingWait are true', () => { |
| 45 | + const result = useInlineFieldsContainerClass({ loading: true, loadingWait: true }); |
| 46 | + expect(result).toMatchObject({ [`${cn}--container-loading`]: true }); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should not add loading class when loadingWait is false', () => { |
| 50 | + const result = useInlineFieldsContainerClass({ loading: true, loadingWait: false }); |
| 51 | + expect(result[`${cn}--container-loading`]).toBe(false); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should add tableField class when tableField is true', () => { |
| 55 | + const result = useInlineFieldsContainerClass({ tableField: true }); |
| 56 | + expect(result).toMatchObject({ [`${cn}--container-table`]: true }); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should add field-specific classes when field, density, and variant are provided', () => { |
| 60 | + const result = useInlineFieldsContainerClass({ density: 'compact', field: 'v-text-field', variant: 'outlined' }); |
| 61 | + expect(result[`${cn}--container-v-text-field`]).toBe(true); |
| 62 | + expect(result[`${cn}--container-v-text-field-compact`]).toBe(true); |
| 63 | + expect(result[`${cn}--container-v-text-field-outlined`]).toBeTruthy(); |
| 64 | + expect(result[`${cn}--container-v-text-field-compact-outlined`]).toBeTruthy(); |
| 65 | + expect(result[`${cn}--container-v-text-field-outlined-compact`]).toBeTruthy(); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should use mdi as default icon set', () => { |
| 69 | + const result = useInlineFieldsContainerClass({}); |
| 70 | + expect(result).toMatchObject({ [`${cn}--container-icon-set-mdi`]: true }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + |
| 75 | + describe('useDisplayContainerClass', () => { |
| 76 | + it('should include base classes', () => { |
| 77 | + const result = useDisplayContainerClass({}); |
| 78 | + expect(result).toMatchObject({ |
| 79 | + [`${cn}--display-container`]: true, |
| 80 | + [`${cn}--display-wrapper-value`]: true, |
| 81 | + 'v-input': true, |
| 82 | + 'v-input--horizontal': true, |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should add cell class when cell is true', () => { |
| 87 | + const result = useDisplayContainerClass({ cell: true }); |
| 88 | + expect(result).toMatchObject({ [`${cn}--display-container-cell`]: true }); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should add underline full-width class when cell and cellUnderlineFullWidth are true', () => { |
| 92 | + const result = useDisplayContainerClass({ cell: true, cellUnderlineFullWidth: true }); |
| 93 | + expect(result).toMatchObject({ [`${cn}--display-container-cell-underline-full-width`]: true }); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should not add underline full-width class when cellUnderlineFullWidth is false', () => { |
| 97 | + const result = useDisplayContainerClass({ cell: true, cellUnderlineFullWidth: false }); |
| 98 | + expect(result[`${cn}--display-container-cell-underline-full-width`]).toBe(false); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should include density class', () => { |
| 102 | + const result = useDisplayContainerClass({ density: 'compact' }); |
| 103 | + expect(result).toMatchObject({ 'v-input--density-compact': true }); |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + |
| 108 | + describe('useDisplayInputControlClasses', () => { |
| 109 | + it('should include base classes', () => { |
| 110 | + const result = useDisplayInputControlClasses({}); |
| 111 | + expect(result).toMatchObject({ |
| 112 | + 'v-input': true, |
| 113 | + 'v-input--dirty': true, |
| 114 | + 'v-input--horizontal': true, |
| 115 | + 'v-text-field': true, |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should include density class', () => { |
| 120 | + const result = useDisplayInputControlClasses({ density: 'comfortable' }); |
| 121 | + expect(result).toMatchObject({ 'v-input--density-comfortable': true }); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should include variant class', () => { |
| 125 | + const result = useDisplayInputControlClasses({ variant: 'outlined' }); |
| 126 | + expect(result).toMatchObject({ 'v-text-field--plain-outlined': true }); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + |
| 131 | + describe('useDisplaySelectionControlClasses', () => { |
| 132 | + it('should include base class', () => { |
| 133 | + const result = useDisplaySelectionControlClasses({}); |
| 134 | + expect(result).toMatchObject({ [`${cn}--selection-control`]: true }); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should include density class', () => { |
| 138 | + const result = useDisplaySelectionControlClasses({ density: 'compact' }); |
| 139 | + expect(result).toMatchObject({ 'v-selection-control--density-compact': true }); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + |
| 144 | + describe('useDisplayValueClass', () => { |
| 145 | + it('should include base and name classes', () => { |
| 146 | + const result = useDisplayValueClass('text-field', 'primary', {}); |
| 147 | + expect(result).toMatchObject({ |
| 148 | + [cn]: true, |
| 149 | + [`${cn}--display-value-text-field`]: true, |
| 150 | + [`${cn}--display-value`]: true, |
| 151 | + }); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should apply valueColor class when no error', () => { |
| 155 | + const result = useDisplayValueClass('text-field', 'primary', { error: false }); |
| 156 | + expect(result).toMatchObject({ 'text-danger': false, 'text-primary': true }); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should apply danger class when error is true', () => { |
| 160 | + const result = useDisplayValueClass('text-field', 'primary', { error: true }); |
| 161 | + expect(result).toMatchObject({ 'text-danger': true, 'text-primary': false }); |
| 162 | + }); |
| 163 | + |
| 164 | + it('should accept a ref for error', () => { |
| 165 | + const result = useDisplayValueClass('text-field', 'primary', { error: ref(true) }); |
| 166 | + expect(result).toMatchObject({ 'text-danger': true }); |
| 167 | + }); |
| 168 | + |
| 169 | + it('should add empty class when empty is true', () => { |
| 170 | + const result = useDisplayValueClass('text-field', 'primary', { empty: true }); |
| 171 | + expect(result).toMatchObject({ [`${cn}--display-value-empty`]: true }); |
| 172 | + }); |
| 173 | + }); |
| 174 | + |
| 175 | + |
| 176 | + describe('usePrependAppendIconClasses', () => { |
| 177 | + it('should add outer prepend classes when inner is false and position is prepend', () => { |
| 178 | + const result = usePrependAppendIconClasses({ inner: false, position: 'prepend' }); |
| 179 | + expect(result).toMatchObject({ |
| 180 | + [`${cn}--display-icon`]: true, |
| 181 | + [`${cn}--display-prepend-icon`]: true, |
| 182 | + 'me-1': true, |
| 183 | + 'ms-1': false, |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + it('should add outer append classes when inner is false and position is append', () => { |
| 188 | + const result = usePrependAppendIconClasses({ inner: false, position: 'append' }); |
| 189 | + expect(result).toMatchObject({ |
| 190 | + [`${cn}--display-icon`]: true, |
| 191 | + [`${cn}--display-append-icon`]: true, |
| 192 | + 'me-1': false, |
| 193 | + 'ms-1': true, |
| 194 | + }); |
| 195 | + }); |
| 196 | + |
| 197 | + it('should add inner class when inner is true', () => { |
| 198 | + const result = usePrependAppendIconClasses({ inner: true, position: 'prepend' }); |
| 199 | + expect(result).toMatchObject({ |
| 200 | + [`${cn}--display-icon`]: false, |
| 201 | + [`${cn}--display-prepend-inner-icon`]: true, |
| 202 | + }); |
| 203 | + }); |
| 204 | + }); |
| 205 | + |
| 206 | + |
| 207 | + describe('useFieldContainerClass', () => { |
| 208 | + it('should include base classes', () => { |
| 209 | + const result = useFieldContainerClass({ name: 'text-field' }); |
| 210 | + expect(result).toMatchObject({ |
| 211 | + [cn]: true, |
| 212 | + [`${cn}--field`]: true, |
| 213 | + [`${cn}--field-text-field`]: true, |
| 214 | + }); |
| 215 | + }); |
| 216 | + |
| 217 | + it('should add active class when active is true', () => { |
| 218 | + const result = useFieldContainerClass({ active: true, name: 'text-field' }); |
| 219 | + expect(result).toMatchObject({ [`${cn}--field-active`]: true }); |
| 220 | + }); |
| 221 | + |
| 222 | + it('should not add active class when active is false', () => { |
| 223 | + const result = useFieldContainerClass({ active: false, name: 'text-field' }); |
| 224 | + expect(result[`${cn}--field-active`]).toBe(false); |
| 225 | + }); |
| 226 | + }); |
| 227 | + |
| 228 | + |
| 229 | + describe('useSaveFieldsContainerClass', () => { |
| 230 | + it('should return the save fields container class', () => { |
| 231 | + const result = useSaveFieldsContainerClass(); |
| 232 | + expect(result).toMatchObject({ [`${cn}--save-fields-container`]: true }); |
| 233 | + }); |
| 234 | + }); |
| 235 | + |
| 236 | + |
| 237 | + describe('useCancelButtonClass', () => { |
| 238 | + it('should add me-1 when variant is elevated', () => { |
| 239 | + const result = useCancelButtonClass({ cancelButtonVariant: 'elevated' }); |
| 240 | + expect(result).toMatchObject({ 'me-1': true, 'ms-1': true }); |
| 241 | + }); |
| 242 | + |
| 243 | + it('should not add me-1 when variant is not elevated', () => { |
| 244 | + const result = useCancelButtonClass({ cancelButtonVariant: 'text' }); |
| 245 | + expect(result).toMatchObject({ 'me-1': false, 'ms-1': true }); |
| 246 | + }); |
| 247 | + |
| 248 | + it('should always include ms-1', () => { |
| 249 | + const result = useCancelButtonClass({}); |
| 250 | + expect(result).toMatchObject({ 'ms-1': true }); |
| 251 | + }); |
| 252 | + }); |
| 253 | + |
| 254 | + |
| 255 | + describe('useCardContainerClass', () => { |
| 256 | + it('should include base and name classes', () => { |
| 257 | + const result = useCardContainerClass({ name: 'custom-field', showField: false }); |
| 258 | + expect(result).toMatchObject({ |
| 259 | + [`${cn}--card-container`]: true, |
| 260 | + [`${cn}--card-container-custom-field`]: true, |
| 261 | + }); |
| 262 | + }); |
| 263 | + |
| 264 | + it('should hide when showField is false', () => { |
| 265 | + const result = useCardContainerClass({ name: 'custom-field', showField: false }); |
| 266 | + expect(result).toMatchObject({ 'd-none': true }); |
| 267 | + }); |
| 268 | + |
| 269 | + it('should not hide when showField is true', () => { |
| 270 | + const result = useCardContainerClass({ name: 'custom-field', showField: true }); |
| 271 | + expect(result).toMatchObject({ 'd-none': false }); |
| 272 | + }); |
| 273 | + }); |
| 274 | +}); |
0 commit comments