import { ElementArrayFinder , ElementFinder } from 'protractor' ; import { PageHeaderPage } from './page-header.po.spec' ; describe ( 'Page Header Tests' , ( ) => { let page ; beforeEach ( async ( ) => { page = new PageHeaderPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . confirmPageHeaderIsCondensed ( ) ) . toBeFalsy ( ) ; expect ( await page . getABreadcrumb ( 0 ) ) . toEqual ( 'Home' ) ; expect ( await page . confirmApplicationLogoIsPresent ( ) ) . toBeTruthy ( ) ; expect ( await page . getApplicationLogoText ( ) ) . toEqual ( 'Home' ) ; expect ( await page . confirmDropdownIsPresent ( ) ) . toBeTruthy ( ) ; expect ( await page . confirmDropdownIsOpened ( ) ) . toBeFalsy ( ) ; expect ( await page . confirmNotificationIconIsPresent ( ) ) . toBeTruthy ( ) ; expect ( await page . confirmActionsIconIsPresent ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should display breadcrumbs when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . getABreadcrumb ( 0 ) ) . toEqual ( 'Home' ) ; expect ( await page . getABreadcrumb ( 1 ) ) . toEqual ( 'Archive' ) ; expect ( await page . getABreadcrumb ( 2 ) ) . toEqual ( 'My Page' ) ; } ) ; it ( 'should display an application logo and text when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . confirmApplicationLogoIsPresent ( ) ) . toBeTruthy ( ) ; expect ( await page . getApplicationLogoText ( ) ) . toEqual ( 'Home' ) ; } ) ; it ( 'should display the dropdown menu' , async ( ) => { expect ( await page . confirmDropdownIsPresent ( ) ) . toBeTruthy ( ) ; await page . openDropdown ( ) ; expect ( await page . confirmDropdownIsOpened ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should display the dropdown menu when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . confirmDropdownIsPresent ( ) ) . toBeTruthy ( ) ; await page . openDropdown ( ) ; expect ( await page . confirmDropdownIsOpened ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should display the dropdown menu items' , async ( ) => { expect ( await page . confirmDropdownIsPresent ( ) ) . toBeTruthy ( ) ; await page . openDropdown ( ) ; expect ( await page . confirmDropdownIsOpened ( ) ) . toBeTruthy ( ) ; expect ( await page . getFirstDropdownMenuItem ( 1 ) ) . toEqual ( 'Pie Charts' ) ; await page . displaySecondDropdownMenu ( ) ; expect ( await page . getSecondDropdownMenuItem ( 2 ) ) . toEqual ( 'Monthly View' ) ; } ) ; it ( 'should display the dropdown menu items when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . confirmDropdownIsPresent ( ) ) . toBeTruthy ( ) ; await page . openDropdown ( ) ; expect ( await page . confirmDropdownIsOpened ( ) ) . toBeTruthy ( ) ; expect ( await page . getFirstDropdownMenuItem ( 1 ) ) . toEqual ( 'Pie Charts' ) ; await page . displaySecondDropdownMenu ( ) ; expect ( await page . getSecondDropdownMenuItem ( 2 ) ) . toEqual ( 'Monthly View' ) ; } ) ; it ( 'should display the notifications menu' , async ( ) => { expect ( await page . confirmNotificationIconIsPresent ( ) ) . toBeTruthy ( ) ; await page . openNotifications ( ) ; expect ( await page . confirmNotificationsAreDisplayed ( ) ) . toEqual ( 3 ) ; } ) ; it ( 'should display the notifications menu when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . confirmNotificationIconIsPresent ( ) ) . toBeTruthy ( ) ; await page . openNotifications ( ) ; expect ( await page . confirmNotificationsAreDisplayed ( ) ) . toEqual ( 3 ) ; } ) ; it ( 'should display the actions menu' , async ( ) => { expect ( await page . confirmActionsIconIsPresent ( ) ) . toBeTruthy ( ) ; await page . openActions ( ) ; expect ( await page . confirmActionsAreDisplayed ( ) ) . toEqual ( 3 ) ; } ) ; it ( 'should display the actions menu when condensed' , async ( ) => { await page . toggleTheHeader ( ) ; expect ( await page . confirmActionsIconIsPresent ( ) ) . toBeTruthy ( ) ; await page . openActions ( ) ; expect ( await page . confirmActionsAreDisplayed ( ) ) . toEqual ( 3 ) ; } ) ; it ( 'should not show secondary navigation when nothing is selected' , async ( ) => { const secondaryNavigation = await page . getSecondaryNavigation ( ) ; expect ( await secondaryNavigation . isPresent ( ) ) . toBe ( false ) ; } ) ; it ( 'should not show secondary navigation items when there is no children on the selected item' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 0 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; const tabset = await secondaryNavigation . $ ( '.nav-tabs' ) ; expect ( await secondaryNavigation . isPresent ( ) ) . toBe ( false ) ; expect ( await tabset . isPresent ( ) ) . toBe ( false ) ; } ) ; it ( 'should show secondary navigation items when there are children on the selected item' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; const tabset = await secondaryNavigation . $ ( '.nav-tabs' ) ; const tabs = await tabset . $$ ( 'li' ) ; expect ( await secondaryNavigation . isPresent ( ) ) . toBe ( true ) ; expect ( await tabset . isPresent ( ) ) . toBe ( true ) ; expect ( tabs . length ) . toBe ( 3 ) ; } ) ; it ( 'should align the tabset accordingly' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; expect ( await page . getClasses ( secondaryNavigation ) ) . toContain ( 'center' ) ; await page . alignLeftButton . click ( ) ; expect ( await page . getClasses ( secondaryNavigation ) ) . toContain ( 'left' ) ; await page . alignRightButton . click ( ) ; expect ( await page . getClasses ( secondaryNavigation ) ) . toContain ( 'right' ) ; await page . alignCenterButton . click ( ) ; expect ( await page . getClasses ( secondaryNavigation ) ) . toContain ( 'center' ) ; } ) ; it ( 'should call the select functions when secondary items are clicked' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; const tabset = await secondaryNavigation . $ ( '.nav-tabs' ) ; const tabs = await tabset . $$ ( 'li' ) ; await tabs [ 0 ] . click ( ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Daily View' ) ; await tabs [ 1 ] . click ( ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Weekly View' ) ; await tabs [ 2 ] . click ( ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Monthly View' ) ; } ) ; it ( 'should automatically select the first item when autoselect is enabled' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; const tabset = await secondaryNavigation . $ ( '.nav-tabs' ) ; const tabs = await tabset . $$ ( 'li' ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Daily View' ) ; } ) ; it ( 'should reselect the first item when the parent it clicked with autoselect enabled' , async ( ) => { await page . autoselectButton . click ( ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; const secondaryNavigation = await page . getSecondaryNavigation ( ) ; const tabset = await secondaryNavigation . $ ( '.nav-tabs' ) ; const tabs = await tabset . $$ ( 'li' ) ; await tabs [ 1 ] . click ( ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Weekly View' ) ; await page . pageHeader2 . $$ ( '.horizontal-navigation-button' ) . get ( 1 ) . click ( ) ; expect ( await page . selected . getText ( ) ) . toBe ( 'Daily View' ) ; } ) ; it ( 'should get the correct subheader' , async ( ) => { expect ( await page . getSubheaderText ( page . pageHeader1 ) ) . toBe ( 'My Subheader' ) ; } ) ; it ( 'should navigate to the routerLink of the breadcrumb when clicked' , async ( ) => { expect ( await page . getBreadcrumbPageTextContent ( ) ) . toBe ( '' ) ; await page . clickBreadcrumb ( 0 ) ; expect ( await page . getBreadcrumbPageTextContent ( ) ) . toBe ( 'Home' ) ; } ) ; it ( 'should not navigate when clicking a breadcrumb that does not specify a routerLink' , async ( ) => { expect ( await page . getBreadcrumbPageTextContent ( ) ) . toBe ( '' ) ; await page . clickBreadcrumb ( 1 ) ; expect ( await page . getBreadcrumbPageTextContent ( ) ) . toBe ( '' ) ; } ) ; } ) ;