@@ -6,7 +6,7 @@ describe('useCollapse', () => {
6
6
it ( 'should return expected methods and properties' , ( ) => {
7
7
const collapsed = ref ( false ) ;
8
8
const sizePercentage = ref ( 50 ) ;
9
- const options = { transitionDuration : 300 } ;
9
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
10
10
11
11
const result = useCollapse ( collapsed , sizePercentage , options ) ;
12
12
@@ -26,7 +26,7 @@ describe('useCollapse', () => {
26
26
it ( 'should set collapsed to true' , ( ) => {
27
27
const collapsed = ref ( false ) ;
28
28
const sizePercentage = ref ( 50 ) ;
29
- const options = { transitionDuration : 300 } ;
29
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
30
30
31
31
const { collapse } = useCollapse ( collapsed , sizePercentage , options ) ;
32
32
@@ -40,7 +40,7 @@ describe('useCollapse', () => {
40
40
it ( 'should set collapsed to false' , ( ) => {
41
41
const collapsed = ref ( true ) ;
42
42
const sizePercentage = ref ( 0 ) ;
43
- const options = { transitionDuration : 300 } ;
43
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
44
44
45
45
const { expand } = useCollapse ( collapsed , sizePercentage , options ) ;
46
46
@@ -54,7 +54,7 @@ describe('useCollapse', () => {
54
54
it ( 'should set collapsed to the provided value' , ( ) => {
55
55
const collapsed = ref ( false ) ;
56
56
const sizePercentage = ref ( 50 ) ;
57
- const options = { transitionDuration : 300 } ;
57
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
58
58
59
59
const { toggle } = useCollapse ( collapsed , sizePercentage , options ) ;
60
60
@@ -67,10 +67,10 @@ describe('useCollapse', () => {
67
67
} ) ;
68
68
69
69
describe ( 'collapsed watcher behavior' , ( ) => {
70
- it ( 'should store size and set to 0 when collapsing' , async ( ) => {
70
+ it ( 'should store size and set to collapsedSize when collapsing' , async ( ) => {
71
71
const collapsed = ref ( false ) ;
72
72
const sizePercentage = ref ( 75 ) ;
73
- const options = { transitionDuration : 300 } ;
73
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
74
74
75
75
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
76
76
@@ -84,7 +84,7 @@ describe('useCollapse', () => {
84
84
it ( 'should restore size when expanding' , async ( ) => {
85
85
const collapsed = ref ( false ) ;
86
86
const sizePercentage = ref ( 60 ) ;
87
- const options = { transitionDuration : 300 } ;
87
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
88
88
89
89
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
90
90
@@ -104,7 +104,7 @@ describe('useCollapse', () => {
104
104
it ( 'should preserve original size through multiple collapse/expand cycles' , async ( ) => {
105
105
const collapsed = ref ( false ) ;
106
106
const sizePercentage = ref ( 42 ) ;
107
- const options = { transitionDuration : 300 } ;
107
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
108
108
109
109
useCollapse ( collapsed , sizePercentage , options ) ;
110
110
@@ -130,7 +130,7 @@ describe('useCollapse', () => {
130
130
it ( 'should handle size changes between collapse cycles' , async ( ) => {
131
131
const collapsed = ref ( false ) ;
132
132
const sizePercentage = ref ( 30 ) ;
133
- const options = { transitionDuration : 300 } ;
133
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
134
134
135
135
useCollapse ( collapsed , sizePercentage , options ) ;
136
136
@@ -163,7 +163,7 @@ describe('useCollapse', () => {
163
163
it ( 'should start with null transition state' , ( ) => {
164
164
const collapsed = ref ( false ) ;
165
165
const sizePercentage = ref ( 50 ) ;
166
- const options = { transitionDuration : 300 } ;
166
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
167
167
168
168
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
169
169
@@ -173,7 +173,7 @@ describe('useCollapse', () => {
173
173
it ( 'should set collapsing state when collapsed becomes true' , async ( ) => {
174
174
const collapsed = ref ( false ) ;
175
175
const sizePercentage = ref ( 50 ) ;
176
- const options = { transitionDuration : 300 } ;
176
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
177
177
178
178
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
179
179
@@ -186,7 +186,7 @@ describe('useCollapse', () => {
186
186
it ( 'should set expanding state when collapsed becomes false' , async ( ) => {
187
187
const collapsed = ref ( true ) ;
188
188
const sizePercentage = ref ( 0 ) ;
189
- const options = { transitionDuration : 300 } ;
189
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
190
190
191
191
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
192
192
@@ -201,7 +201,7 @@ describe('useCollapse', () => {
201
201
it ( 'should return CSS transition duration' , ( ) => {
202
202
const collapsed = ref ( false ) ;
203
203
const sizePercentage = ref ( 50 ) ;
204
- const options = { transitionDuration : 500 } ;
204
+ const options = { transitionDuration : 500 , collapsedSize : 0 } ;
205
205
206
206
const { transitionDurationCss } = useCollapse ( collapsed , sizePercentage , options ) ;
207
207
@@ -212,7 +212,7 @@ describe('useCollapse', () => {
212
212
const collapsed = ref ( false ) ;
213
213
const sizePercentage = ref ( 50 ) ;
214
214
const transitionDuration = ref ( 300 ) ;
215
- const options = { transitionDuration } ;
215
+ const options = { transitionDuration, collapsedSize : 0 } ;
216
216
217
217
const { transitionDurationCss } = useCollapse ( collapsed , sizePercentage , options ) ;
218
218
@@ -227,7 +227,7 @@ describe('useCollapse', () => {
227
227
it ( 'should handle rapid collapse/expand operations' , async ( ) => {
228
228
const collapsed = ref ( false ) ;
229
229
const sizePercentage = ref ( 65 ) ;
230
- const options = { transitionDuration : 300 } ;
230
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
231
231
232
232
const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
233
233
@@ -247,7 +247,7 @@ describe('useCollapse', () => {
247
247
it ( 'should work with methods triggering state changes' , async ( ) => {
248
248
const collapsed = ref ( false ) ;
249
249
const sizePercentage = ref ( 45 ) ;
250
- const options = { transitionDuration : 300 } ;
250
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
251
251
252
252
const { collapse, expand, toggle, collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
253
253
@@ -276,7 +276,7 @@ describe('useCollapse', () => {
276
276
it ( 'should work with zero initial size' , async ( ) => {
277
277
const collapsed = ref ( false ) ;
278
278
const sizePercentage = ref ( 0 ) ;
279
- const options = { transitionDuration : 300 } ;
279
+ const options = { transitionDuration : 300 , collapsedSize : 0 } ;
280
280
281
281
useCollapse ( collapsed , sizePercentage , options ) ;
282
282
@@ -290,5 +290,51 @@ describe('useCollapse', () => {
290
290
await nextTick ( ) ;
291
291
expect ( sizePercentage . value ) . toBe ( 0 ) ;
292
292
} ) ;
293
+
294
+ it ( 'should use custom collapsedSize value' , async ( ) => {
295
+ const collapsed = ref ( false ) ;
296
+ const sizePercentage = ref ( 60 ) ;
297
+ const options = { transitionDuration : 300 , collapsedSize : 10 } ;
298
+
299
+ const { collapseTransitionState } = useCollapse ( collapsed , sizePercentage , options ) ;
300
+
301
+ // Collapse to custom size
302
+ collapsed . value = true ;
303
+ await nextTick ( ) ;
304
+ expect ( sizePercentage . value ) . toBe ( 10 ) ;
305
+ expect ( collapseTransitionState . value ) . toBe ( 'collapsing' ) ;
306
+
307
+ // Expand should restore original size
308
+ collapsed . value = false ;
309
+ await nextTick ( ) ;
310
+ expect ( sizePercentage . value ) . toBe ( 60 ) ;
311
+ expect ( collapseTransitionState . value ) . toBe ( 'expanding' ) ;
312
+ } ) ;
313
+
314
+ it ( 'should support reactive collapsedSize value' , async ( ) => {
315
+ const collapsed = ref ( false ) ;
316
+ const sizePercentage = ref ( 70 ) ;
317
+ const collapsedSize = ref ( 5 ) ;
318
+ const options = { transitionDuration : 300 , collapsedSize } ;
319
+
320
+ useCollapse ( collapsed , sizePercentage , options ) ;
321
+
322
+ // Collapse with initial collapsedSize
323
+ collapsed . value = true ;
324
+ await nextTick ( ) ;
325
+ expect ( sizePercentage . value ) . toBe ( 5 ) ;
326
+
327
+ // Change collapsedSize while collapsed
328
+ collapsedSize . value = 15 ;
329
+
330
+ // Expand and collapse again with new collapsedSize
331
+ collapsed . value = false ;
332
+ await nextTick ( ) ;
333
+ expect ( sizePercentage . value ) . toBe ( 70 ) ;
334
+
335
+ collapsed . value = true ;
336
+ await nextTick ( ) ;
337
+ expect ( sizePercentage . value ) . toBe ( 15 ) ;
338
+ } ) ;
293
339
} ) ;
294
340
} ) ;
0 commit comments