Skip to content

Commit

Permalink
Updated e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Dec 4, 2019
1 parent f0b892e commit 00b9f49
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/e2e-tests/specs/editor/various/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ async function openPreviewPage( editorPage ) {
let openTabs = await browser.pages();
const expectedTabsCount = openTabs.length + 1;
await editorPage.click( '.editor-post-preview' );
await editorPage.waitForSelector( '.editor-block-preview__new-tab' );
await editorPage.click( '.editor-block-preview__new-tab' );

// Wait for the new tab to open.
while ( openTabs.length < expectedTabsCount ) {
Expand All @@ -31,9 +33,7 @@ async function openPreviewPage( editorPage ) {
}

const previewPage = last( openTabs );
// Wait for the preview to load. We can't do interstitial detection here,
// because it might load too quickly for us to pick up, so we wait for
// the preview to load by waiting for the title to appear.
// Wait for the preview to load by waiting for the title to appear.
await previewPage.waitForSelector( '.entry-title' );
return previewPage;
}
Expand All @@ -48,6 +48,8 @@ async function openPreviewPage( editorPage ) {
*/
async function waitForPreviewNavigation( previewPage ) {
await page.click( '.editor-post-preview' );
await page.waitForSelector( '.editor-block-preview__new-tab' );
await page.click( '.editor-block-preview__new-tab' );
return previewPage.waitForNavigation();
}

Expand Down Expand Up @@ -117,6 +119,7 @@ describe( 'Preview', () => {

// Return to editor to change title.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
await editorPage.type( '.editor-post-title__input', '!' );
await waitForPreviewNavigation( previewPage );

Expand All @@ -127,12 +130,14 @@ describe( 'Preview', () => {
// Pressing preview without changes should bring same preview window to
// front and reload, but should not show interstitial.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
await waitForPreviewNavigation( previewPage );
previewTitle = await previewPage.$eval( '.entry-title', ( node ) => node.textContent );
expect( previewTitle ).toBe( 'Hello World!' );

// Preview for published post (no unsaved changes) directs to canonical URL for post.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
await publishPost();

// Return to editor to change title.
Expand All @@ -156,6 +161,7 @@ describe( 'Preview', () => {
//
// See: https://github.com/WordPress/gutenberg/issues/7561
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
await waitForPreviewNavigation( previewPage );

// Title in preview should match updated input.
Expand Down Expand Up @@ -185,6 +191,7 @@ describe( 'Preview', () => {

// Return to editor.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );

// Append bbbbb to the title, and tab away from the title so blur event is triggered.
await editorPage.type( '.editor-post-title__input', 'bbbbb' );
Expand Down Expand Up @@ -238,6 +245,7 @@ describe( 'Preview with Custom Fields enabled', () => {

// Return to editor and modify the title and content.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
await editorPage.click( '.editor-post-title__input' );
await pressKeyWithModifier( 'primary', 'a' );
await editorPage.keyboard.press( 'Delete' );
Expand All @@ -258,5 +266,6 @@ describe( 'Preview with Custom Fields enabled', () => {

// Make sure the editor is active for the afterEach function.
await editorPage.bringToFront();
await editorPage.click( '[aria-label="Close dialog"' );
} );
} );

0 comments on commit 00b9f49

Please sign in to comment.