Skip to content

Commit 8e7210a

Browse files
committed
Added a test for the scrollspy component that ensures the active class is applied on scroll
1 parent 9e9cf75 commit 8e7210a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/scrollspy_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import dash
2+
import dash_html_components as html
3+
import dash_mp_components
4+
5+
"""
6+
Tests the basic scrollspy functionality
7+
Ensures first link is active initially
8+
Ensures second link is active after its item is scrolled to
9+
"""
10+
def test_scrollspy_menu(dash_duo):
11+
app = dash.Dash(__name__)
12+
app.layout = html.Div(className='scrollspy', children=[
13+
dash_mp_components.Scrollspy(
14+
menuGroups=[{'label': 'Table of Contents', 'items': [{'label': 'One', 'targetId': 'one'}, {'label': 'Two', 'targetId': 'two'}, {'label': 'Three', 'targetId': 'three'}]}],
15+
menuClassName="menu",
16+
menuItemContainerClassName="menu-list",
17+
activeClassName="is-active",
18+
offset=0
19+
),
20+
html.Div(className='content', children=[
21+
html.Div(id='one', style={'height': '600px'}, children=[
22+
html.H1('One'),
23+
html.P('lorem ipsum'),
24+
]),
25+
html.Div(id='two', style={'height': '600px'}, children=[
26+
html.H1('Two'),
27+
html.P('lorem ipsum'),
28+
]),
29+
html.Div(id='three', style={'height': '600px'}, children=[
30+
html.H1('Three'),
31+
html.P('lorem ipsum'),
32+
]),
33+
])
34+
])
35+
dash_duo.start_server(app)
36+
dash_duo.driver.set_window_size(1920, 1080)
37+
links = dash_duo.find_elements('a')
38+
assert links[0].text == 'One'
39+
assert links[0].get_attribute('class') == 'is-active'
40+
second_block = dash_duo.find_element('#two')
41+
dash_duo.driver.execute_script("arguments[0].scrollIntoView();", second_block)
42+
assert links[1].get_attribute('class') == 'is-active'

0 commit comments

Comments
 (0)