@@ -142,4 +142,108 @@ export const ExperimentalSuites = freezeSuites([
142142 name: "default", // optional param to target non-default tests locally
143143 }, */
144144 } ,
145+ {
146+ name : "Responsive-Design" ,
147+ url : "experimental/responsive-design/dist/index.html" ,
148+ tags : [ "responsive-design" , "webcomponents" , "experimental" ] ,
149+ type : "async" ,
150+ async prepare ( page ) {
151+ await page . waitForElement ( "cooking-app" ) ;
152+ } ,
153+ tests : [
154+ new BenchmarkTestStep ( "LoadChatAndExpandRecipes" , async ( page ) => {
155+ const resumePreviousChatBtn = page . querySelector ( "#resume-previous-chat-btn" , [ "cooking-app" , "chat-window" ] ) ;
156+ resumePreviousChatBtn . click ( ) ;
157+ page . layout ( ) ;
158+
159+ const nextRestaurantBtn = page . querySelector ( "#next-restaurant-btn" , [ "cooking-app" , "information-window" ] ) ;
160+ const restaurantCards = page . querySelectorAll ( "restaurant-card" , [ "cooking-app" , "information-window" ] ) ;
161+ const numOfRestaurantCards = restaurantCards . length - 1 ;
162+ for ( let i = 0 ; i < numOfRestaurantCards ; i ++ ) {
163+ nextRestaurantBtn . click ( ) ;
164+ page . layout ( ) ;
165+ }
166+
167+ const showMoreBtn = page . querySelectorAll ( ".show-more-btn" , [ "cooking-app" , "main-content" , "recipe-grid" ] ) ;
168+ for ( const btn of showMoreBtn ) {
169+ btn . click ( ) ;
170+ page . layout ( ) ;
171+ }
172+ } ) ,
173+ new BenchmarkTestStep ( "ReduceWidthIn5Steps" , async ( page ) => {
174+ const widths = [ 768 , 704 , 640 , 560 , 480 ] ;
175+ const MATCH_MEDIA_QUERY_BREAKPOINT = 640 ;
176+
177+ // The matchMedia query is "(max-width: 640px)"
178+ // Starting from a width > 640px, we'll only get 1 event when crossing to <= 640px
179+ // This happens when the width changes from 704px to 640px
180+ const resizeWorkPromise = new Promise ( ( resolve ) => {
181+ page . addEventListener ( "resize-work-complete" , resolve , { once : true } ) ;
182+ } ) ;
183+
184+ for ( const width of widths ) {
185+ page . setWidth ( width ) ;
186+ page . layout ( ) ;
187+ if ( width === MATCH_MEDIA_QUERY_BREAKPOINT )
188+ await resizeWorkPromise ;
189+ }
190+
191+ await new Promise ( ( resolve ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( resolve ) ) ) ;
192+ } ) ,
193+ new BenchmarkTestStep ( "ScrollToChatAndSendMessages" , async ( page ) => {
194+ const cvWorkComplete = new Promise ( ( resolve ) => {
195+ page . addEventListener ( "video-grid-content-visibility-complete" , resolve , { once : true } ) ;
196+ } ) ;
197+
198+ const nextItemBtn = page . querySelector ( "#next-item-carousel-btn" , [ "cooking-app" , "main-content" , "recipe-carousel" ] ) ;
199+ const recipeCarouselItems = page . querySelectorAll ( ".carousel-item" , [ "cooking-app" , "main-content" , "recipe-carousel" ] ) ;
200+ const numOfCarouselItems = recipeCarouselItems . length - 3 ;
201+ for ( let i = 0 ; i < numOfCarouselItems ; i ++ ) {
202+ nextItemBtn . click ( ) ;
203+ page . layout ( ) ;
204+ }
205+
206+ // Collapse recipes
207+ const showMoreBtnCollapse = page . querySelectorAll ( ".show-more-btn" , [ "cooking-app" , "main-content" , "recipe-grid" ] ) ;
208+ for ( const btn of showMoreBtnCollapse ) {
209+ btn . click ( ) ;
210+ page . layout ( ) ;
211+ }
212+
213+ const chatWindow = page . querySelector ( "#chat-window" , [ "cooking-app" , "chat-window" ] ) ;
214+ chatWindow . scrollIntoView ( { behavior : "instant" } ) ;
215+ page . layout ( ) ;
216+
217+ const messagesToBeSent = [ "Please generate an image of Tomato Soup." , "Try again, but make the soup look thicker." , "Try again, but make the soup served in a rustic bowl and include a sprinkle of fresh herbs on top." ] ;
218+ const chatInput = page . querySelector ( "#chat-input" , [ "cooking-app" , "chat-window" ] ) ;
219+ for ( const message of messagesToBeSent ) {
220+ chatInput . setValue ( message ) ;
221+ chatInput . dispatchEvent ( "input" ) ;
222+ chatInput . enter ( "keydown" ) ;
223+ page . layout ( ) ;
224+ }
225+ await cvWorkComplete ;
226+ } ) ,
227+ new BenchmarkTestStep ( "IncreaseWidthIn5Steps" , async ( page ) => {
228+ const widths = [ 560 , 640 , 704 , 768 , 800 ] ;
229+ const MATCH_MEDIA_QUERY_BREAKPOINT = 704 ;
230+
231+ // The matchMedia query is "(max-width: 640px)"
232+ // Starting from a width <= 640px, we'll get 1 event when crossing back to > 640px.
233+ // This happens when the width changes from 640px to 704px.
234+ const resizeWorkPromise = new Promise ( ( resolve ) => {
235+ page . addEventListener ( "resize-work-complete" , resolve , { once : true } ) ;
236+ } ) ;
237+
238+ for ( const width of widths ) {
239+ page . setWidth ( width ) ;
240+ page . layout ( ) ;
241+ if ( width === MATCH_MEDIA_QUERY_BREAKPOINT )
242+ await resizeWorkPromise ;
243+ }
244+
245+ await new Promise ( ( resolve ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( resolve ) ) ) ;
246+ } ) ,
247+ ] ,
248+ } ,
145249] ) ;
0 commit comments