-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E tests for core themes mobile menus (#6933)
Co-authored-by: Piotr Delawski <piotr.delawski@gmail.com>
- Loading branch information
1 parent
26c9220
commit e6686fd
Showing
11 changed files
with
690 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminPage } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setTemplateMode } from '../../utils/amp-settings-utils'; | ||
import { assignMenuToLocation } from '../../utils/assign-menu-to-location'; | ||
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap'; | ||
|
||
describe( 'Twenty Fifteen theme on AMP', () => { | ||
beforeAll( async () => { | ||
await installTheme( 'twentyfifteen' ); | ||
await activateTheme( 'twentyfifteen' ); | ||
|
||
await visitAdminPage( 'admin.php', 'page=amp-options' ); | ||
await setTemplateMode( 'standard' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwenty' ); | ||
} ); | ||
|
||
describe( 'main navigation on mobile', () => { | ||
beforeAll( async () => { | ||
await assignMenuToLocation( 'primary' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await setBrowserViewport( MOBILE_BROWSER_VIEWPORT_SIZE ); | ||
await page.goto( createURL( '/' ) ); | ||
await page.waitForSelector( '#page' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await setBrowserViewport( DEFAULT_BROWSER_VIEWPORT_SIZE ); | ||
} ); | ||
|
||
it( 'should be initially hidden', async () => { | ||
await expect( page ).toMatchElement( '.site-header .secondary-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#site-navigation', { visible: false } ); | ||
} ); | ||
|
||
it( 'should be togglable', async () => { | ||
await expect( page ).toClick( '.site-header .secondary-toggle' ); | ||
await expect( page ).toMatchElement( '.site-header .secondary-toggle[aria-expanded=true]' ); | ||
await expect( page ).toMatchElement( '#site-navigation', { visible: true } ); | ||
|
||
await expect( page ).toClick( '.site-header .secondary-toggle' ); | ||
await expect( page ).toMatchElement( '.site-header .secondary-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#site-navigation', { visible: false } ); | ||
} ); | ||
|
||
it( 'should have a togglable submenu', async () => { | ||
await expect( page ).toClick( '.site-header .secondary-toggle' ); | ||
|
||
const menuItemWithSubmenu = await page.$( '#site-navigation .menu-item-has-children' ); | ||
|
||
expect( menuItemWithSubmenu ).not.toBeNull(); | ||
|
||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=false]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } ); | ||
|
||
await expect( menuItemWithSubmenu ).toClick( '.dropdown-toggle' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=true]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: true } ); | ||
|
||
await expect( menuItemWithSubmenu ).toClick( '.dropdown-toggle' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=false]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminPage } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setTemplateMode } from '../../utils/amp-settings-utils'; | ||
import { assignMenuToLocation } from '../../utils/assign-menu-to-location'; | ||
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap'; | ||
|
||
describe( 'Twenty Fourteen theme on AMP', () => { | ||
beforeAll( async () => { | ||
await installTheme( 'twentyfourteen' ); | ||
await activateTheme( 'twentyfourteen' ); | ||
|
||
await visitAdminPage( 'admin.php', 'page=amp-options' ); | ||
await setTemplateMode( 'standard' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwenty' ); | ||
} ); | ||
|
||
describe( 'main navigation on mobile', () => { | ||
beforeAll( async () => { | ||
await assignMenuToLocation( 'primary' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await setBrowserViewport( MOBILE_BROWSER_VIEWPORT_SIZE ); | ||
await page.goto( createURL( '/' ) ); | ||
await page.waitForSelector( '#page' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await setBrowserViewport( DEFAULT_BROWSER_VIEWPORT_SIZE ); | ||
} ); | ||
|
||
it( 'should be initially hidden', async () => { | ||
await expect( page ).toMatchElement( '#primary-navigation .menu-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#primary-navigation .nav-menu', { visible: false } ); | ||
} ); | ||
|
||
it( 'should be togglable', async () => { | ||
await expect( page ).toClick( '#primary-navigation .menu-toggle' ); | ||
await expect( page ).toMatchElement( '#primary-navigation .menu-toggle[aria-expanded=true]' ); | ||
await expect( page ).toMatchElement( '#primary-navigation .nav-menu', { visible: true } ); | ||
|
||
// Submenus are expanded by default on twentyfourteen mobile. | ||
await expect( page ).toMatchElement( '#primary-navigation .nav-menu .menu-item-has-children .sub-menu', { visible: true } ); | ||
|
||
await expect( page ).toClick( '#primary-navigation .menu-toggle' ); | ||
await expect( page ).toMatchElement( '#primary-navigation .menu-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#primary-navigation .nav-menu', { visible: false } ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminPage } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setTemplateMode } from '../../utils/amp-settings-utils'; | ||
import { assignMenuToLocation } from '../../utils/assign-menu-to-location'; | ||
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap'; | ||
|
||
describe( 'Twenty Nineteen theme on AMP', () => { | ||
beforeAll( async () => { | ||
await installTheme( 'twentynineteen' ); | ||
await activateTheme( 'twentynineteen' ); | ||
|
||
await visitAdminPage( 'admin.php', 'page=amp-options' ); | ||
await setTemplateMode( 'standard' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwenty' ); | ||
} ); | ||
|
||
describe( 'main navigation on mobile', () => { | ||
beforeAll( async () => { | ||
await assignMenuToLocation( 'menu-1' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await setBrowserViewport( MOBILE_BROWSER_VIEWPORT_SIZE ); | ||
await page.goto( createURL( '/' ) ); | ||
await page.waitForSelector( '#page' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await setBrowserViewport( DEFAULT_BROWSER_VIEWPORT_SIZE ); | ||
} ); | ||
|
||
it( 'should have a togglable submenu', async () => { | ||
await expect( page ).toMatchElement( '.main-navigation' ); | ||
|
||
const menuItemWithSubmenu = await page.$( '.main-navigation .menu-item-has-children' ); | ||
|
||
expect( menuItemWithSubmenu ).not.toBeNull(); | ||
|
||
await expect( menuItemWithSubmenu ).toMatchElement( '.submenu-expand' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } ); | ||
|
||
await expect( menuItemWithSubmenu ).toClick( '.submenu-expand' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: true } ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activateTheme, createURL, installTheme, setBrowserViewport, visitAdminPage } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setTemplateMode } from '../../utils/amp-settings-utils'; | ||
import { assignMenuToLocation } from '../../utils/assign-menu-to-location'; | ||
import { DEFAULT_BROWSER_VIEWPORT_SIZE, MOBILE_BROWSER_VIEWPORT_SIZE } from '../../config/bootstrap'; | ||
|
||
describe( 'Twenty Seventeen theme on AMP', () => { | ||
beforeAll( async () => { | ||
await installTheme( 'twentyseventeen' ); | ||
await activateTheme( 'twentyseventeen' ); | ||
|
||
await visitAdminPage( 'admin.php', 'page=amp-options' ); | ||
await setTemplateMode( 'standard' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwenty' ); | ||
} ); | ||
|
||
describe( 'main navigation on mobile', () => { | ||
beforeAll( async () => { | ||
await assignMenuToLocation( 'top' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await setBrowserViewport( MOBILE_BROWSER_VIEWPORT_SIZE ); | ||
await page.goto( createURL( '/' ) ); | ||
await page.waitForSelector( '#page' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await setBrowserViewport( DEFAULT_BROWSER_VIEWPORT_SIZE ); | ||
} ); | ||
|
||
it( 'should be initially hidden', async () => { | ||
await expect( page ).toMatchElement( '.main-navigation .menu-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#top-menu', { visible: false } ); | ||
} ); | ||
|
||
it( 'should be togglable', async () => { | ||
await expect( page ).toClick( '.main-navigation .menu-toggle' ); | ||
await expect( page ).toMatchElement( '.main-navigation .menu-toggle[aria-expanded=true]' ); | ||
await expect( page ).toMatchElement( '#top-menu', { visible: true } ); | ||
|
||
await expect( page ).toClick( '.main-navigation .menu-toggle' ); | ||
await expect( page ).toMatchElement( '.main-navigation .menu-toggle[aria-expanded=false]' ); | ||
await expect( page ).toMatchElement( '#top-menu', { visible: false } ); | ||
} ); | ||
|
||
it( 'should have a togglable submenu', async () => { | ||
await expect( page ).toClick( '.main-navigation .menu-toggle' ); | ||
|
||
const menuItemWithSubmenu = await page.$( '.main-navigation .menu-item-has-children' ); | ||
|
||
expect( menuItemWithSubmenu ).not.toBeNull(); | ||
|
||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=false]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } ); | ||
|
||
await expect( menuItemWithSubmenu ).toClick( '.dropdown-toggle' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=true]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: true } ); | ||
|
||
await expect( menuItemWithSubmenu ).toClick( '.dropdown-toggle' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.dropdown-toggle[aria-expanded=false]' ); | ||
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.