Skip to content

Commit

Permalink
Reorganize e2e tests folders and files (#36734)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <ntsekouras@outlook.com>
  • Loading branch information
youknowriad and ntsekouras committed Nov 29, 2021
1 parent ebff4e2 commit 3adf577
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 44 deletions.
1 change: 1 addition & 0 deletions packages/e2e-tests/jest.config.js
Expand Up @@ -5,6 +5,7 @@ const baseConfig = require( '@wordpress/scripts/config/jest-e2e.config' );

module.exports = {
...baseConfig,
testMatch: [ '<rootDir>/specs/**/*.test.js' ],
setupFiles: [ '<rootDir>/config/gutenberg-phase.js' ],
setupFilesAfterEnv: [
'<rootDir>/config/setup-test-framework.js',
Expand Down
39 changes: 39 additions & 0 deletions packages/e2e-tests/specs/experiments/experimental-features.js
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';
import { visitAdminPage } from '@wordpress/e2e-test-utils';

async function setExperimentalFeaturesState( features, enable ) {
const query = addQueryArgs( '', {
page: 'gutenberg-experiments',
} );
await visitAdminPage( '/admin.php', query );

await Promise.all(
features.map( async ( feature ) => {
await page.waitForSelector( feature );
const checkedSelector = `${ feature }[checked=checked]`;
const isChecked = !! ( await page.$( checkedSelector ) );
if ( ( ! isChecked && enable ) || ( isChecked && ! enable ) ) {
await page.click( feature );
}
} )
);
await Promise.all( [
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
page.click( '#submit' ),
] );
}

/**
* Establishes test lifecycle to enable experimental feature for the duration of
* the grouped test block.
*
* @param {Array} features Array of {string} selectors of settings to enable.
* Assumes they can be enabled with one click.
*/
export function useExperimentalFeatures( features ) {
beforeAll( () => setExperimentalFeaturesState( features, true ) );
afterAll( () => setExperimentalFeaturesState( features, false ) );
}
Expand Up @@ -22,7 +22,7 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import { useExperimentalFeatures } from '../../experimental-features';
import { useExperimentalFeatures } from './experimental-features';
import menuItemsFixture from './fixtures/menu-items-request-fixture.json';

const TYPE_NAMES = {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/performance/site-editor.test.js
Expand Up @@ -19,7 +19,7 @@ import {
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from '../site-editor/utils';
import {
readFile,
deleteFile,
Expand Down
Expand Up @@ -6,7 +6,7 @@ import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

async function getDocumentSettingsTitle() {
const titleElement = await page.waitForSelector(
Expand Down
Expand Up @@ -16,7 +16,7 @@ import {
/**
* Internal dependencies
*/
import { navigationPanel, siteEditor } from '../../experimental-features';
import { navigationPanel, siteEditor } from './utils';

const clickTemplateItem = async ( menus, itemName ) => {
await navigationPanel.open();
Expand Down
Expand Up @@ -14,7 +14,7 @@ import {
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

describe( 'Multi-entity save flow', () => {
// Selectors - usable between Post/Site editors.
Expand Down
Expand Up @@ -12,7 +12,7 @@ import {
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

async function toggleSidebar() {
await page.click(
Expand Down
Expand Up @@ -13,7 +13,7 @@ import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

async function waitForFileExists( filePath, timeout = 10000 ) {
const start = Date.now();
Expand Down
Expand Up @@ -6,7 +6,7 @@ import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

describe( 'Site Editor Inserter', () => {
beforeAll( async () => {
Expand Down
Expand Up @@ -16,7 +16,7 @@ import {
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

const templatePartNameInput =
'.edit-site-create-template-part-modal .components-text-control__input';
Expand Down
Expand Up @@ -14,7 +14,7 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';
import { siteEditor } from './utils';

const {
visit: visitSiteEditor,
Expand Down
Expand Up @@ -4,40 +4,6 @@
import { addQueryArgs } from '@wordpress/url';
import { visitAdminPage } from '@wordpress/e2e-test-utils';

async function setExperimentalFeaturesState( features, enable ) {
const query = addQueryArgs( '', {
page: 'gutenberg-experiments',
} );
await visitAdminPage( '/admin.php', query );

await Promise.all(
features.map( async ( feature ) => {
await page.waitForSelector( feature );
const checkedSelector = `${ feature }[checked=checked]`;
const isChecked = !! ( await page.$( checkedSelector ) );
if ( ( ! isChecked && enable ) || ( isChecked && ! enable ) ) {
await page.click( feature );
}
} )
);
await Promise.all( [
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
page.click( '#submit' ),
] );
}

/**
* Establishes test lifecycle to enable experimental feature for the duration of
* the grouped test block.
*
* @param {Array} features Array of {string} selectors of settings to enable.
* Assumes they can be enabled with one click.
*/
export function useExperimentalFeatures( features ) {
beforeAll( () => setExperimentalFeaturesState( features, true ) );
afterAll( () => setExperimentalFeaturesState( features, false ) );
}

export const navigationPanel = {
async open() {
const isOpen = !! ( await page.$(
Expand Down

0 comments on commit 3adf577

Please sign in to comment.