Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register admin submenu exclusively outside the app #734

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading