Skip to content

Commit

Permalink
Try fixing E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Oct 28, 2021
1 parent 88a1fd9 commit 8836b54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 55 deletions.
20 changes: 17 additions & 3 deletions tests/e2e/specs/admin/amp-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ describe( 'Settings screen when reader theme is active theme', () => {
} );

describe( 'Mode info notices', () => {
it( 'show information in the Template Mode section if site scan results are stale', async () => {
const timeout = 10000;

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

afterEach( async () => {
await cleanUpSettings();
} );

it( 'show information in the Template Mode section if site scan results are stale', async () => {
// Trigger a site scan.
await page.waitForSelector( '#site-scan' );

Expand All @@ -77,16 +85,22 @@ describe( 'Mode info notices', () => {
}

await scrollToElement( { selector: '#site-scan .settings-site-scan__footer .is-primary', click: true } );
await expect( page ).toMatchElement( '#site-scan .settings-site-scan__footer .is-primary', { text: 'Rescan Site', timeout: 10000 } );
await expect( page ).toMatchElement( '#site-scan .settings-site-scan__footer .is-primary', { text: 'Rescan Site', timeout } );

await scrollToElement( { selector: '#template-modes' } );

// Confirm there is no notice about stale results.
const noticeXpath = '//*[@id="template-modes"]/*[contains(@class, "amp-notice--info")]/*[contains(text(), "Site Scan results are stale")]';

const noticeBefore = await page.$x( noticeXpath );
expect( noticeBefore ).toHaveLength( 0 );

// Change template mode to make the scan results stale.
await setTemplateMode( 'transitional' );
await page.waitForSelector( '.settings-site-scan__footer .is-primary', { timeout: 10000 } );

await page.waitForSelector( '.settings-site-scan__footer .is-primary', { timeout } );

await scrollToElement( { selector: '#template-modes' } );

const noticeAfter = await page.$x( noticeXpath );
expect( noticeAfter ).toHaveLength( 1 );
Expand Down
52 changes: 0 additions & 52 deletions tests/e2e/specs/amp-onboarding/done.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { trashAllPosts, visitAdminPage } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -34,43 +29,6 @@ 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 Expand Up @@ -119,14 +77,4 @@ describe( 'Done', () => {
await expect( page ).toMatchElement( 'p', { text: /Reader mode/i } );
await expect( page ).toMatchElement( '.done__preview-container input[type="checkbox"]' );
} );

it( 'does not render site preview in reader mode if there are no posts and pages', async () => {
await trashAllPosts();
await trashAllPosts( 'page' );

await moveToDoneScreen( { mode: 'reader' } );

await expect( page ).toMatchElement( 'h1', { text: 'Done' } );
await expect( page ).not.toMatchElement( '.done__preview-iframe' );
} );
} );

0 comments on commit 8836b54

Please sign in to comment.