@@ -3,8 +3,6 @@ import { BottomSheetModel } from "./models/bottom-sheet.model"
3
3
4
4
let I : BottomSheetModel
5
5
6
- const ANIMATION_DURATION = 500
7
-
8
6
test . describe ( "bottom-sheet" , ( ) => {
9
7
test . beforeEach ( async ( { page } ) => {
10
8
I = new BottomSheetModel ( page )
@@ -22,11 +20,13 @@ test.describe("bottom-sheet", () => {
22
20
await I . seeBackdrop ( )
23
21
} )
24
22
25
- test ( "should close when backdrop is clicked" , async ( ) => {
23
+ test ( "should close when clicked outside " , async ( ) => {
26
24
await I . clickTrigger ( )
27
25
await I . seeContent ( )
26
+ await I . waitForOpenState ( )
27
+
28
+ await I . clickOutsideSheet ( )
28
29
29
- await I . clickBackdrop ( )
30
30
await I . dontSeeContent ( )
31
31
await I . dontSeeBackdrop ( )
32
32
} )
@@ -39,21 +39,19 @@ test.describe("bottom-sheet", () => {
39
39
await I . seeTriggerIsFocused ( )
40
40
} )
41
41
42
- test ( "should close when dragged down past swipeVelocityThreshold" , async ( { page } ) => {
42
+ test ( "should close when dragged down past swipeVelocityThreshold" , async ( ) => {
43
43
await I . clickTrigger ( )
44
44
await I . seeContent ( )
45
+ await I . waitForOpenState ( )
45
46
46
- await page . waitForTimeout ( ANIMATION_DURATION )
47
-
48
- await I . dragGrabber ( "down" , 100 , 100 )
47
+ await I . dragGrabber ( "down" , 200 , 100 )
49
48
await I . dontSeeContent ( )
50
49
} )
51
50
52
- test ( "should close when dragged down past closeThreshold" , async ( { page } ) => {
51
+ test ( "should close when dragged down past closeThreshold" , async ( ) => {
53
52
await I . clickTrigger ( )
54
53
await I . seeContent ( )
55
-
56
- await page . waitForTimeout ( ANIMATION_DURATION )
54
+ await I . waitForOpenState ( )
57
55
58
56
const initialHeight = await I . getContentVisibleHeight ( )
59
57
const dragDistance = Math . floor ( initialHeight * 0.3 )
@@ -62,21 +60,19 @@ test.describe("bottom-sheet", () => {
62
60
await I . dontSeeContent ( )
63
61
} )
64
62
65
- test ( "should stay open when dragged down slightly" , async ( { page } ) => {
63
+ test ( "should stay open when dragged down slightly" , async ( ) => {
66
64
await I . clickTrigger ( )
67
65
await I . seeContent ( )
68
-
69
- await page . waitForTimeout ( ANIMATION_DURATION )
66
+ await I . waitForOpenState ( )
70
67
71
68
await I . dragGrabber ( "down" , 100 )
72
69
await I . seeContent ( )
73
70
} )
74
71
75
- test ( "should no effect when dragged up" , async ( { page } ) => {
72
+ test ( "should no effect when dragged up" , async ( ) => {
76
73
await I . clickTrigger ( )
77
74
await I . seeContent ( )
78
-
79
- await page . waitForTimeout ( ANIMATION_DURATION )
75
+ await I . waitForOpenState ( )
80
76
81
77
const initialHeight = await I . getContentVisibleHeight ( )
82
78
await I . dragGrabber ( "up" , 150 )
@@ -102,12 +98,12 @@ test.describe("bottom-sheet", () => {
102
98
test ( "should not allow dragging from no-drag area" , async ( { page } ) => {
103
99
await I . clickTrigger ( )
104
100
await I . seeContent ( )
105
-
106
- await page . waitForTimeout ( ANIMATION_DURATION )
101
+ await I . waitForOpenState ( )
107
102
108
103
const initialHeight = await I . getContentVisibleHeight ( )
109
104
110
105
await I . dragNoDragArea ( "down" , 100 , 500 , false )
106
+ await I . waitForSnapComplete ( )
111
107
const heightAfterNoDragAreaDrag = await I . getContentVisibleHeight ( )
112
108
113
109
expect ( initialHeight - heightAfterNoDragAreaDrag ) . toBe ( 0 )
@@ -126,11 +122,10 @@ test.describe("bottom-sheet [draggable=false]", () => {
126
122
await I . goto ( "/bottom-sheet-draggable-false" )
127
123
} )
128
124
129
- test ( "sheet content should not be draggable" , async ( { page } ) => {
125
+ test ( "sheet content should not be draggable" , async ( ) => {
130
126
await I . clickTrigger ( )
131
127
await I . seeContent ( )
132
-
133
- await page . waitForTimeout ( ANIMATION_DURATION )
128
+ await I . waitForOpenState ( )
134
129
135
130
const initialHeight = await I . getContentVisibleHeight ( )
136
131
@@ -150,33 +145,31 @@ test.describe("bottom-sheet [snapPoints]", () => {
150
145
await I . goto ( "/bottom-sheet-snap-points" )
151
146
} )
152
147
153
- test ( "should snap to defined positions" , async ( { page } ) => {
148
+ test ( "should snap to defined positions" , async ( ) => {
154
149
await I . clickTrigger ( )
155
150
await I . seeContent ( )
156
-
157
- await page . waitForTimeout ( ANIMATION_DURATION )
151
+ await I . waitForOpenState ( )
158
152
159
153
const initialHeight = await I . getContentVisibleHeight ( )
160
- const middleHeight = initialHeight * 0.5
161
154
const lowerHeight = initialHeight * 0.25
162
155
163
- // Drag down to middle position (50%)
164
- await I . dragGrabber ( "down" , initialHeight / 2 )
165
- await page . waitForTimeout ( ANIMATION_DURATION )
156
+ // Drag down significantly to trigger snap to 250px fixed snap point
157
+ await I . dragGrabber ( "down" , 300 )
158
+ await I . waitForSnapComplete ( )
166
159
167
160
let currentHeight = await I . getContentVisibleHeight ( )
168
161
169
- // Should snap to middle (50%)
170
- expect ( currentHeight ) . toBe ( middleHeight )
162
+ // Should snap to 250px fixed snap point
163
+ expect ( currentHeight ) . toBe ( 250 )
171
164
172
- // Drag down more to snap to lower position (25% )
173
- await I . dragGrabber ( "down" , currentHeight / 2 )
174
- await page . waitForTimeout ( ANIMATION_DURATION )
165
+ // Drag down to snap to 25% position (drag less to avoid closing )
166
+ await I . dragGrabber ( "down" , 60 )
167
+ await I . waitForSnapComplete ( )
175
168
176
169
currentHeight = await I . getContentVisibleHeight ( )
177
170
178
- // Should be at a lower snap point
179
- expect ( currentHeight ) . toBe ( lowerHeight )
171
+ // Should be at 25% snap point (allow small rounding differences)
172
+ expect ( currentHeight ) . toBeCloseTo ( lowerHeight , 0 )
180
173
} )
181
174
} )
182
175
@@ -186,44 +179,50 @@ test.describe("bottom-sheet [defaultActiveSnapPoint]", () => {
186
179
await I . goto ( "/bottom-sheet-default-active-snap-point" )
187
180
} )
188
181
189
- test ( "should open at default snap point and drag to 50% and 100%" , async ( { page } ) => {
182
+ test ( "should open at default snap point and drag to 250px and 100%" , async ( ) => {
190
183
await I . clickTrigger ( )
191
184
await I . seeContent ( )
185
+ await I . waitForOpenState ( )
186
+
187
+ let currentHeight = await I . getContentVisibleHeight ( )
192
188
193
- await page . waitForTimeout ( ANIMATION_DURATION )
189
+ // Calculate expected heights based on actual content height
190
+ // First, drag to 100% to get the full height
191
+ await I . dragGrabber ( "up" , 600 )
192
+ await I . waitForSnapComplete ( )
194
193
195
- const fullHeight = 500
196
- const middleHeight = fullHeight * 0.5
194
+ const fullHeight = await I . getContentVisibleHeight ( )
197
195
const lowerHeight = fullHeight * 0.25
198
196
199
- let currentHeight = await I . getContentVisibleHeight ( )
197
+ // Close and reopen to test default snap point
198
+ await I . pressKey ( "Escape" )
199
+ await I . dontSeeContent ( )
200
+
201
+ await I . clickTrigger ( )
202
+ await I . seeContent ( )
203
+ await I . waitForOpenState ( )
204
+
205
+ currentHeight = await I . getContentVisibleHeight ( )
200
206
201
207
// Should open at default snap point (25%)
202
- expect ( currentHeight ) . toBe ( lowerHeight )
208
+ expect ( currentHeight ) . toBeCloseTo ( lowerHeight , 0 )
203
209
204
- // Drag up to reach middle position (50%)
205
- await I . dragGrabber ( "up" , 175 )
206
- await page . waitForTimeout ( ANIMATION_DURATION )
210
+ // Drag up to reach 250px snap point
211
+ await I . dragGrabber ( "up" , 100 )
212
+ await I . waitForSnapComplete ( )
207
213
208
214
currentHeight = await I . getContentVisibleHeight ( )
209
215
210
- // Should have snapped to middle position (50%)
211
- expect ( currentHeight ) . toBe ( middleHeight )
216
+ // Should have snapped to 250px fixed snap point
217
+ expect ( currentHeight ) . toBe ( 250 )
212
218
213
219
// Drag up more to reach full height (100%)
214
- await I . dragGrabber ( "up" , 250 )
215
- await page . waitForTimeout ( ANIMATION_DURATION )
220
+ await I . dragGrabber ( "up" , 500 )
221
+ await I . waitForSnapComplete ( )
216
222
217
223
currentHeight = await I . getContentVisibleHeight ( )
218
224
219
225
// Should be at maximum height (100% snap point)
220
226
expect ( currentHeight ) . toBe ( fullHeight )
221
-
222
- // Try dragging up more - should not increase further as it's at max
223
- await I . dragGrabber ( "up" , 100 )
224
- await page . waitForTimeout ( ANIMATION_DURATION )
225
-
226
- currentHeight = await I . getContentVisibleHeight ( )
227
- expect ( currentHeight ) . toBe ( fullHeight )
228
227
} )
229
228
} )
0 commit comments