@ -3,56 +3,73 @@ import { fromBaseUrl } from '../utils/support/url';
describe ( 'Pin nav items' , ( ) = > {
describe ( 'Pin nav items' , ( ) = > {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
cy . viewport ( 1280 , 800 ) ;
e2e . flows . login ( Cypress . env ( 'USERNAME' ) , Cypress . env ( 'PASSWORD' ) ) ;
e2e . flows . login ( Cypress . env ( 'USERNAME' ) , Cypress . env ( 'PASSWORD' ) ) ;
cy . visit ( fromBaseUrl ( '/' ) ) ;
} ) ;
} ) ;
afterEach ( ( ) = > {
afterEach ( ( ) = > {
e2e . flows . setDefaultUserPreferences ( ) ;
e2e . flows . setDefaultUserPreferences ( ) ;
} ) ;
} ) ;
it ( 'should pin the selected menu item and add it as a Bookmarks menu item child' , ( ) = > {
it ( 'should pin the selected menu item and add it as a Bookmarks menu item child' , ( ) = > {
// Check if the mega menu is visible
cy . visit ( fromBaseUrl ( '/' ) , {
e2e . components . NavMenu . Menu ( ) . should ( 'be.visible' ) ;
onBeforeLoad : ( win ) = > {
win . localStorage . setItem ( 'grafana.navigation.docked' , 'true' ) ; // Make sure the menu is docked
// Check if the Bookmark section is visible
} ,
const bookmarkSection = cy . get ( '[href="/bookmarks"]' ) ;
bookmarkSection . should ( 'be.visible' ) ;
// Click on the pin icon to add Administration to the Bookmarks section
const adminItem = cy . contains ( 'a' , 'Administration' ) ;
const bookmarkPinIcon = adminItem . siblings ( 'button' ) . should ( 'have.attr' , 'aria-label' , 'Add to Bookmarks' ) ;
bookmarkPinIcon . click ( { force : true } ) ;
// Check if the Administration menu item is visible in the Bookmarks section
cy . get ( '[aria-label="Expand section: Bookmarks"]' ) . click ( ) ;
const bookmarks = cy . get ( '[href="/bookmarks"]' ) . parentsUntil ( 'li' ) . siblings ( 'ul' ) ;
bookmarks . within ( ( ) = > {
cy . get ( 'a' ) . should ( 'contain.text' , 'Administration' ) ;
} ) ;
} ) ;
e2e . components . NavMenu . Menu ( )
. should ( 'be.visible' )
. within ( ( ) = > {
cy . get ( 'ul[aria-label="Navigation"]' ) . should ( 'be.visible' ) . as ( 'navList' ) ;
// Check if the Bookmark section is visible
cy . get ( '@navList' ) . children ( ) . eq ( 1 ) . should ( 'be.visible' ) . as ( 'bookmarksItem' ) ;
cy . get ( '@bookmarksItem' ) . should ( 'contain.text' , 'Bookmarks' ) ;
// Check if the Adminstration section is visible
cy . get ( '@navList' ) . children ( ) . last ( ) . should ( 'be.visible' ) . as ( 'adminItem' ) ;
cy . get ( '@adminItem' ) . should ( 'contain.text' , 'Administration' ) ;
cy . get ( '@adminItem' ) . within ( ( ) = > {
cy . get ( 'button[aria-label="Add to Bookmarks"]' ) . should ( 'exist' ) . click ( { force : true } ) ;
} ) ;
// Check if the Administration menu item is visible in the Bookmarks section
cy . get ( '@bookmarksItem' ) . within ( ( ) = > {
// Expand the Bookmarks section
cy . get ( 'button[aria-label="Expand section: Bookmarks"]' ) . should ( 'exist' ) . click ( { force : true } ) ;
cy . get ( 'a' ) . should ( 'contain.text' , 'Administration' ) . should ( 'be.visible' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
it ( 'should unpin the item and remove it from the Bookmarks section' , ( ) = > {
it ( 'should unpin the item and remove it from the Bookmarks section' , ( ) = > {
// Set Administration as a pinned item and reload the page
// Set Administration as a pinned item and reload the page
e2e . flows . setUserPreferences ( { navbar : { bookmarkUrls : [ '/admin' ] } } ) ;
e2e . flows . setUserPreferences ( { navbar : { bookmarkUrls : [ '/admin' ] } } ) ;
cy . reload ( ) ;
// Check if the mega menu is visible
cy . visit ( fromBaseUrl ( '/' ) , {
e2e . components . NavMenu . Menu ( ) . should ( 'be.visible' ) ;
onBeforeLoad : ( win ) = > {
win . localStorage . setItem ( 'grafana.navigation.docked' , 'true' ) ; // Make sure the menu is docked
} ,
} ) ;
// Check if the Bookmark section is visible and open it
e2e . components . NavMenu . Menu ( )
cy . get ( '[href="/bookmarks"]' ) . should ( 'be.visible' ) ;
. should ( 'be.visible' )
cy . get ( '[aria-label="Expand section: Bookmarks"]' ) . click ( ) ;
. within ( ( ) = > {
cy . get ( 'ul[aria-label="Navigation"]' ) . should ( 'be.visible' ) . as ( 'navList' ) ;
// Check if the Administration menu item is visible in the Bookmarks section
// Check if the Bookmark section is visible
const bookmarks = cy . get ( '[href="/bookmarks"]' ) . parentsUntil ( 'li' ) . siblings ( 'ul' ) . children ( ) ;
cy . get ( '@navList' ) . children ( ) . eq ( 1 ) . should ( 'be.visible' ) . as ( 'bookmarksItem' ) ;
const administrationIsPinned = bookmarks . filter ( 'li' ) . children ( ) . should ( 'contain.text' , 'Administration' ) ;
cy . get ( '@bookmarksItem' ) . should ( 'contain.text' , 'Bookmarks' ) ;
cy . get ( '@bookmarksItem' ) . within ( ( ) = > {
// Expand the Bookmarks section
cy . get ( 'button[aria-label="Expand section: Bookmarks"]' ) . should ( 'exist' ) . click ( { force : true } ) ;
cy . get ( 'a' ) . should ( 'contain.text' , 'Administration' ) . should ( 'be.visible' ) ;
cy . get ( 'button[aria-label="Remove from Bookmarks"]' ) . should ( 'exist' ) . click ( { force : true } ) ;
} ) ;
// Click on the pin icon to remove Administration from the Bookmarks section and check if it is removed
cy . get ( '@bookmarksItem' , { timeout : 60000 } ) . within ( ( ) = > {
administrationIsPinned . within ( ( ) = > {
cy . get ( 'a' ) . should ( 'have.length' , 1 ) . should ( 'not.contain.text' , 'Administration' ) ;
cy . get ( '[aria-label="Remove from Bookmarks"]' ) . click ( { force : true } ) ;
} ) ;
} ) ;
} ) ;
cy . wait ( 500 ) ;
administrationIsPinned . should ( 'not.exist' ) ;
} ) ;
} ) ;
} ) ;
} ) ;