1
1
import { expect } from '@playwright/test' ;
2
- import type { Locator } from '@playwright/test' ;
3
2
import { configs , test } from '@utils/test/playwright' ;
4
- import type { E2EPage } from '@utils/test/playwright' ;
5
3
6
- configs ( { directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
4
+ import { ActionSheetFixture } from './fixture' ;
5
+
6
+ /**
7
+ * This behavior does not vary across modes/directions
8
+ */
9
+ configs ( { mode : [ 'ios' ] , directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
7
10
test . describe ( title ( 'action sheet: data' ) , ( ) => {
8
11
let actionSheetFixture ! : ActionSheetFixture ;
9
12
test . beforeEach ( async ( { page } ) => {
@@ -35,58 +38,11 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
35
38
} ) ;
36
39
} ) ;
37
40
} ) ;
38
- configs ( { directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
39
- test . describe ( title ( 'action sheet: attributes' ) , ( ) => {
40
- test ( 'should set htmlAttributes' , async ( { page } ) => {
41
- await page . goto ( `/src/components/action-sheet/test/basic` , config ) ;
42
- const actionSheetFixture = new ActionSheetFixture ( page ) ;
43
-
44
- await actionSheetFixture . open ( '#basic' ) ;
45
-
46
- const actionSheet = page . locator ( 'ion-action-sheet' ) ;
47
- await expect ( actionSheet ) . toHaveAttribute ( 'data-testid' , 'basic-action-sheet' ) ;
48
- } ) ;
49
- } ) ;
50
- } ) ;
51
- configs ( ) . forEach ( ( { config, screenshot, title } ) => {
52
- test . describe ( title ( 'action sheet: variant rendering' ) , ( ) => {
53
- let actionSheetFixture ! : ActionSheetFixture ;
54
- test . beforeEach ( async ( { page } ) => {
55
- actionSheetFixture = new ActionSheetFixture ( page , screenshot ) ;
56
41
57
- await page . goto ( `/src/components/action-sheet/test/basic` , config ) ;
58
- } ) ;
59
- test ( 'should open basic action sheet' , async ( ) => {
60
- await actionSheetFixture . open ( '#basic' ) ;
61
- await actionSheetFixture . screenshot ( 'basic' ) ;
62
-
63
- /**
64
- * We want to test that the dismiss method
65
- * actually works, but we do not need to test
66
- * it every time. As a result, we only
67
- * call dismiss in this test.
68
- */
69
- await actionSheetFixture . dismiss ( ) ;
70
- } ) ;
71
- test ( 'should open cancel only action sheet' , async ( ) => {
72
- await actionSheetFixture . open ( '#cancelOnly' ) ;
73
- await actionSheetFixture . screenshot ( 'cancel-only' ) ;
74
- } ) ;
75
- test ( 'should open custom action sheet' , async ( ) => {
76
- await actionSheetFixture . open ( '#custom' ) ;
77
- await actionSheetFixture . screenshot ( 'custom' ) ;
78
- } ) ;
79
- test ( 'should open scrollable action sheet' , async ( ) => {
80
- await actionSheetFixture . open ( '#scrollableOptions' ) ;
81
- await actionSheetFixture . screenshot ( 'scrollable-options' ) ;
82
- } ) ;
83
- test ( 'should open scrollable action sheet without cancel' , async ( ) => {
84
- await actionSheetFixture . open ( '#scrollWithoutCancel' ) ;
85
- await actionSheetFixture . screenshot ( 'scroll-without-cancel' ) ;
86
- } ) ;
87
- } ) ;
88
- } ) ;
89
- configs ( { directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
42
+ /**
43
+ * This behavior does not vary across modes/directions
44
+ */
45
+ configs ( { mode : [ 'ios' ] , directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
90
46
test . describe ( title ( 'action sheet: variant functionality' ) , ( ) => {
91
47
let actionSheetFixture ! : ActionSheetFixture ;
92
48
test . beforeEach ( async ( { page } ) => {
@@ -118,7 +74,11 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
118
74
} ) ;
119
75
} ) ;
120
76
} ) ;
121
- configs ( { directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
77
+
78
+ /**
79
+ * This behavior does not vary across modes/directions
80
+ */
81
+ configs ( { mode : [ 'ios' ] , directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
122
82
test . describe ( title ( 'action sheet: focus trap' ) , ( ) => {
123
83
test ( 'it should trap focus in action sheet' , async ( { page, browserName } ) => {
124
84
await page . goto ( `/src/components/action-sheet/test/basic` , config ) ;
@@ -140,42 +100,3 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
140
100
} ) ;
141
101
} ) ;
142
102
} ) ;
143
-
144
- class ActionSheetFixture {
145
- readonly page : E2EPage ;
146
- readonly screenshotFn ?: ( file : string ) => string ;
147
-
148
- private actionSheet ! : Locator ;
149
-
150
- constructor ( page : E2EPage , screenshot ?: ( file : string ) => string ) {
151
- this . page = page ;
152
- this . screenshotFn = screenshot ;
153
- }
154
-
155
- async open ( selector : string ) {
156
- const ionActionSheetDidPresent = await this . page . spyOnEvent ( 'ionActionSheetDidPresent' ) ;
157
- await this . page . locator ( selector ) . click ( ) ;
158
- await ionActionSheetDidPresent . next ( ) ;
159
- this . actionSheet = this . page . locator ( 'ion-action-sheet' ) ;
160
- await expect ( this . actionSheet ) . toBeVisible ( ) ;
161
- }
162
-
163
- async dismiss ( ) {
164
- const ionActionSheetDidDismiss = await this . page . spyOnEvent ( 'ionActionSheetDidDismiss' ) ;
165
- await this . actionSheet . evaluate ( ( el : HTMLIonActionSheetElement ) => el . dismiss ( ) ) ;
166
- await ionActionSheetDidDismiss . next ( ) ;
167
- await expect ( this . actionSheet ) . not . toBeVisible ( ) ;
168
- }
169
-
170
- async screenshot ( modifier : string ) {
171
- const { screenshotFn } = this ;
172
-
173
- if ( ! screenshotFn ) {
174
- throw new Error (
175
- 'A screenshot function is required to take a screenshot. Pass one in when creating ActionSheetFixture.'
176
- ) ;
177
- }
178
-
179
- await expect ( this . actionSheet ) . toHaveScreenshot ( screenshotFn ( `action-sheet-${ modifier } -diff` ) ) ;
180
- }
181
- }
0 commit comments