Skip to content

Commit

Permalink
Try fixing e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 3, 2020
1 parent 43ab9de commit dad3772
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 52 deletions.
12 changes: 12 additions & 0 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,18 @@ _Parameters_

- _name_ `string`: Block name.

<a name="trashAllPosts" href="#trashAllPosts">#</a> **trashAllPosts**

Navigates to the post listing screen and bulk-trashes any posts which exist.

_Parameters_

- _postType_ `string`: String slug for type of post to trash.

_Returns_

- `Promise`: Promise resolving once posts have been trashed.

<a name="uninstallPlugin" href="#uninstallPlugin">#</a> **uninstallPlugin**

Uninstalls a plugin.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export {
} from './observe-focus-loss';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
export { openPublishPanel } from './open-publish-panel';
export { trashAllPosts } from './posts';
export { pressKeyTimes } from './press-key-times';
export { pressKeyWithModifier } from './press-key-with-modifier';
export { publishPost } from './publish-post';
Expand Down
45 changes: 45 additions & 0 deletions packages/e2e-test-utils/src/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { switchUserToAdmin } from './switch-user-to-admin';
import { switchUserToTest } from './switch-user-to-test';
import { visitAdminPage } from './visit-admin-page';

/**
* Navigates to the post listing screen and bulk-trashes any posts which exist.
*
* @param {string} postType - String slug for type of post to trash.
*
* @return {Promise} Promise resolving once posts have been trashed.
*/
export async function trashAllPosts( postType = 'post' ) {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
const query = addQueryArgs( '', {
post_type: postType,
} ).slice( 1 );
await visitAdminPage( 'edit.php', query );

// If this selector doesn't exist there are no posts for us to delete.
const bulkSelector = await page.$( '#bulk-action-selector-top' );
if ( ! bulkSelector ) {
return;
}

// Select all posts.
await page.waitForSelector( '[id^=cb-select-all-]' );
await page.click( '[id^=cb-select-all-]' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
await page.click( '#doaction' );
await page.waitForXPath(
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
);
await switchUserToTest();
}
42 changes: 3 additions & 39 deletions packages/e2e-tests/config/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import {
enablePageDialogAccept,
isOfflineMode,
setBrowserViewport,
switchUserToAdmin,
switchUserToTest,
visitAdminPage,
trashAllPosts,
} from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
* Timeout, in seconds, that the test should be allowed to run.
Expand Down Expand Up @@ -67,40 +64,6 @@ async function setupBrowser() {
await setBrowserViewport( 'large' );
}

/**
* Navigates to the post listing screen and bulk-trashes any posts which exist.
*
* @param {string} postType - String slug for type of post to trash.
*
* @return {Promise} Promise resolving once posts have been trashed.
*/
export async function trashExistingPosts( postType = 'post' ) {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
const query = addQueryArgs( '', {
post_type: postType,
} ).slice( 1 );
await visitAdminPage( 'edit.php', query );

// If this selector doesn't exist there are no posts for us to delete.
const bulkSelector = await page.$( '#bulk-action-selector-top' );
if ( ! bulkSelector ) {
return;
}

// Select all posts.
await page.waitForSelector( '[id^=cb-select-all-]' );
await page.click( '[id^=cb-select-all-]' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
await page.click( '#doaction' );
await page.waitForXPath(
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
);
await switchUserToTest();
}

/**
* Adds an event listener to the page to handle additions of page event
* handlers, to assure that they are removed at test teardown.
Expand Down Expand Up @@ -289,7 +252,8 @@ beforeAll( async () => {
observeConsoleLogging();
await simulateAdverseConditions();

await trashExistingPosts();
await trashAllPosts();
await trashAllPosts( 'wp_block' );
await setupBrowser();
await activatePlugin( 'gutenberg-test-plugin-disables-the-css-animations' );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
pressKeyWithModifier,
searchForReusableBlock,
getEditedPostContent,
trashAllPosts,
} from '@wordpress/e2e-test-utils';

function waitForAndAcceptDialog() {
Expand All @@ -22,6 +23,10 @@ describe( 'Reusable blocks', () => {
await createNewPost();
} );

afterAll( async () => {
await trashAllPosts( 'wp_block' );
} );

beforeEach( async () => {
// Remove all blocks from the post so that we're working with a clean slate
await page.evaluate( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
visitAdminPage,
createNewPost,
publishPost,
trashAllPosts,
} from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { useExperimentalFeatures } from '../../experimental-features';
import { trashExistingPosts } from '../../config/setup-test-framework';

const visitSiteEditor = async () => {
const query = addQueryArgs( '', {
Expand Down Expand Up @@ -164,8 +164,8 @@ describe( 'Multi-entity editor states', () => {
] );

beforeAll( async () => {
await trashExistingPosts( 'wp_template' );
await trashExistingPosts( 'wp_template_part' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );

it( 'should not display any dirty entities when loading the site editor', async () => {
Expand Down Expand Up @@ -194,8 +194,8 @@ describe( 'Multi-entity editor states', () => {

describe( 'Multi-entity edit', () => {
beforeAll( async () => {
await trashExistingPosts( 'wp_template' );
await trashExistingPosts( 'wp_template_part' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await createNewPost( {
postType: 'wp_template',
title: kebabCase( templateName ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
insertBlock,
publishPost,
visitAdminPage,
trashAllPosts,
} from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { useExperimentalFeatures } from '../../experimental-features';
import { trashExistingPosts } from '../../config/setup-test-framework';

describe( 'Multi-entity save flow', () => {
// Selectors - usable between Post/Site editors.
Expand Down Expand Up @@ -58,8 +58,8 @@ describe( 'Multi-entity save flow', () => {
] );

beforeAll( async () => {
await trashExistingPosts( 'wp_template' );
await trashExistingPosts( 'wp_template_part' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );

describe( 'Post Editor', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/e2e-tests/specs/experiments/template-part.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
insertBlock,
disablePrePublishChecks,
visitAdminPage,
trashAllPosts,
} from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { useExperimentalFeatures } from '../../experimental-features';
import { trashExistingPosts } from '../../config/setup-test-framework';

describe( 'Template Part', () => {
useExperimentalFeatures( [
Expand All @@ -22,12 +22,12 @@ describe( 'Template Part', () => {
] );

beforeAll( async () => {
await trashExistingPosts( 'wp_template' );
await trashExistingPosts( 'wp_template_part' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );
afterAll( async () => {
await trashExistingPosts( 'wp_template' );
await trashExistingPosts( 'wp_template_part' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );

describe( 'Template part block', () => {
Expand Down

0 comments on commit dad3772

Please sign in to comment.