Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store component #248

Merged
merged 17 commits into from Oct 3, 2018

Add test for Storage component.

  • Loading branch information...
T4rk1n committed Jul 27, 2018
commit 7d2241fd58d887673e6608858aec80c69d074b2e
@@ -5,6 +5,7 @@
import os
import sys
import time
import json
import pandas as pd

import dash
@@ -531,7 +532,7 @@ def on_click(n_clicks):
}
]
}

self.startServer(app=app)

button_one = self.wait_for_element_by_css_selector('#one')
@@ -951,6 +952,7 @@ def update_output(start_date, end_date):
end_date.click()

self.assertEquals(date_content.text, '1997-05-03 - 1997-05-04')

def test_interval(self):
app = dash.Dash(__name__)
app.layout = html.Div([
@@ -1160,3 +1162,60 @@ def render_content(click, prev_graph):
button.click()
time.sleep(2) # Wait for graph to re-render
self.snapshot('render-empty-graph')

def test_storage_component(self):
app = dash.Dash(__name__)

getter = 'return window.sessionStorage.getItem("{}");'
clicked_getter = getter.format('storage')
dummy_getter = getter.format('dummy')
dummy_data = 'Hello world'

app.layout = html.Div([
dcc.Storage(id='storage',
storage_type='session'),
html.Button('click me', id='btn'),
html.Button('clear', id='clear-btn'),
dcc.Storage(id='dummy',
storage_type='session',
data=dummy_data)
])

@app.callback(Output('storage', 'data'),
[Input('btn', 'n_clicks')],
[State('storage', 'data')])
def on_click(n_clicks, storage):
if n_clicks is None:
return
storage = storage or {}
return {'clicked': storage.get('clicked', 0) + 1}

@app.callback(Output('storage', 'clear_data'),
[Input('clear-btn', 'n_clicks')])
def on_clear(n_clicks):
if n_clicks is None:
return
return True

self.startServer(app)

time.sleep(1)

dummy = self.driver.execute_script(dummy_getter)
self.assertEqual(dummy_data, dummy)

click_btn = self.wait_for_element_by_css_selector('#btn')
clear_btn = self.wait_for_element_by_css_selector('#clear-btn')

for i in range(10):
click_btn.click()
time.sleep(0.5)

click_data = json.loads(self.driver.execute_script(clicked_getter))
self.assertEqual(i+1, click_data.get('clicked'))

clear_btn.click()
time.sleep(0.5)

cleared_data = self.driver.execute_script(clicked_getter)
self.assertTrue(cleared_data is None)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.