import { browser , by , element , ElementFinder , protractor } from 'protractor' ; import { Util as Closeness } from './util' ; import { EasingFunctionsPage } from './easing-functions.po' ; xdescribe ( 'Scroll Easing Functions' , ( ) => { let page ; beforeEach ( ( ) => { page = new EasingFunctionsPage ( ) ; page . navigateTo ( ) ; } ) ; it ( 'should scroll to seventh heading from button with linear easing' , ( ) => { const target = element ( by . css ( '#head7' ) ) ; const trigger = element ( by . css ( '#testButton' ) ) ; target . getLocation ( ) . then ( ( headingLocation ) => { page . getScrollPos ( ) . then ( ( initialPos ) => { expect ( initialPos ) . toEqual ( 0 ) ; browser . manage ( ) . logs ( ) . get ( 'browser' ) . then ( ( ) => { trigger . sendKeys ( protractor . Key . ENTER ) . then ( ( ) => { browser . sleep ( 5000 ) . then ( ( ) => { page . getScrollPos ( ) . then ( ( pos ) => { expect ( pos ) . toBeCloseTo ( headingLocation . y , Closeness . ofByOne ) ; } ) ; browser . manage ( ) . logs ( ) . get ( 'browser' ) . then ( browserLog => { const scrollPositionHistory = browserLog . filter ( log => log . message . indexOf ( 'Scroll Position: ' ) >= 0 ) . map ( log => parseInt ( log . message . split ( ' ' ) . reverse ( ) [ 0 ] , 10 ) ) ; expect ( scrollPositionHistory . length ) . toBeGreaterThan ( 0 ) ; const totalScrollDistance = headingLocation . y - initialPos ; const averageScrollPosChange = scrollPositionHistory [ scrollPositionHistory . length - 1 ] / scrollPositionHistory . length ; const closeToEpsilon = Closeness . ofBy ( totalScrollDistance * 0.0075 ) ; for ( let i = 0 ; i < scrollPositionHistory . length - 2 ; i ++ ) { const scrollPosChange = scrollPositionHistory [ i + 1 ] - scrollPositionHistory [ i ] ; expect ( scrollPosChange ) . toBeCloseTo ( averageScrollPosChange , closeToEpsilon ) ; } } ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ; it ( 'should scroll to seventh heading from button with custom easing' , ( ) => { const target = element ( by . css ( '#head7' ) ) ; const trigger = element ( by . css ( '#customEasingButton' ) ) ; const pageScrollDuration = 1250 ; target . getLocation ( ) . then ( ( headingLocation ) => { page . getScrollPos ( ) . then ( ( initialPos ) => { expect ( initialPos ) . toEqual ( 0 ) ; browser . manage ( ) . logs ( ) . get ( 'browser' ) . then ( ( ) => { trigger . sendKeys ( protractor . Key . ENTER ) . then ( ( ) => { browser . sleep ( pageScrollDuration ) . then ( ( ) => { page . getScrollPos ( ) . then ( ( pos ) => { expect ( pos ) . toBeCloseTo ( Math . round ( headingLocation . y ) , Closeness . ofByOne ) ; } ) ; browser . manage ( ) . logs ( ) . get ( 'browser' ) . then ( browserLog => { const scrollPositionHistory = browserLog . filter ( log => log . message . indexOf ( 'Scroll Position: ' ) >= 0 ) . map ( log => parseInt ( log . message . split ( ' ' ) . reverse ( ) [ 0 ] , 10 ) ) ; expect ( scrollPositionHistory . length ) . toBeGreaterThan ( 0 ) ; const averageScrollPosChange = scrollPositionHistory [ scrollPositionHistory . length - 1 ] / scrollPositionHistory . length ; const firstQuarterEnd = Math . round ( scrollPositionHistory . length * 0.25 ) ; for ( let i = 0 ; i < firstQuarterEnd ; i ++ ) { const scrollPosChange = scrollPositionHistory [ i + 1 ] - scrollPositionHistory [ i ] ; expect ( scrollPosChange ) . toBeLessThan ( averageScrollPosChange ) ; } const center20PercentStart = Math . round ( scrollPositionHistory . length * 0.4 ) ; const center20PercentEnd = Math . round ( scrollPositionHistory . length * 0.6 ) ; for ( let i = center20PercentStart ; i < center20PercentEnd ; i ++ ) { const scrollPosChange = scrollPositionHistory [ i + 1 ] - scrollPositionHistory [ i ] ; expect ( scrollPosChange ) . toBeGreaterThan ( averageScrollPosChange ) ; } const lastQuarterStart = Math . round ( scrollPositionHistory . length * 0.75 ) ; for ( let i = lastQuarterStart ; i < scrollPositionHistory . length - 2 ; i ++ ) { const scrollPosChange = scrollPositionHistory [ i + 1 ] - scrollPositionHistory [ i ] ; expect ( scrollPosChange ) . toBeLessThan ( averageScrollPosChange ) ; } } ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ;