diff --git a/e2e/various-suite/navigation.spec.ts b/e2e/various-suite/navigation.spec.ts new file mode 100644 index 00000000000..35ee5ee90f4 --- /dev/null +++ b/e2e/various-suite/navigation.spec.ts @@ -0,0 +1,47 @@ +import { e2e } from '../utils'; +import { fromBaseUrl } from '../utils/support/url'; + +describe('Docked Navigation', () => { + beforeEach(() => { + cy.viewport(1280, 800); + e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD')); + + cy.visit(fromBaseUrl('/'), { + onBeforeLoad(window) { + window.localStorage.setItem('grafana.featureToggles', 'dockedMegaMenu=1'); + }, + }); + }); + + it('should remain docked when reloading the page', () => { + // Expand, then dock the mega menu + cy.get('[aria-label="Toggle menu"]').click(); + cy.get('[aria-label="Dock menu"]').click(); + + e2e.components.NavMenu.Menu().should('be.visible'); + + cy.reload(); + e2e.components.NavMenu.Menu().should('be.visible'); + }); + + it('should remain docked when navigating to another page', () => { + // Expand, then dock the mega menu + cy.get('[aria-label="Toggle menu"]').click(); + cy.get('[aria-label="Dock menu"]').click(); + + cy.contains('a', 'Administration').click(); + e2e.components.NavMenu.Menu().should('be.visible'); + + cy.contains('a', 'Users').click(); + e2e.components.NavMenu.Menu().should('be.visible'); + }); + + it('should become docked at larger viewport sizes', () => { + e2e.components.NavMenu.Menu().should('not.exist'); + + cy.viewport(1920, 1080); + cy.reload(); + + e2e.components.NavMenu.Menu().should('be.visible'); + }); +}); diff --git a/packages/grafana-e2e-selectors/src/selectors/components.ts b/packages/grafana-e2e-selectors/src/selectors/components.ts index e658a6134fc..c023ab6cf3f 100644 --- a/packages/grafana-e2e-selectors/src/selectors/components.ts +++ b/packages/grafana-e2e-selectors/src/selectors/components.ts @@ -264,6 +264,7 @@ export const Components = { }, }, NavMenu: { + Menu: 'data-testid navigation mega-menu', item: 'data-testid Nav menu item', }, NavToolbar: { diff --git a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.test.tsx b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.test.tsx index a914fda4cac..5b603aeb12d 100644 --- a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.test.tsx +++ b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.test.tsx @@ -5,6 +5,7 @@ import { Router } from 'react-router-dom'; import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; import { NavModelItem } from '@grafana/data'; +import { selectors } from '@grafana/e2e-selectors'; import { locationService } from '@grafana/runtime'; import { TestProvider } from '../../../../../test/helpers/TestProvider'; @@ -53,7 +54,7 @@ describe('MegaMenu', () => { it('should render component', async () => { setup(); - expect(await screen.findByTestId('navbarmenu')).toBeInTheDocument(); + expect(await screen.findByTestId(selectors.components.NavMenu.Menu)).toBeInTheDocument(); expect(await screen.findByRole('link', { name: 'Section name' })).toBeInTheDocument(); }); diff --git a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.tsx b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.tsx index 622426f3485..ca3a90e364e 100644 --- a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.tsx +++ b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.tsx @@ -4,6 +4,7 @@ import React, { forwardRef } from 'react'; import { useLocation } from 'react-router-dom'; import { GrafanaTheme2 } from '@grafana/data'; +import { selectors } from '@grafana/e2e-selectors'; import { CustomScrollbar, Icon, IconButton, useStyles2 } from '@grafana/ui'; import { Flex } from '@grafana/ui/src/unstable'; import { useGrafana } from 'app/core/context/GrafanaContext'; @@ -39,7 +40,7 @@ export const MegaMenu = React.memo( }; return ( -
+
{ it('should render component', async () => { setup(); - expect(await screen.findByTestId('navbarmenu')).toBeInTheDocument(); + expect(await screen.findByTestId(selectors.components.NavMenu.Menu)).toBeInTheDocument(); expect(await screen.findByRole('link', { name: 'Section name' })).toBeInTheDocument(); }); diff --git a/public/app/core/components/AppChrome/MegaMenu/NavBarMenu.tsx b/public/app/core/components/AppChrome/MegaMenu/NavBarMenu.tsx index 18e6411a900..6cdb9d308b3 100644 --- a/public/app/core/components/AppChrome/MegaMenu/NavBarMenu.tsx +++ b/public/app/core/components/AppChrome/MegaMenu/NavBarMenu.tsx @@ -6,6 +6,7 @@ import React, { useEffect, useRef, useState } from 'react'; import CSSTransition from 'react-transition-group/CSSTransition'; import { GrafanaTheme2, NavModelItem } from '@grafana/data'; +import { selectors } from '@grafana/e2e-selectors'; import { CustomScrollbar, Icon, IconButton, useTheme2 } from '@grafana/ui'; import { useGrafana } from 'app/core/context/GrafanaContext'; @@ -62,7 +63,13 @@ export function NavBarMenu({ activeItem, navItems, searchBarHidden, onClose }: P onExited={onClose} > -
+