import { browser , by , element , ElementFinder , protractor } from 'protractor' ; import { Util as Closeness } from './util' ; import { NamespaceScrollPage } from './namespaces.po' ; describe ( 'Namespace Feature' , ( ) => { let page ; beforeEach ( ( ) => { page = new NamespaceScrollPage ( ) ; page . navigateTo ( ) ; } ) ; it ( 'should have only one scroll animation running in one namespace' , ( ) => { protractor . promise . all ( [ page . getContainer1ScrollTop ( ) , page . getContainer2ScrollTop ( ) ] ) . then ( ( [ container1ScrollTop , container2ScrollTop ] ) => { expect ( container1ScrollTop ) . toEqual ( 0 ) ; expect ( container2ScrollTop ) . toEqual ( 0 ) ; page . triggerDefaultNamespaces ( ) . then ( ( ) => { browser . sleep ( 1250 ) . then ( ( ) => { protractor . promise . all ( [ page . getContainer1ScrollTop ( ) , page . getContainer2ScrollTop ( ) ] ) . then ( ( [ laterContainer1ScrollTop , laterContainer2ScrollTop ] ) => { expect ( + laterContainer1ScrollTop ) . toEqual ( 0 ) ; expect ( + laterContainer2ScrollTop ) . toBeGreaterThan ( 0 ) ; } ) ; } ) ; } ) ; } ) ; } ) ; it ( 'should be possible to have multiple scroll animations running' , ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ container2ScrollTop , container3ScrollTop ] ) => { expect ( container2ScrollTop ) . toEqual ( 0 ) ; expect ( container3ScrollTop ) . toEqual ( 0 ) ; page . triggerDefaultAndCustomNamespaceScroll ( ) . then ( ( ) => { browser . sleep ( 1250 ) . then ( ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ laterContainer2ScrollTop , laterContainer3ScrollTop ] ) => { expect ( laterContainer2ScrollTop ) . toBeGreaterThan ( 0 ) ; expect ( laterContainer3ScrollTop ) . toBeGreaterThan ( 0 ) ; } ) ; } ) ; } ) ; } ) ; } ) ; it ( 'should stop only the running scroll animations in the correct namespace' , ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ container2ScrollTop , container3ScrollTop ] ) => { expect ( container2ScrollTop ) . toEqual ( 0 ) ; expect ( container3ScrollTop ) . toEqual ( 0 ) ; page . scheduleDefaultButtonClick ( ) ; page . triggerDefaultAndCustomNamespaceScroll ( ) . then ( ( ) => { browser . sleep ( 10000 ) . then ( ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ laterContainer2ScrollTop , laterContainer3ScrollTop ] ) => { expect ( + laterContainer2ScrollTop ) . toBeGreaterThan ( 0 ) ; expect ( page . getTarget2OffsetTop ( ) ) . toBeGreaterThan ( + laterContainer2ScrollTop ) ; expect ( page . getTarget3OffsetTop ( ) ) . toBeCloseTo ( + laterContainer3ScrollTop , Closeness . ofByOne ) ; } ) ; } ) ; } ) ; } ) ; } ) ; it ( 'should stop be able to stop all running scroll animations, regardless of the namespace' , ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ container2ScrollTop , container3ScrollTop ] ) => { expect ( container2ScrollTop ) . toEqual ( 0 ) ; expect ( container3ScrollTop ) . toEqual ( 0 ) ; page . scheduleStopAllButtonClick ( ) ; page . triggerDefaultAndCustomNamespaceScroll ( ) . then ( ( ) => { browser . sleep ( 10000 ) . then ( ( ) => { protractor . promise . all ( [ page . getContainer2ScrollTop ( ) , page . getContainer3ScrollTop ( ) ] ) . then ( ( [ laterContainer2ScrollTop , laterContainer3ScrollTop ] ) => { expect ( laterContainer2ScrollTop ) . toBeGreaterThan ( 0 ) ; expect ( page . getTarget2OffsetTop ( ) ) . toBeGreaterThan ( + laterContainer2ScrollTop ) ; expect ( laterContainer3ScrollTop ) . toBeGreaterThan ( 0 ) ; expect ( page . getTarget3OffsetTop ( ) ) . toBeGreaterThan ( + laterContainer3ScrollTop ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ;