From e3a0dd5c214c0ed55e5cbb1666ea242e5fdc22a1 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 5 Mar 2019 14:12:25 -0500 Subject: [PATCH] Testing: Leverage saveDraft for meta boxes save --- .../specs/plugins/meta-boxes.test.js | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/e2e-tests/specs/plugins/meta-boxes.test.js b/packages/e2e-tests/specs/plugins/meta-boxes.test.js index b2e7649f53b57b..0a21dfe20d9d72 100644 --- a/packages/e2e-tests/specs/plugins/meta-boxes.test.js +++ b/packages/e2e-tests/specs/plugins/meta-boxes.test.js @@ -9,11 +9,15 @@ import { insertBlock, openDocumentSettingsSidebar, publishPost, + saveDraft, } from '@wordpress/e2e-test-utils'; describe( 'Meta boxes', () => { beforeAll( async () => { await activatePlugin( 'gutenberg-test-plugin-meta-box' ); + } ); + + beforeEach( async () => { await createNewPost(); } ); @@ -29,23 +33,14 @@ describe( 'Meta boxes', () => { await page.type( '.editor-post-title__input', 'Hello Meta' ); expect( await page.$( '.editor-post-save-draft' ) ).not.toBe( null ); - await Promise.all( [ - // Transitions between three states "Saving..." -> "Saved" -> "Save - // Draft" (the button is always visible while meta are present). - page.waitForSelector( '.editor-post-saved-state.is-saving' ), - page.waitForSelector( '.editor-post-saved-state.is-saved' ), - page.waitForSelector( '.editor-post-save-draft' ), - - // Keyboard shortcut Ctrl+S save. - page.keyboard.down( 'Meta' ), - page.keyboard.press( 'S' ), - page.keyboard.up( 'Meta' ), - ] ); + await saveDraft(); + + // After saving, affirm that the button returns to Save Draft. + await page.waitForSelector( '.editor-post-save-draft' ); } ); it( 'Should render dynamic blocks when the meta box uses the excerpt for front end rendering', async () => { // Publish a post so there's something for the latest posts dynamic block to render. - await createNewPost(); await page.type( '.editor-post-title__input', 'A published post' ); await insertBlock( 'Paragraph' ); await page.keyboard.type( 'Hello there!' ); @@ -67,7 +62,6 @@ describe( 'Meta boxes', () => { } ); it( 'Should render the excerpt in meta based on post content if no explicit excerpt exists', async () => { - await createNewPost(); await insertBlock( 'Paragraph' ); await page.keyboard.type( 'Excerpt from content.' ); await page.type( '.editor-post-title__input', 'A published post' ); @@ -91,7 +85,6 @@ describe( 'Meta boxes', () => { } ); it( 'Should render the explicitly set excerpt in meta instead of the content based one', async () => { - await createNewPost(); await insertBlock( 'Paragraph' ); await page.keyboard.type( 'Excerpt from content.' ); await page.type( '.editor-post-title__input', 'A published post' );