Skip to content

Commit c0c2ea1

Browse files
test: add tests for composables (#37)
1 parent e889ed8 commit c0c2ea1

File tree

10 files changed

+783
-18
lines changed

10 files changed

+783
-18
lines changed

packages/vue-split-panel/src/SplitPanel.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,14 @@ defineExpose({ collapse, expand, toggle });
126126
</script>
127127

128128
<template>
129-
<div ref="split-panel" class="split-panel" :class="[orientation, collapseTransitionState, { collapsed, dragging: isDragging }]" @transitionend="onTransitionEnd">
130-
<div class="start">
129+
<div
130+
ref="split-panel"
131+
class="split-panel"
132+
:class="[orientation, collapseTransitionState, { collapsed, dragging: isDragging }]"
133+
data-testid="root"
134+
@transitionend="onTransitionEnd"
135+
>
136+
<div class="start" data-testid="start">
131137
<slot name="start" />
132138
</div>
133139
<div
@@ -140,14 +146,15 @@ defineExpose({ collapse, expand, toggle });
140146
aria-valuemin="0"
141147
aria-valuemax="100"
142148
aria-label="Resize"
149+
data-testid="divider"
143150
@keydown="handleKeydown"
144151
@dblclick="handleDblClick"
145152
>
146153
<slot name="divider">
147154
<div />
148155
</slot>
149156
</div>
150-
<div class="end">
157+
<div class="end" data-testid="end">
151158
<slot name="end" />
152159
</div>
153160
</div>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)