@@ -15,17 +15,16 @@ import {
15
15
expect ,
16
16
fixture ,
17
17
html ,
18
- nextFrame ,
19
- oneEvent ,
18
+ waitUntil ,
20
19
} from '@open-wc/testing' ;
21
20
import { ActionMenu } from '@spectrum-web-components/action-menu' ;
22
21
import '@spectrum-web-components/action-menu/sync/sp-action-menu.js' ;
23
22
import '@spectrum-web-components/menu/sp-menu-divider.js' ;
24
23
import '@spectrum-web-components/menu/sp-menu-item.js' ;
25
- import { setViewport } from '@web/test-runner-commands' ;
26
24
import { spreadProps } from '../../../test/lit-helpers.js' ;
27
- import { sendMouse } from '../../../test/plugins/browser.js' ;
28
- import { isChrome } from '@spectrum-web-components/shared' ;
25
+ import { sendMouseTo } from '../../../test/testing-helpers.js' ;
26
+ import { Popover } from '@spectrum-web-components/popover' ;
27
+ import { Tray } from '@spectrum-web-components/tray/src/Tray.js' ;
29
28
30
29
describe ( 'ActionMenu, responsive' , ( ) => {
31
30
let el : ActionMenu ;
@@ -63,51 +62,42 @@ describe('ActionMenu, responsive', () => {
63
62
el . isMobile . matches = true ;
64
63
el . bindEvents ( ) ;
65
64
66
- /**
67
- * While we can set the view port, but not `(hover: none) and (pointer: coarse)`
68
- * which prevents us from testing this at unit time. Hopefully there will be
69
- * a future version of Playwright and/or @web/test-runner that does allow this.
70
- * See: https://github.com/microsoft/playwright/issues/11781
71
- **/
72
- await setViewport ( { width : 360 , height : 640 } ) ;
73
- // Allow viewport update to propagate.
74
- await nextFrame ( ) ;
75
-
76
- const opened = oneEvent ( el , 'sp-opened' ) ;
77
-
78
- const boundingRect = el . button . getBoundingClientRect ( ) ;
79
- sendMouse ( {
80
- steps : [
81
- {
82
- type : 'click' ,
83
- position : [
84
- boundingRect . x + boundingRect . width / 2 ,
85
- boundingRect . y + boundingRect . height / 2 ,
86
- ] ,
87
- } ,
88
- ] ,
89
- } ) ;
90
-
91
- await opened ;
65
+ sendMouseTo ( el . button , 'click' ) ;
66
+
67
+ // in this test we only need to wait to see if a tray opens
68
+ let tray : Tray | null = null ;
69
+ await waitUntil (
70
+ ( ) => {
71
+ tray = el . shadowRoot . querySelector ( 'sp-tray' ) as Tray ;
72
+ return ! ! tray ;
73
+ } ,
74
+ `tray appeared (el.open: ${ el . open } )` ,
75
+ { timeout : 300 }
76
+ ) ;
92
77
93
- const tray = el . shadowRoot . querySelector ( 'sp-tray' ) ;
94
78
const popover = el . shadowRoot . querySelector ( 'sp-popover' ) ;
95
79
96
80
expect ( tray ) . to . not . be . null ;
97
81
expect ( popover ) . to . be . null ;
98
82
} ) ;
99
83
100
84
it ( 'is a Popover in desktop' , async ( ) => {
101
- await setViewport ( { width : 701 , height : 640 } ) ;
102
- // Allow viewport update to propagate.
103
- await nextFrame ( ) ;
104
- await nextFrame ( ) ;
105
85
106
- const opened = oneEvent ( el , 'sp-opened' ) ;
107
86
el . open = true ;
108
- await opened ;
109
87
110
- const popover = el . shadowRoot . querySelector ( 'sp-popover' ) ;
88
+ // in this test we only need to wait to see if a popover opens
89
+ let popover : Popover | null = null ;
90
+ await waitUntil (
91
+ ( ) => {
92
+ popover = el . shadowRoot . querySelector (
93
+ 'sp-popover'
94
+ ) as Popover ;
95
+ return ! ! popover && popover . open ;
96
+ } ,
97
+ `popover appeared (el.open: ${ el . open } )` ,
98
+ { timeout : 300 }
99
+ ) ;
100
+
111
101
const tray = el . shadowRoot . querySelector ( 'sp-tray' ) ;
112
102
113
103
expect ( popover ) . to . not . be . null ;
@@ -122,63 +112,50 @@ describe('ActionMenu, responsive', () => {
122
112
} ) ;
123
113
124
114
it ( 'is a Popover in mobile' , async ( ) => {
125
- // This test is flaky in chrome on ci so we're skipping it for now
126
- if ( isChrome ( ) ) {
127
- return ;
128
- }
129
-
130
115
/**
131
116
* This is a hack to set the `isMobile` property to true so that we can test the MobileController
132
117
*/
133
118
el . isMobile . matches = true ;
134
119
el . bindEvents ( ) ;
135
120
136
- /**
137
- * While we can set the view port, but not `(hover: none) and (pointer: coarse)`
138
- * which prevents us from testing this at unit time. Hopefully there will be
139
- * a future version of Playwright and/or @web/test-runner that does allow this.
140
- * See: https://github.com/microsoft/playwright/issues/11781
141
- **/
142
- await setViewport ( { width : 360 , height : 640 } ) ;
143
- // Allow viewport update to propagate.
144
- await nextFrame ( ) ;
145
-
146
- const opened = oneEvent ( el , 'sp-opened' ) ;
147
-
148
- const boundingRect = el . button . getBoundingClientRect ( ) ;
149
- sendMouse ( {
150
- steps : [
151
- {
152
- type : 'click' ,
153
- position : [
154
- boundingRect . x + boundingRect . width / 2 ,
155
- boundingRect . y + boundingRect . height / 2 ,
156
- ] ,
157
- } ,
158
- ] ,
159
- } ) ;
160
- await elementUpdated ( el ) ;
121
+ el . open = true ;
161
122
162
- await opened ;
123
+ // in this test we only need to wait to see if a popover opens
124
+ let popover : Popover | null = null ;
125
+ await waitUntil (
126
+ ( ) => {
127
+ popover = el . shadowRoot . querySelector (
128
+ 'sp-popover'
129
+ ) as Popover ;
130
+ return ! ! popover && popover . open ;
131
+ } ,
132
+ `popover appeared (el.open: ${ el . open } )` ,
133
+ { timeout : 300 }
134
+ ) ;
163
135
164
136
const tray = el . shadowRoot . querySelector ( 'sp-tray' ) ;
165
- const popover = el . shadowRoot . querySelector ( 'sp-popover' ) ;
166
137
167
138
expect ( tray ) . to . be . null ;
168
139
expect ( popover ) . to . not . be . null ;
169
140
} ) ;
170
141
171
142
it ( 'is a Popover in desktop' , async ( ) => {
172
- await setViewport ( { width : 701 , height : 640 } ) ;
173
- // Allow viewport update to propagate.
174
- await nextFrame ( ) ;
175
- await nextFrame ( ) ;
176
143
177
- const opened = oneEvent ( el , 'sp-opened' ) ;
178
144
el . open = true ;
179
- await opened ;
180
145
181
- const popover = el . shadowRoot . querySelector ( 'sp-popover' ) ;
146
+ // in this test we only need to wait to see if a popover opens
147
+ let popover : Popover | null = null ;
148
+ await waitUntil (
149
+ ( ) => {
150
+ popover = el . shadowRoot . querySelector (
151
+ 'sp-popover'
152
+ ) as Popover ;
153
+ return ! ! popover && popover . open ;
154
+ } ,
155
+ `popover appeared (el.open: ${ el . open } )` ,
156
+ { timeout : 300 }
157
+ ) ;
158
+
182
159
const tray = el . shadowRoot . querySelector ( 'sp-tray' ) ;
183
160
184
161
expect ( popover ) . to . not . be . null ;
0 commit comments