Skip to content

Commit 84acbab

Browse files
committed
Add test for assets.
1 parent ff1cff3 commit 84acbab

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

tests/assets/load_first.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.tested = ['load_first'];

tests/assets/nested_css/nested.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#content {
2+
padding: 8px;
3+
}

tests/assets/nested_js/load_after.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.tested.push('load_after');

tests/assets/nested_js/load_after1.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
window.tested.push('load_after1');
2+
document.getElementById('tested').innerHTML = JSON.stringify(window.tested);

tests/assets/reset.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body {margin: 0;}

tests/test_integration.py

+52
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from multiprocessing import Value
23
import datetime
34
import itertools
@@ -322,6 +323,9 @@ def test_index_customization(self):
322323
throw Error('could not find container to add');
323324
}
324325
elem.innerHTML = 'Got added';
326+
var config = {};
327+
fetch('/nonexist').then(r => r.json())
328+
.then(r => config = r).catch(err => ({config}));
325329
</script>
326330
</body>
327331
</html>
@@ -344,3 +348,51 @@ def test_index_customization(self):
344348
self.assertEqual('Got added', add.text)
345349

346350
self.percy_snapshot('custom-index')
351+
352+
def test_assets(self):
353+
app = dash.Dash(assets_folder='tests/assets')
354+
app.index_string = '''
355+
<!DOCTYPE html>
356+
<html>
357+
<head>
358+
{metas}
359+
<title>{title}</title>
360+
{css}
361+
</head>
362+
<body>
363+
<div id="tested"></div>
364+
{app_entry}
365+
<footer>
366+
{config}
367+
{scripts}
368+
</footer>
369+
</body>
370+
</html>
371+
'''
372+
373+
app.layout = html.Div([
374+
html.Div(id='content'),
375+
dcc.Input(id='test')
376+
], id='layout')
377+
378+
self.startServer(app)
379+
380+
body = self.driver.find_element_by_tag_name('body')
381+
382+
body_margin = body.value_of_css_property('margin')
383+
self.assertEqual('0px', body_margin)
384+
385+
content = self.wait_for_element_by_id('content')
386+
content_padding = content.value_of_css_property('padding')
387+
self.assertEqual('8px', content_padding)
388+
389+
tested = self.wait_for_element_by_id('tested')
390+
tested = json.loads(tested.text)
391+
self.assertEqual(3, len(tested))
392+
393+
order = ('load_first', 'load_after', 'load_after1')
394+
395+
for i in range(3):
396+
self.assertEqual(order[i], tested[i])
397+
398+
self.percy_snapshot('test assets includes')

0 commit comments

Comments
 (0)