|
| 1 | +import type { ComputedRef } from 'vue'; |
| 2 | +import type { UseGridTemplateOptions } from './use-grid-template'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | +import { computed, ref } from 'vue'; |
| 5 | +import { useGridTemplate } from './use-grid-template'; |
| 6 | + |
| 7 | +describe('useGridTemplate', () => { |
| 8 | + const createOptions = (overrides = {}): UseGridTemplateOptions => ({ |
| 9 | + collapsed: ref(false), |
| 10 | + minSizePercentage: computed(() => {}) as ComputedRef<number | undefined>, |
| 11 | + maxSizePercentage: computed(() => {}) as ComputedRef<number | undefined>, |
| 12 | + sizePercentage: computed(() => 50), |
| 13 | + dividerSize: computed(() => 4), |
| 14 | + primary: 'start', |
| 15 | + direction: 'ltr', |
| 16 | + orientation: 'horizontal', |
| 17 | + ...overrides, |
| 18 | + }); |
| 19 | + |
| 20 | + it('returns collapsed state when collapsed is true', () => { |
| 21 | + const options = createOptions({ collapsed: ref(true) }); |
| 22 | + const { gridTemplate } = useGridTemplate(options); |
| 23 | + |
| 24 | + expect(gridTemplate.value).toBe('0 4px auto'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('returns basic clamp template when no min/max constraints', () => { |
| 28 | + const options = createOptions(); |
| 29 | + const { gridTemplate } = useGridTemplate(options); |
| 30 | + |
| 31 | + expect(gridTemplate.value).toBe('clamp(0%, 50%, calc(100% - 4px)) 4px auto'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('returns complex clamp template with min/max constraints', () => { |
| 35 | + const options = createOptions({ |
| 36 | + minSizePercentage: computed(() => 20), |
| 37 | + maxSizePercentage: computed(() => 80), |
| 38 | + }); |
| 39 | + const { gridTemplate } = useGridTemplate(options); |
| 40 | + |
| 41 | + expect(gridTemplate.value).toBe('clamp(0%, clamp(20%, 50%, 80%), calc(100% - 4px)) 4px auto'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('reverses order when primary is end and direction is ltr', () => { |
| 45 | + const options = createOptions({ primary: 'end' }); |
| 46 | + const { gridTemplate } = useGridTemplate(options); |
| 47 | + |
| 48 | + expect(gridTemplate.value).toBe('auto 4px clamp(0%, 50%, calc(100% - 4px))'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('reverses order when direction is rtl and primary is start', () => { |
| 52 | + const options = createOptions({ direction: 'rtl' }); |
| 53 | + const { gridTemplate } = useGridTemplate(options); |
| 54 | + |
| 55 | + expect(gridTemplate.value).toBe('auto 4px clamp(0%, 50%, calc(100% - 4px))'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('handles vertical orientation correctly', () => { |
| 59 | + const options = createOptions({ orientation: 'vertical' }); |
| 60 | + const { gridTemplate } = useGridTemplate(options); |
| 61 | + |
| 62 | + expect(gridTemplate.value).toBe('clamp(0%, 50%, calc(100% - 4px)) 4px auto'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('handles vertical orientation with end primary', () => { |
| 66 | + const options = createOptions({ |
| 67 | + orientation: 'vertical', |
| 68 | + primary: 'end', |
| 69 | + }); |
| 70 | + const { gridTemplate } = useGridTemplate(options); |
| 71 | + |
| 72 | + expect(gridTemplate.value).toBe('auto 4px clamp(0%, 50%, calc(100% - 4px))'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('uses custom divider size', () => { |
| 76 | + const options = createOptions({ dividerSize: computed(() => 8) }); |
| 77 | + const { gridTemplate } = useGridTemplate(options); |
| 78 | + |
| 79 | + expect(gridTemplate.value).toBe('clamp(0%, 50%, calc(100% - 8px)) 8px auto'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('handles undefined primary as start', () => { |
| 83 | + const options = createOptions({ primary: undefined }); |
| 84 | + const { gridTemplate } = useGridTemplate(options); |
| 85 | + |
| 86 | + expect(gridTemplate.value).toBe('clamp(0%, 50%, calc(100% - 4px)) 4px auto'); |
| 87 | + }); |
| 88 | +}); |
0 commit comments