1- import pattern from "./scroll-box" ;
1+ import pattern , { parser } from "./scroll-box" ;
22import utils from "../../core/utils" ;
33import events from "../../core/events" ;
44
55describe ( "pat-scroll-box" , function ( ) {
6+ let orig_timeout ;
7+ let custom_timeout = 10 ; // reduced timeout for faster testing
8+ beforeEach ( function ( ) {
9+ orig_timeout = parser . parameters [ "timeout-stop" ] . value ;
10+ parser . parameters [ "timeout-stop" ] . value = custom_timeout ;
11+ } ) ;
12+
613 afterEach ( function ( ) {
714 jest . restoreAllMocks ( ) ;
815 document . body . innerHTML = "" ;
16+ parser . parameters [ "timeout-stop" ] . value = orig_timeout ;
917 } ) ;
1018
11- it ( "1 - Basic functionality" , async function ( ) {
19+ it ( "Basic functionality" , async function ( ) {
1220 document . body . innerHTML = `
1321 <div id="el1" style="overflow: scroll"></div>
1422 ` ;
@@ -28,6 +36,8 @@ describe("pat-scroll-box", function () {
2836 expect ( el . classList ) . not . toContain ( "scroll-position-bottom" ) ;
2937 expect ( el . classList ) . not . toContain ( "scroll-up" ) ;
3038 expect ( el . classList ) . not . toContain ( "scroll-down" ) ;
39+ expect ( el . classList ) . not . toContain ( "scrolling-up" ) ;
40+ expect ( el . classList ) . not . toContain ( "scrolling-down" ) ;
3141
3242 el . scrollTop = 100 ;
3343 el . dispatchEvent ( events . scroll_event ( ) ) ;
@@ -36,6 +46,8 @@ describe("pat-scroll-box", function () {
3646 expect ( el . classList ) . not . toContain ( "scroll-position-bottom" ) ;
3747 expect ( el . classList ) . not . toContain ( "scroll-up" ) ;
3848 expect ( el . classList ) . toContain ( "scroll-down" ) ;
49+ expect ( el . classList ) . not . toContain ( "scrolling-up" ) ;
50+ expect ( el . classList ) . toContain ( "scrolling-down" ) ;
3951
4052 el . scrollTop = 50 ;
4153 el . dispatchEvent ( events . scroll_event ( ) ) ;
@@ -44,6 +56,8 @@ describe("pat-scroll-box", function () {
4456 expect ( el . classList ) . not . toContain ( "scroll-position-bottom" ) ;
4557 expect ( el . classList ) . toContain ( "scroll-up" ) ;
4658 expect ( el . classList ) . not . toContain ( "scroll-down" ) ;
59+ expect ( el . classList ) . toContain ( "scrolling-up" ) ;
60+ expect ( el . classList ) . not . toContain ( "scrolling-down" ) ;
4761
4862 el . scrollTop = 200 ;
4963 el . dispatchEvent ( events . scroll_event ( ) ) ;
@@ -52,6 +66,8 @@ describe("pat-scroll-box", function () {
5266 expect ( el . classList ) . toContain ( "scroll-position-bottom" ) ;
5367 expect ( el . classList ) . not . toContain ( "scroll-up" ) ;
5468 expect ( el . classList ) . toContain ( "scroll-down" ) ;
69+ expect ( el . classList ) . not . toContain ( "scrolling-up" ) ;
70+ expect ( el . classList ) . toContain ( "scrolling-down" ) ;
5571
5672 el . scrollTop = 0 ;
5773 el . dispatchEvent ( events . scroll_event ( ) ) ;
@@ -60,5 +76,33 @@ describe("pat-scroll-box", function () {
6076 expect ( el . classList ) . not . toContain ( "scroll-position-bottom" ) ;
6177 expect ( el . classList ) . toContain ( "scroll-up" ) ;
6278 expect ( el . classList ) . not . toContain ( "scroll-down" ) ;
79+ expect ( el . classList ) . toContain ( "scrolling-up" ) ;
80+ expect ( el . classList ) . not . toContain ( "scrolling-down" ) ;
81+
82+ // Test for clearing the scrolling classes after a scroll stop
83+ // Still there...
84+ await utils . timeout ( custom_timeout / 2 ) ;
85+ expect ( el . classList ) . toContain ( "scrolling-up" ) ;
86+ // Now gone
87+ await utils . timeout ( custom_timeout / 2 + 1 ) ;
88+ expect ( el . classList ) . not . toContain ( "scrolling-up" ) ;
89+
90+ el . scrollTop = 100 ;
91+ el . dispatchEvent ( events . scroll_event ( ) ) ;
92+ await utils . animation_frame ( ) ;
93+ expect ( el . classList ) . not . toContain ( "scroll-position-top" ) ;
94+ expect ( el . classList ) . not . toContain ( "scroll-position-bottom" ) ;
95+ expect ( el . classList ) . not . toContain ( "scroll-up" ) ;
96+ expect ( el . classList ) . toContain ( "scroll-down" ) ;
97+ expect ( el . classList ) . not . toContain ( "scrolling-up" ) ;
98+ expect ( el . classList ) . toContain ( "scrolling-down" ) ;
99+
100+ // Test for clearing the scrolling classes after a scroll stop
101+ // Still there...
102+ await utils . timeout ( custom_timeout / 2 ) ;
103+ expect ( el . classList ) . toContain ( "scrolling-down" ) ;
104+ // Now gone
105+ await utils . timeout ( custom_timeout / 2 + 1 ) ;
106+ expect ( el . classList ) . not . toContain ( "scrolling-down" ) ;
63107 } ) ;
64108} ) ;
0 commit comments