Skip to content

Commit

Permalink
Merge branch 'master' into bug/1700-manifest-autload.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Aug 27, 2020
2 parents 4fedc52 + 3fc03d8 commit 1969b76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- name: E2E Tests (WordPress nightly)
env: E2E=1 WP_VERSION=nightly
- name: E2E Tests (WordPress 4.7)
env: E2E=1 WP_VERSION=4.7.13
env: E2E=1 WP_VERSION=4.7.13 AMP_VERSION=1.5.5
- name: E2E Tests (WordPress 4.9, Gutenberg 4.9)
env: E2E=1 WP_VERSION=4.9.10 GUTENBERG_VERSION=4.9.0

Expand Down
8 changes: 7 additions & 1 deletion bin/local-env/install-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ fi

# Install the AMP plugin
status_message "Installing the AMP plugin..."
wp plugin install amp --force --quiet
if [[ ! -z "$AMP_VERSION" ]]; then
wp plugin install amp --force --quiet --version="$AMP_VERSION"
else
# Install latest 2.x by default, but not v3
wp plugin install amp --force --quiet --version="2.0.0"
wp plugin update amp --minor --quiet
fi

# Install a dummy favicon to avoid 404 errors.
status_message "Installing a dummy favicon..."
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/matchers/to-have-valid-amp-for-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export async function toHaveValidAMPForUser( path ) {
const html = await fetchPageContent( urlToFetch );
const jsDoc = new JSDOM( html ).window.document;
try {
expect( jsDoc.querySelector( '#amp-admin-bar-item-status-icon' ).textContent ).toMatch( '✅' );
const iconElement = jsDoc.querySelector( '#amp-admin-bar-item-status-icon' );
// AMP v2 uses an amp-icon class, as well as additional classes for validity.
if ( iconElement.classList.contains( 'amp-icon' ) ) {
expect( iconElement.classList.contains( 'amp-valid' ) ).toBe( true );
} else { // AMP v1
expect( iconElement.textContent ).toMatch( '✅' );
}
pass = true;
message = () => 'Expected logged-in user not to have valid AMP';
} catch ( error ) {
Expand Down
26 changes: 25 additions & 1 deletion tests/e2e/utils/activate-amp-and-set-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
import { activatePlugin, visitAdminPage } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { wpApiFetch } from './';

/**
* The allow list of AMP modes.
*/
Expand Down Expand Up @@ -50,9 +55,28 @@ export const activateAMPWithMode = async ( mode ) => {
export const setAMPMode = async ( mode ) => {
// Test to be sure that the passed mode is known.
expect( allowedAMPModes ).toHaveProperty( mode );
const ampMode = allowedAMPModes[ mode ];
// Set the AMP mode
await visitAdminPage( 'admin.php', 'page=amp-options' );
await expect( page ).toClick( `#theme_support_${ allowedAMPModes[ mode ] }` );

// AMP v2
const optionsRESTPath = await page.evaluate( () => window.ampSettings && window.ampSettings.OPTIONS_REST_PATH );
if ( optionsRESTPath ) {
await Promise.all( [
page.waitForResponse( ( res ) => res.url().match( optionsRESTPath ) ),
wpApiFetch( {
method: 'post',
path: optionsRESTPath,
data: {
theme_support: ampMode,
},
} ),
] );
return;
}

// AMP v1
await expect( page ).toClick( `#theme_support_${ ampMode }` );
await expect( page ).toClick( '#submit' );
await page.waitForNavigation();
};

0 comments on commit 1969b76

Please sign in to comment.