@@ -2,6 +2,12 @@ import { browser, element, by } from 'protractor';
2
2
3
3
describe ( 'ScrollSpy Lib E2E Tests' , function ( ) {
4
4
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
+
5
11
beforeEach ( ( ) => browser . get ( '' ) ) ;
6
12
7
13
afterEach ( ( ) => {
@@ -14,4 +20,29 @@ describe('ScrollSpy Lib E2E Tests', function () {
14
20
expect ( element ( by . css ( '[snScrollSpy]' ) ) . isPresent ( ) ) . toBeTruthy ( ) ;
15
21
} ) ;
16
22
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
+
17
48
} ) ;
0 commit comments