import { browser , Key } from 'protractor' ; import { imageCompare } from '../common/image-compare' ; import { CardTabsPage } from './card-tabs.po.spec' ; describe ( 'Card Tab Tests' , ( ) => { let page ; beforeEach ( async ( ) => { page = new CardTabsPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . getTabSelected ( 0 ) ) . toBe ( true ) ; expect ( await page . getTabSelected ( 1 ) ) . toBe ( false ) ; expect ( await page . getTabSelected ( 2 ) ) . toBe ( false ) ; expect ( await page . getTabSelected ( 3 ) ) . toBe ( false ) ; expect ( await page . getTabSelected ( 4 ) ) . toBe ( false ) ; expect ( await page . getPosition ( ) ) . toBe ( 'top' ) ; expect ( await page . getTabContent ( ) ) . toBe ( 'Tab 1 Content' ) ; expect ( await imageCompare ( 'card-tabs-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should select a card on click' , async ( ) => { expect ( await page . getTabSelected ( 0 ) ) . toBe ( true ) ; expect ( await page . getTabSelected ( 1 ) ) . toBe ( false ) ; const tab = await page . getTab ( 1 ) ; await tab . click ( ) ; expect ( await page . getTabSelected ( 0 ) ) . toBe ( false ) ; expect ( await page . getTabSelected ( 1 ) ) . toBe ( true ) ; expect ( await page . getTabContent ( ) ) . toBe ( 'Tab 2 Content' ) ; } ) ; it ( 'should select a card on enter' , async ( ) => { expect ( await page . getTabSelected ( 0 ) ) . toBe ( true ) ; expect ( await page . getTabSelected ( 1 ) ) . toBe ( false ) ; await browser . actions ( ) . sendKeys ( Key . TAB ) . sendKeys ( Key . TAB ) . sendKeys ( Key . ENTER ) . perform ( ) ; expect ( await page . getTabSelected ( 0 ) ) . toBe ( false ) ; expect ( await page . getTabSelected ( 1 ) ) . toBe ( true ) ; expect ( await page . getTabContent ( ) ) . toBe ( 'Tab 2 Content' ) ; } ) ; it ( 'should show more items on next button click' , async ( ) => { expect ( await page . getScrollPosition ( ) ) . toBe ( 0 ) ; await page . nextBtn . click ( ) ; await browser . sleep ( 500 ) ; expect ( await page . getScrollPosition ( ) ) . toBe ( - 400 ) ; } ) ; it ( 'should be able to scroll back again' , async ( ) => { expect ( await page . getScrollPosition ( ) ) . toBe ( 0 ) ; await page . nextBtn . click ( ) ; await browser . sleep ( 500 ) ; expect ( await page . getScrollPosition ( ) ) . toBe ( - 400 ) ; await page . previousBtn . click ( ) ; await browser . sleep ( 500 ) ; expect ( await page . getScrollPosition ( ) ) . toBe ( 0 ) ; } ) ; it ( 'should be able to change the position' , async ( ) => { expect ( await page . getPosition ( ) ) . toBe ( 'top' ) ; await page . positionBtn . click ( ) ; expect ( await page . getPosition ( ) ) . toBe ( 'bottom' ) ; } ) ; } ) ;