@@ -2,6 +2,12 @@ import { browser, element, by } from 'protractor';
22
33describe ( 'ScrollSpy Lib E2E Tests' , function ( ) {
44
5+ const scrollToSection = ( n : number ) => {
6+ const script = `window.scrollTo(0, (window.innerHeight * ${ n - 1 } ) + 80)` ;
7+ browser . executeScript ( script ) ;
8+ browser . sleep ( 100 ) ;
9+ } ;
10+
511 beforeEach ( ( ) => browser . get ( '' ) ) ;
612
713 afterEach ( ( ) => {
@@ -14,4 +20,29 @@ describe('ScrollSpy Lib E2E Tests', function () {
1420 expect ( element ( by . css ( '[snScrollSpy]' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
1521 } ) ;
1622
23+ it ( 'should add active class to sections' , ( ) => {
24+ expect ( element ( by . css ( '[href="#section1"].active' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
25+ expect ( element ( by . css ( '[href="#section2"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
26+ expect ( element ( by . css ( '[href="#section3"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
27+ expect ( element ( by . css ( '[href="#section4"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
28+
29+ scrollToSection ( 2 ) ;
30+ expect ( element ( by . css ( '[href="#section1"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
31+ expect ( element ( by . css ( '[href="#section2"].active' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
32+ expect ( element ( by . css ( '[href="#section3"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
33+ expect ( element ( by . css ( '[href="#section4"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
34+
35+ scrollToSection ( 3 ) ;
36+ expect ( element ( by . css ( '[href="#section1"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
37+ expect ( element ( by . css ( '[href="#section2"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
38+ expect ( element ( by . css ( '[href="#section3"].active' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
39+ expect ( element ( by . css ( '[href="#section4"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
40+
41+ scrollToSection ( 4 ) ;
42+ expect ( element ( by . css ( '[href="#section1"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
43+ expect ( element ( by . css ( '[href="#section2"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
44+ expect ( element ( by . css ( '[href="#section3"].active' ) ) . isPresent ( ) ) . toBeFalsy ( ) ;
45+ expect ( element ( by . css ( '[href="#section4"].active' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
46+ } ) ;
47+
1748} ) ;
0 commit comments