@@ -144,7 +144,7 @@ describe( 'Widgets screen', () => {
144144 role : 'group' ,
145145 name : 'Block: Widget Area' ,
146146 } ) ;
147- const [ firstWidgetArea ] = widgetAreas ;
147+ const [ firstWidgetArea , secondWidgetArea ] = widgetAreas ;
148148
149149 let addParagraphBlock = await getBlockInGlobalInserter ( 'Paragraph' ) ;
150150 await addParagraphBlock . hover ( ) ;
@@ -202,32 +202,17 @@ describe( 'Widgets screen', () => {
202202 '[video src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"]'
203203 ) ;
204204
205- /**
206- * FIXME: There seems to have a bug when saving the widgets
207- */
208- // await secondWidgetArea.click();
209-
210- // addParagraphBlock = await getParagraphBlockInGlobalInserter();
211- // await addParagraphBlock.hover();
212-
213- // // FIXME: The insertion point indicator is not showing when the widget area has no blocks.
214- // // await expectInsertionPointIndicatorToBeBelowLastBlock(
215- // // secondWidgetArea
216- // // );
217-
218- // await addParagraphBlock.click();
205+ // Add to the second widget area.
206+ await secondWidgetArea . click ( ) ;
219207
220- // const addedParagraphBlockInSecondWidgetArea = await secondWidgetArea.$(
221- // '[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
222- // );
223-
224- // expect(
225- // await addedParagraphBlockInSecondWidgetArea.evaluate(
226- // ( node ) => node === document.activeElement
227- // )
228- // ).toBe( true );
208+ addParagraphBlock = await getBlockInGlobalInserter ( 'Paragraph' ) ;
209+ await addParagraphBlock . click ( ) ;
229210
230- // await page.keyboard.type( 'Third Paragraph' );
211+ const addedParagraphBlockInSecondWidgetArea = await secondWidgetArea . $ (
212+ '[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
213+ ) ;
214+ await addedParagraphBlockInSecondWidgetArea . focus ( ) ;
215+ await page . keyboard . type ( 'Third Paragraph' ) ;
231216
232217 await saveWidgets ( ) ;
233218
@@ -247,6 +232,9 @@ describe( 'Widgets screen', () => {
247232 </div></div>
248233 <div class=\\"widget widget_block\\"><div class=\\"widget-content\\"><p><div style=\\"width: 580px;\\" class=\\"wp-video\\"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
249234 <video class=\\"wp-video-shortcode\\" id=\\"video-0-1\\" width=\\"580\\" height=\\"326\\" preload=\\"metadata\\" controls=\\"controls\\"><source type=\\"video/mp4\\" src=\\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4?_=1\\" /><a href=\\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\\">http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4</a></video></div></p>
235+ </div></div>",
236+ "sidebar-2": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
237+ <p>Third Paragraph</p>
250238 </div></div>",
251239 }
252240 ` ) ;
@@ -345,10 +333,10 @@ describe( 'Widgets screen', () => {
345333 } ) ;
346334 await inlineInserterButton . click ( ) ;
347335
348- // TODO: Convert to find() API from puppeteer-testing-library.
349- const inserterSearchBox = await page . waitForSelector (
350- 'aria/ Search for blocks and patterns[role="searchbox"]'
351- ) ;
336+ const inserterSearchBox = await find ( {
337+ role : 'searchbox' ,
338+ name : ' Search for blocks and patterns' ,
339+ } ) ;
352340 await expect ( inserterSearchBox ) . toHaveFocus ( ) ;
353341
354342 await page . keyboard . type ( 'Heading' ) ;
@@ -473,19 +461,19 @@ describe( 'Widgets screen', () => {
473461
474462 let editedSerializedWidgetAreas = await getSerializedWidgetAreas ( ) ;
475463 await expect ( editedSerializedWidgetAreas ) . toMatchInlineSnapshot ( `
476- Object {
477- "sidebar-1": "<marquee>Howdy</marquee>",
478- }
479- ` ) ;
464+ Object {
465+ "sidebar-1": "<marquee>Howdy</marquee>",
466+ }
467+ ` ) ;
480468
481469 await page . reload ( ) ;
482470
483471 editedSerializedWidgetAreas = await getSerializedWidgetAreas ( ) ;
484472 await expect ( editedSerializedWidgetAreas ) . toMatchInlineSnapshot ( `
485- Object {
486- "sidebar-1": "<marquee>Howdy</marquee>",
487- }
488- ` ) ;
473+ Object {
474+ "sidebar-1": "<marquee>Howdy</marquee>",
475+ }
476+ ` ) ;
489477
490478 await addMarquee ( 2 ) ;
491479
@@ -506,10 +494,10 @@ describe( 'Widgets screen', () => {
506494 await saveWidgets ( ) ;
507495 editedSerializedWidgetAreas = await getSerializedWidgetAreas ( ) ;
508496 await expect ( editedSerializedWidgetAreas ) . toMatchInlineSnapshot ( `
509- Object {
510- "sidebar-1": "<marquee>Howdy</marquee>",
511- }
512- ` ) ;
497+ Object {
498+ "sidebar-1": "<marquee>Howdy</marquee>",
499+ }
500+ ` ) ;
513501
514502 await page . reload ( ) ;
515503 const marqueesAfter = await findAll ( {
@@ -519,28 +507,32 @@ describe( 'Widgets screen', () => {
519507 } ) ;
520508 } ) ;
521509
522- // Disable reason: We temporary skip this test until we can figure out why it fails sometimes.
523- // eslint-disable-next-line jest/no-disabled-tests
524- it . skip ( 'Should duplicate the widgets' , async ( ) => {
525- let firstWidgetArea = await page . $ (
526- '[aria-label="Block: Widget Area"][role="group"]'
527- ) ;
510+ it ( 'Should duplicate the widgets' , async ( ) => {
511+ let [ firstWidgetArea ] = await findAll ( {
512+ role : 'group' ,
513+ name : 'Block: Widget Area' ,
514+ } ) ;
528515
529516 const addParagraphBlock = await getBlockInGlobalInserter ( 'Paragraph' ) ;
530517 await addParagraphBlock . click ( ) ;
531518
532- let firstParagraphBlock = await firstWidgetArea . $ (
533- '[data-block][data-type="core/paragraph"][aria-label^="Empty block"]'
519+ let firstParagraphBlock = await find (
520+ {
521+ role : 'group' ,
522+ name : / ^ E m p t y b l o c k / ,
523+ } ,
524+ { root : firstWidgetArea }
534525 ) ;
535526 await firstParagraphBlock . focus ( ) ;
536527 await page . keyboard . type ( 'First Paragraph' ) ;
537528
538529 await saveWidgets ( ) ;
539530 await page . reload ( ) ;
540531 // Wait for the widget areas to load.
541- firstWidgetArea = await page . waitForSelector (
542- '[aria-label="Block: Widget Area"][role="group"]'
543- ) ;
532+ [ firstWidgetArea ] = await findAll ( {
533+ role : 'group' ,
534+ name : 'Block: Widget Area' ,
535+ } ) ;
544536
545537 const initialSerializedWidgetAreas = await getSerializedWidgetAreas ( ) ;
546538 expect ( initialSerializedWidgetAreas ) . toMatchInlineSnapshot ( `
@@ -559,21 +551,11 @@ describe( 'Widgets screen', () => {
559551 await firstParagraphBlock . focus ( ) ;
560552
561553 await showBlockToolbar ( ) ;
562-
563- const blockToolbar = await page . waitForSelector (
564- '[role="toolbar"][aria-label="Block tools"]'
565- ) ;
566- const moreOptionsButton = await blockToolbar . $ (
567- 'button[aria-label="Options"]'
568- ) ;
569- await moreOptionsButton . click ( ) ;
570-
571- const optionsMenu = await page . waitForSelector (
572- '[role="menu"][aria-label="Options"]'
573- ) ;
574- const [ duplicateButton ] = await optionsMenu . $x (
575- '//*[@role="menuitem"][*[text()="Duplicate"]]'
576- ) ;
554+ await clickBlockToolbarButton ( 'Options' ) ;
555+ const duplicateButton = await find ( {
556+ role : 'menuitem' ,
557+ name : / ^ D u p l i c a t e / ,
558+ } ) ;
577559 await duplicateButton . click ( ) ;
578560
579561 await page . waitForFunction (
@@ -597,16 +579,10 @@ describe( 'Widgets screen', () => {
597579 expect ( firstParagraphBlockClientId ) . not . toBe (
598580 duplicatedParagraphBlockClientId
599581 ) ;
600- expect (
601- await duplicatedParagraphBlock . evaluate (
602- ( node ) => node . textContent
603- )
604- ) . toBe ( 'First Paragraph' ) ;
605- expect (
606- await duplicatedParagraphBlock . evaluate (
607- ( node ) => node === document . activeElement
608- )
609- ) . toBe ( true ) ;
582+ await expect ( duplicatedParagraphBlock ) . toMatchQuery ( {
583+ text : 'First Paragraph' ,
584+ } ) ;
585+ await expect ( duplicatedParagraphBlock ) . toHaveFocus ( ) ;
610586
611587 await saveWidgets ( ) ;
612588 const editedSerializedWidgetAreas = await getSerializedWidgetAreas ( ) ;
0 commit comments