11import { browser , element , by } from 'protractor' ;
22
3+ function scrollTo ( x : number = 0 , y : number = 0 ) {
4+ browser . executeScript ( `window.scrollTo(${ x } ,${ y } )` ) ;
5+ browser . sleep ( 200 ) ;
6+ }
7+
38describe ( 'InViewport Lib E2E Tests' , function ( ) {
49
510 beforeEach ( ( ) => browser . get ( '' ) ) ;
611
7- beforeEach ( ( ) => browser . executeScript ( 'window.scrollTo(0,0)' ) ) ;
12+ beforeEach ( ( ) => browser . waitForAngular ( ) ) ;
13+
14+ beforeEach ( ( ) => scrollTo ( ) ) ;
815
916 afterEach ( ( ) => {
1017 browser . manage ( ) . logs ( ) . get ( 'browser' ) . then ( ( browserLog : any [ ] ) => {
@@ -19,44 +26,49 @@ describe('InViewport Lib E2E Tests', function () {
1926 it ( 'should show `sn-viewport-out` class' , ( ) => {
2027 expect ( element ( by . css ( '.small-element.sn-viewport-out' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
2128
22- browser . executeScript ( 'window. scrollTo(0, window.innerHeight/2)' ) ;
29+ scrollTo ( 0 , 768 / 2 ) ;
2330 expect ( element ( by . css ( '.small-element.sn-viewport-out' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
2431 } ) ;
2532
2633 it ( 'should show `sn-viewport-in` class' , ( ) => {
27- browser . executeScript ( 'window. scrollTo(0, window.innerHeight/2)' ) ;
34+ scrollTo ( 0 , 768 / 2 ) ;
2835 expect ( element ( by . css ( '.small-element.sn-viewport-in' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
2936
30- browser . executeScript ( 'window.scrollTo(0,0)' ) ;
37+ scrollTo ( 0 , 0 ) ;
38+
3139 expect ( element ( by . css ( '.small-element.sn-viewport-in' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
3240 } ) ;
3341
3442 it ( 'should run event handler `onInViewportChange`' , ( ) => {
35- browser . executeScript ( 'window.scrollTo(0, window.innerHeight/2)' ) ;
43+ scrollTo ( 0 , 768 / 2 ) ;
44+
3645 expect ( element ( by . css ( '.small-element.highlight' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
3746
38- browser . executeScript ( 'window.scrollTo(0,0)' ) ;
47+ scrollTo ( ) ;
48+
3949 expect ( element ( by . css ( '.small-element.highlight' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
4050 } ) ;
4151
4252 it ( 'should add `in-viewport` class to large element' , ( ) => {
43- browser . executeScript ( 'window. scrollTo(0, window.innerHeight * 2)' ) ;
53+ scrollTo ( 0 , 768 * 2 ) ;
4454 expect ( element ( by . css ( '.large-element.sn-viewport-in' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
4555
46- browser . executeScript ( 'window. scrollTo(0,0)' ) ;
56+ scrollTo ( ) ;
4757 expect ( element ( by . css ( '.large-element.sn-viewport-in' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
4858 } ) ;
4959
5060 it ( 'should add `in-viewport` class to element inside a scrollable element' , ( ) => {
51- browser . executeScript ( 'window. scrollTo(0, window.innerHeight * 3)' ) ;
61+ scrollTo ( 0 , 768 * 3 ) ;
5262 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-in' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
5363 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-out' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
5464
55- browser . executeScript ( `document.getElementsByClassName('scrollable')[0].scrollTop = window.innerHeight` ) ;
65+ browser . executeScript ( `document.getElementsByClassName('scrollable')[0].scrollTop = 768` ) ;
66+ browser . sleep ( 200 ) ;
5667 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-in' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
5768 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-out' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
5869
59- browser . executeScript ( `document.getElementsByClassName('scrollable')[0].scrollTop = window.innerHeight * 2` ) ;
70+ browser . executeScript ( `document.getElementsByClassName('scrollable')[0].scrollTop = 768 * 2` ) ;
71+ browser . sleep ( 200 ) ;
6072 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-in' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
6173 expect ( element ( by . css ( '.inside-scrollable.sn-viewport-out' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
6274 } ) ;
0 commit comments