Skip to content

Commit

Permalink
Improve nav menu E2E tests by creating test menu before each test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Mar 9, 2022
1 parent 362f48f commit beba916
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 43 deletions.
33 changes: 0 additions & 33 deletions tests/e2e/config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { get } from 'lodash';
import {
activateTheme,
clearLocalStorage,
createMenu,
deleteAllMenus,
enablePageDialogAccept,
installTheme,
isOfflineMode,
Expand Down Expand Up @@ -250,36 +248,6 @@ async function createTestData() {
} );
}

/**
* Create test posts so that the WordPress instance has some data.
*/
async function createTestMenus() {
await deleteAllMenus();
await createMenu(
{
name: 'Test Menu 1',
},
[
{
title: 'WordPress.org',
url: 'https://wordpress.org',
menu_order: 1,
},
{
title: 'Wikipedia.org',
url: 'https://wikipedia.org',
menu_order: 2,
},
{
title: 'Google',
url: 'https://google.com',
menu_order: 3,
parent: 1,
},
],
);
}

/**
* Install themes and plugins needed in tests.
*/
Expand Down Expand Up @@ -309,7 +277,6 @@ beforeAll( async () => {
await setupThemesAndPlugins();
await trashAllPosts();
await createTestData();
await createTestMenus();
await cleanUpSettings();
await page.setDefaultNavigationTimeout( 10000 );
await page.setDefaultTimeout( 10000 );
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentyfifteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Fifteen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Fifteen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentyfourteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Fourteen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Fourteen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentynineteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Nineteen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Nineteen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'menu-1' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentyseventeen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Seventeen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Seventeen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'top' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentysixteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Sixteen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Sixteen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentythirteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Thirteen theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Thirteen theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentytwelve.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Twelve theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Twelve theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentytwenty.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, setBrowserViewport, visitAdminPage } from '@w
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Twenty theme on AMP', () => {
Expand All @@ -31,6 +31,7 @@ describe( 'Twenty Twenty theme on AMP', () => {

describe( 'main navigation', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'mobile' );
} );

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/core-themes/twentytwentyone.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminP
* Internal dependencies
*/
import { setTemplateMode } from '../../utils/amp-settings-utils';
import { assignMenuToLocation } from '../../utils/assign-menu-to-location';
import { assignMenuToLocation, createTestMenu } from '../../utils/nav-menu-utils';
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap';

describe( 'Twenty Twenty-One theme on AMP', () => {
Expand All @@ -25,6 +25,7 @@ describe( 'Twenty Twenty-One theme on AMP', () => {

describe( 'main navigation on mobile', () => {
beforeAll( async () => {
await createTestMenu();
await assignMenuToLocation( 'primary' );
} );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
/**
* WordPress dependencies
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';
import { createMenu, deleteAllMenus, visitAdminPage } from '@wordpress/e2e-test-utils';

export async function createTestMenu() {
await deleteAllMenus();
await createMenu(
{
name: 'Test Menu 1',
},
[
{
title: 'WordPress.org',
url: 'https://wordpress.org',
menu_order: 1,
},
{
title: 'Wikipedia.org',
url: 'https://wikipedia.org',
menu_order: 2,
},
{
title: 'Google',
url: 'https://google.com',
menu_order: 3,
parent: 1,
},
],
);
}

export async function assignMenuToLocation( menuLocationName ) {
await visitAdminPage( 'nav-menus.php', '' );
Expand Down

0 comments on commit beba916

Please sign in to comment.