import { browser , Key } from 'protractor' ; import { imageCompare } from '../common/image-compare' ; import { TabsTestPageComponent } from './tabs.po.spec' ; describe ( 'Tabs Tests (Angular)' , ( ) => { let page ; beforeEach ( async ( ) => { page = new TabsTestPageComponent ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . getTabCount ( ) ) . toBe ( 4 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; expect ( await page . getTabsetStyle ( ) ) . toBe ( 'minimal' ) ; expect ( await page . getTabsetStack ( ) ) . toBe ( 'none' ) ; expect ( await imageCompare ( 'tabs-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should select a tab on click' , async ( ) => { expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; await page . clickTabAtIndex ( 1 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'protection' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Protection' ) ; } ) ; it ( 'should navigate between tabs using arrow keys' , async ( ) => { expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; await page . clickTabAtIndex ( 1 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'protection' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Protection' ) ; await page . pressKey ( Key . ARROW_LEFT ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; await page . pressKey ( Key . ARROW_RIGHT ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'protection' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Protection' ) ; } ) ; it ( 'should navigate to first tab when Home key is pressed' , async ( ) => { expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; await page . clickTabAtIndex ( 1 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'protection' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Protection' ) ; await page . pressKey ( Key . HOME ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; } ) ; it ( 'should navigate to last tab when End key is pressed' , async ( ) => { expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Schedule' ) ; await page . clickTabAtIndex ( 1 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'protection' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Protection' ) ; await page . pressKey ( Key . END ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'analytics' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'Analytics' ) ; } ) ; it ( 'should trigger select event on click' , async ( ) => { expect ( await page . getSelectedLabelText ( ) ) . toBe ( 'The selected tab is: Schedule' ) ; await page . clickTabAtIndex ( 1 ) ; expect ( await page . getSelectedLabelText ( ) ) . toBe ( 'The selected tab is: Protection' ) ; } ) ; it ( 'should allow alternative styling' , async ( ) => { expect ( await page . getTabsetStyle ( ) ) . toBe ( 'minimal' ) ; await page . minimalCheckbox . click ( ) ; expect ( await page . getTabsetStyle ( ) ) . toBe ( 'alternative' ) ; await browser . sleep ( 500 ) ; expect ( await imageCompare ( 'tabs-alternate' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should allow stacking left' , async ( ) => { expect ( await page . getTabsetStack ( ) ) . toBe ( 'none' ) ; await page . stackLeftRadio . click ( ) ; expect ( await page . getTabsetStack ( ) ) . toBe ( 'left' ) ; expect ( await imageCompare ( 'tabs-stack-left' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should allow stacking right' , async ( ) => { expect ( await page . getTabsetStack ( ) ) . toBe ( 'none' ) ; await page . stackRightRadio . click ( ) ; expect ( await page . getTabsetStack ( ) ) . toBe ( 'right' ) ; expect ( await imageCompare ( 'tabs-stack-right' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should allow inserting a new tab at the leftmost position' , async ( ) => { expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; await page . addTab0 . click ( ) ; expect ( await page . getTabCount ( ) ) . toBe ( 5 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'schedule' ) ; await page . clickTabAtIndex ( 0 ) ; expect ( ( await page . getSelectedTab ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'new tab 0' ) ; expect ( await page . getSelectedTabContent ( ) ) . toBe ( 'New Tab 0' ) ; } ) ; } ) ;