Skip to content

Commit

Permalink
Merge pull request #734 from bluehost/update/admin-menu-behaviour
Browse files Browse the repository at this point in the history
Register admin submenu exclusively outside the app
  • Loading branch information
circlecube authored Oct 13, 2023
2 parents b259ff3 + a66a0fb commit 1279fb3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 44 deletions.
21 changes: 12 additions & 9 deletions inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ public static function page() {
0
);

foreach ( self::subpages() as $route => $title ) {
\add_submenu_page(
'bluehost',
$title,
$title,
'manage_options',
$route,
array( __CLASS__, 'render' )
);
// If we're outside of Bluehost, add subpages to Bluehost menu
if ( false === ( isset( $_GET['page'] ) && strpos( filter_input( INPUT_GET, 'page', FILTER_UNSAFE_RAW ), 'bluehost' ) >= 0 ) ) { // phpcs:ignore
foreach ( self::subpages() as $route => $title ) {
\add_submenu_page(
'bluehost',
$title,
$title,
'manage_options',
$route,
array( __CLASS__, 'render' )
);
}
}
}

Expand Down
58 changes: 23 additions & 35 deletions tests/cypress/integration/navigation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ describe('Navigation', function () {

});

it('Admin submenu shouldn\'t exist inside app', () => {
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu')
.should('not.exist');
});

it('Logo Links to home', () => {
cy.get('.wppbh-logo-wrap').click();
cy.wait(500);
cy.hash().should('eq', '#/home');
});

it('Admin Subnav properly highlights', () => {
cy
.get('#adminmenu #toplevel_page_bluehost')
.should('have.class', 'wp-has-current-submenu');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /home/);
});

// test main nav
it('Main nav links properly navigates', () => {
Expand All @@ -35,10 +31,6 @@ describe('Navigation', function () {
cy
.get('.wppbh-app-navitem-Marketplace')
.should('have.class', 'active');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /marketplace/);

cy.get('.wppbh-app-navitem-Performance').click();
cy.wait(500);
Expand All @@ -49,18 +41,10 @@ describe('Navigation', function () {
cy
.get('.wppbh-app-navitem-Marketplace')
.should('not.have.class', 'active');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /performance/);

cy.get('.wppbh-app-navitem-Settings').click();
cy.wait(500);
cy.hash().should('eq', '#/settings');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /settings/);
});

it('Subnav links properly navigates', () => {
Expand All @@ -76,21 +60,13 @@ describe('Navigation', function () {
cy
.get('.wppbh-app-navitem-Marketplace')
.should('have.class', 'active');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /marketplace/);

cy.get('.wppbh-app-subnavitem-Services').click();
cy.wait(500);
cy.hash().should('eq', '#/marketplace/services');
cy
.get('.wppbh-app-subnavitem-Services')
.should('have.class', 'active');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /marketplace/);
cy
.get('.wppbh-app-navitem-Marketplace')
.should('have.class', 'active');
Expand All @@ -105,14 +81,10 @@ describe('Navigation', function () {
cy
.get('.wppbh-app-subnavitem-Services')
.should('not.have.class', 'active');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a')
.should('have.attr', 'href')
.and('match', /marketplace/);
cy
.get('.wppbh-app-navitem-Marketplace')
.should('have.class', 'active');

cy.get('.wppbh-app-navitem-Performance').click();
cy.wait(500);
cy
Expand All @@ -126,6 +98,22 @@ describe('Navigation', function () {
.should('not.have.class', 'active');
});

it('Admin submenu exist outside the app', () => {
cy.visit('/wp-admin/index.php');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu')
.should('exist');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/home"]')
.should('exist');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/marketplace"]')
.should('exist');
cy
.get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/settings"]')
.should('exist');
});

// utility nav is no more, leaving this in place un case we bring it back anytime soon.
it.skip('Utility nav links properly navigates', () => {
cy
Expand Down

0 comments on commit 1279fb3

Please sign in to comment.