Skip to content

Commit

Permalink
Clean up Validated URLs index before some E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Nov 3, 2021
1 parent 1604886 commit 79a4ed3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
55 changes: 24 additions & 31 deletions tests/e2e/specs/admin/amp-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { visitAdminPage, activateTheme, installTheme } from '@wordpress/e2e-test
* Internal dependencies
*/
import { completeWizard, cleanUpSettings, clickMode, scrollToElement } from '../../utils/onboarding-wizard-utils';
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { cleanUpValidatedUrls, setTemplateMode } from '../../utils/amp-settings-utils';

describe( 'AMP settings screen newly activated', () => {
beforeEach( async () => {
Expand Down Expand Up @@ -64,10 +64,13 @@ describe( 'Settings screen when reader theme is active theme', () => {
} );

describe( 'Mode info notices', () => {
const timeout = 10000;
beforeAll( async () => {
await cleanUpSettings();
await cleanUpValidatedUrls();
await completeWizard( { technical: true, mode: 'transitional' } );
} );

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

Expand All @@ -76,34 +79,24 @@ describe( 'Mode info notices', () => {
} );

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

const isPanelCollapsed = await page.$eval( '#site-scan .components-panel__body-toggle', ( el ) => el.ariaExpanded === 'false' );
if ( isPanelCollapsed ) {
await scrollToElement( { selector: '#site-scan .components-panel__body-toggle', click: true } );
}

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 } );

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 } );

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

const noticeAfter = await page.$x( noticeXpath );
expect( noticeAfter ).toHaveLength( 1 );
await expect( page ).toMatchElement( 'h2', { text: 'Template Mode' } );

// When there are no site scan results, no notice in the Template Mode section should be displayed.
await expect( page ).toMatchElement( 'button', { text: 'Scan Site' } );
await expect( page ).not.toMatchElement( '#template-modes h2 + .amp-notice--info' );

// Scan the site.
await Promise.all( [
scrollToElement( { selector: '.settings-site-scan__footer .is-primary', click: true } ),
page.waitForSelector( '.settings-site-scan__status' ),
] );
await page.waitForSelector( '.settings-site-scan__footer .is-primary', { timeout: 30000 } );
await expect( page ).not.toMatchElement( '#template-modes h2 + .amp-notice--info' );

// Change the template mode to make the scan results stale and confirm the notice is displayed.
await setTemplateMode( 'standard' );
await page.waitForSelector( '.settings-site-scan__footer .is-primary', { timeout: 10000 } );
await expect( page ).toMatchElement( '#template-modes h2 + .amp-notice--info' );
} );

it.todo( 'shows expected notices for theme with built-in support' );
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/utils/amp-settings-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ export async function uninstallPlugin( slug ) {
await _uninstallPlugin( slug );
}
}

export async function cleanUpValidatedUrls() {
await switchUserToAdmin();
await visitAdminPage( 'edit.php', 'post_type=amp_validated_url' );
await page.waitForSelector( 'h1' );

const bulkSelector = await page.$( '#bulk-action-selector-top' );

if ( ! bulkSelector ) {
return;
}

await page.waitForSelector( '[id^=cb-select-all-]' );
await page.click( '[id^=cb-select-all-]' );

await page.select( '#bulk-action-selector-top', 'delete' );

await page.click( '#doaction' );
await page.waitForXPath( '//*[contains(@class, "updated notice")]/p[contains(text(), "forgotten")]' );
await switchUserToTest();
}

0 comments on commit 79a4ed3

Please sign in to comment.