Skip to content

Commit

Permalink
Create test post and page using REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Oct 21, 2021
1 parent fce116d commit 8f2985a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
41 changes: 41 additions & 0 deletions tests/e2e/specs/amp-onboarding/done.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* WordPress dependencies
*/
import { trashAllPosts, visitAdminPage } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -29,6 +33,43 @@ async function testCommonDoneStepElements() {
}

describe( 'Done', () => {
let testPost;
let testPage;

beforeAll( async () => {
await visitAdminPage( 'admin.php', 'page=amp-options' );

testPost = await page.evaluate( () => wp.apiFetch( {
path: '/wp/v2/posts',
method: 'POST',
data: { title: 'Test Post', status: 'publish' },
} ) );
testPage = await page.evaluate( () => wp.apiFetch( {
path: '/wp/v2/pages',
method: 'POST',
data: { title: 'Test Page', status: 'publish' },
} ) );
} );

afterAll( async () => {
await visitAdminPage( 'admin.php', 'page=amp-options' );

if ( testPost.id ) {
await page.evaluate( ( id ) => wp.apiFetch( {
path: `/wp/v2/posts/${ id }`,
method: 'DELETE',
data: { force: true },
} ), testPost.id );
}
if ( testPage.id ) {
await page.evaluate( ( id ) => wp.apiFetch( {
path: `/wp/v2/pages/${ id }`,
method: 'DELETE',
data: { force: true },
} ), testPage.id );
}
} );

afterEach( async () => {
await cleanUpSettings();
} );
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/utils/onboarding-wizard-utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/**
* WordPress dependencies
*/
import { createNewPost, visitAdminPage } from '@wordpress/e2e-test-utils';
import { visitAdminPage } from '@wordpress/e2e-test-utils';

export const NEXT_BUTTON_SELECTOR = '#next-button';
export const PREV_BUTTON_SELECTOR = '.amp-settings-nav__prev-next button:not(.is-primary)';

export async function goToOnboardingWizard() {
await visitAdminPage( 'index.php' );
await expect( page ).not.toMatchElement( '#amp-onboarding-wizard' );
await createNewPost(); // So that there is a post to appear on the done screen.
await visitAdminPage( 'admin.php', 'page=amp-onboarding-wizard' );
await expect( page ).toMatchElement( '#amp-onboarding-wizard' );
}
Expand Down

0 comments on commit 8f2985a

Please sign in to comment.