Skip to content

Commit

Permalink
Refactor code to avoid duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 17, 2018
1 parent 78ebeec commit 87b372d
Showing 1 changed file with 30 additions and 67 deletions.
97 changes: 30 additions & 67 deletions test/e2e/specs/publishing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,85 +9,48 @@ import {
} from '../support/utils';

describe( 'Publishing', () => {
describe( 'a post', () => {
beforeEach( async () => {
await newPost();
} );

it( 'should publish a post and close the panel once we start editing again', async () => {
await page.type( '.editor-post-title__input', 'E2E Test Post' );

await publishPost();

// The post-publishing panel is visible.
expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull();

// Start editing again.
await page.type( '.editor-post-title__input', ' (Updated)' );
[ 'post', 'page' ].forEach( ( postType ) => {
describe( `a ${ postType }`, () => {
beforeEach( async () => {
await newPost( postType );
} );

// The post-publishing panel is not visible anymore.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );
it( `should publish the ${ postType } and close the panel once we start editing again.`, async () => {
await page.type( '.editor-post-title__input', 'E2E Test Post' );

describe( 'a post when pre-publish checks are disabled', () => {
beforeEach( async () => {
await newPost();
await disablePrePublishChecks();
} );
await publishPost();

it( 'should publish it without opening the post-publish sidebar.', async () => {
await page.type( '.editor-post-title__input', 'E2E Test Post' );
// The post-publishing panel is visible.
expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull();

// The "Publish" button should be shown instead of the "Publish..." toggle
expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull();
expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull();
// Start editing again.
await page.type( '.editor-post-title__input', ' (Updated)' );

await publishPostWithoutPrePublishChecks();

// The post-publishing panel should have been not shown.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
// The post-publishing panel is not visible anymore.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );
} );

describe( 'a page', () => {
beforeEach( async () => {
await newPost( 'page' );
} );

it( 'should publish a page and close the panel once we start editing again', async () => {
await page.type( '.editor-post-title__input', 'E2E Test Page' );

await publishPost();

// The post-publishing panel is visible.
expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull();

// Start editing the page again.
await page.type( '.editor-post-title__input', ' (Updated)' );

// The post-publishing panel is not visible anymore.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );

describe( 'a page when pre-publish checks are disabled', () => {
beforeEach( async () => {
await newPost( 'page' );
await disablePrePublishChecks();
} );
[ 'post', 'page' ].forEach( ( postType ) => {
describe( `a ${ postType } with pre-publish checks disabled`, () => {
beforeEach( async () => {
await newPost( postType );
await disablePrePublishChecks();
} );

it( 'should publish it without opening the post-publish sidebar', async () => {
await page.type( '.editor-post-title__input', 'E2E Test Page' );
it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => {
await page.type( '.editor-post-title__input', 'E2E Test Post' );

// The "Publish" button should be shown instead of the "Publish..." toggle
expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull();
expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull();
// The "Publish" button should be shown instead of the "Publish..." toggle
expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull();
expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull();

await publishPostWithoutPrePublishChecks();
await publishPostWithoutPrePublishChecks();

// The post-publishing panel should have been not shown.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
// The post-publishing panel should have been not shown.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
} );
} );
} );
} );

0 comments on commit 87b372d

Please sign in to comment.