|
5 | 5 | import os
|
6 | 6 | import sys
|
7 | 7 | import time
|
| 8 | +import json |
8 | 9 | import pandas as pd
|
9 | 10 |
|
10 | 11 | import dash
|
@@ -531,7 +532,7 @@ def on_click(n_clicks):
|
531 | 532 | }
|
532 | 533 | ]
|
533 | 534 | }
|
534 |
| - |
| 535 | + |
535 | 536 | self.startServer(app=app)
|
536 | 537 |
|
537 | 538 | button_one = self.wait_for_element_by_css_selector('#one')
|
@@ -932,6 +933,7 @@ def update_output(start_date, end_date):
|
932 | 933 | end_date.click()
|
933 | 934 |
|
934 | 935 | self.assertEquals(date_content.text, '1997-05-03 - 1997-05-04')
|
| 936 | + |
935 | 937 | def test_interval(self):
|
936 | 938 | app = dash.Dash(__name__)
|
937 | 939 | app.layout = html.Div([
|
@@ -1141,3 +1143,60 @@ def render_content(click, prev_graph):
|
1141 | 1143 | button.click()
|
1142 | 1144 | time.sleep(2) # Wait for graph to re-render
|
1143 | 1145 | self.snapshot('render-empty-graph')
|
| 1146 | + |
| 1147 | + def test_storage_component(self): |
| 1148 | + app = dash.Dash(__name__) |
| 1149 | + |
| 1150 | + getter = 'return window.sessionStorage.getItem("{}");' |
| 1151 | + clicked_getter = getter.format('storage') |
| 1152 | + dummy_getter = getter.format('dummy') |
| 1153 | + dummy_data = 'Hello world' |
| 1154 | + |
| 1155 | + app.layout = html.Div([ |
| 1156 | + dcc.Storage(id='storage', |
| 1157 | + storage_type='session'), |
| 1158 | + html.Button('click me', id='btn'), |
| 1159 | + html.Button('clear', id='clear-btn'), |
| 1160 | + dcc.Storage(id='dummy', |
| 1161 | + storage_type='session', |
| 1162 | + data=dummy_data) |
| 1163 | + ]) |
| 1164 | + |
| 1165 | + @app.callback(Output('storage', 'data'), |
| 1166 | + [Input('btn', 'n_clicks')], |
| 1167 | + [State('storage', 'data')]) |
| 1168 | + def on_click(n_clicks, storage): |
| 1169 | + if n_clicks is None: |
| 1170 | + return |
| 1171 | + storage = storage or {} |
| 1172 | + return {'clicked': storage.get('clicked', 0) + 1} |
| 1173 | + |
| 1174 | + @app.callback(Output('storage', 'clear_data'), |
| 1175 | + [Input('clear-btn', 'n_clicks')]) |
| 1176 | + def on_clear(n_clicks): |
| 1177 | + if n_clicks is None: |
| 1178 | + return |
| 1179 | + return True |
| 1180 | + |
| 1181 | + self.startServer(app) |
| 1182 | + |
| 1183 | + time.sleep(1) |
| 1184 | + |
| 1185 | + dummy = self.driver.execute_script(dummy_getter) |
| 1186 | + self.assertEqual(dummy_data, dummy) |
| 1187 | + |
| 1188 | + click_btn = self.wait_for_element_by_css_selector('#btn') |
| 1189 | + clear_btn = self.wait_for_element_by_css_selector('#clear-btn') |
| 1190 | + |
| 1191 | + for i in range(10): |
| 1192 | + click_btn.click() |
| 1193 | + time.sleep(0.5) |
| 1194 | + |
| 1195 | + click_data = json.loads(self.driver.execute_script(clicked_getter)) |
| 1196 | + self.assertEqual(i+1, click_data.get('clicked')) |
| 1197 | + |
| 1198 | + clear_btn.click() |
| 1199 | + time.sleep(0.5) |
| 1200 | + |
| 1201 | + cleared_data = self.driver.execute_script(clicked_getter) |
| 1202 | + self.assertTrue(cleared_data is None) |
0 commit comments