Skip to content

Commit

Permalink
Testing: Verify saveability, non-dirtiness of initial edits
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Nov 6, 2018
1 parent ddf6f11 commit 3cb31b6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
12 changes: 11 additions & 1 deletion test/e2e/specs/change-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,17 @@ describe( 'Change detection', () => {
await assertIsDirty( true );
} );

it( 'Should not prompt to confirm unsaved changes', async () => {
it( 'Should not prompt to confirm unsaved changes for new post', async () => {
await assertIsDirty( false );
} );

it( 'Should not prompt to confirm unsaved changes for new post with initial edits', async () => {
await newPost( {
title: 'My New Post',
content: 'My content',
excerpt: 'My excerpt',
} );

await assertIsDirty( false );
} );

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/specs/new-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ describe( 'new editor state', () => {
// focused by default when a post already has a title.
expect( activeElementTagName ).toEqual( 'body' );
} );

it( 'should be saveable with sufficient initial edits', async () => {
await newPost( { title: 'Here is the title' } );

// Verify saveable by presence of the Save Draft button.
await page.$( 'button.editor-post-save-draft' );
} );
} );
23 changes: 20 additions & 3 deletions test/e2e/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import { URL } from 'url';
* External dependencies
*/
import { times, castArray } from 'lodash';
import fetch from 'node-fetch';

/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

const {
WP_BASE_URL = 'http://localhost:8889',
WP_USERNAME = 'admin',
WP_PASSWORD = 'password',
} = process.env;
import fetch from 'node-fetch';

/**
* Platform-specific meta key.
Expand Down Expand Up @@ -96,8 +101,20 @@ export async function visitAdmin( adminPath, query ) {
}
}

export async function newPost( { postType, enableTips = false } = {} ) {
await visitAdmin( 'post-new.php', postType ? 'post_type=' + postType : '' );
export async function newPost( {
postType,
title,
content,
excerpt,
enableTips = false,
} = {} ) {
const query = addQueryArgs( '', {
post_type: postType,
post_title: title,
content,
excerpt,
} ).slice( 1 );
await visitAdmin( 'post-new.php', query );

await page.evaluate( ( _enableTips ) => {
const action = _enableTips ? 'enableTips' : 'disableTips';
Expand Down

0 comments on commit 3cb31b6

Please sign in to comment.