12
12
import dash_html_components as html
13
13
import dash_core_components as dcc
14
14
import dash_table_experiments as dt
15
- from dash .exceptions import PreventUpdate
16
15
from selenium import webdriver
17
16
from selenium .webdriver .common .keys import Keys
18
17
from selenium .common .exceptions import InvalidElementStateException
@@ -225,7 +224,7 @@ def test_gallery(self):
225
224
dcc .Upload (),
226
225
227
226
html .Label ('Horizontal Tabs' ),
228
- dcc .Tabs (id = "tabs" , children = [
227
+ dcc .Tabs (id = "horizontal- tabs" , children = [
229
228
dcc .Tab (label = 'Tab one' , className = 'test' , style = {'border' : '1px solid magenta' }, children = [
230
229
html .Div (['Test' ])
231
230
]),
@@ -255,7 +254,7 @@ def test_gallery(self):
255
254
),
256
255
257
256
html .Label ('Vertical Tabs' ),
258
- dcc .Tabs (id = "tabs1 " , vertical = True , children = [
257
+ dcc .Tabs (id = "tabs " , vertical = True , children = [
259
258
dcc .Tab (label = 'Tab one' , children = [
260
259
html .Div (['Test' ])
261
260
]),
@@ -457,123 +456,6 @@ def render_content(tab):
457
456
time .sleep (2 )
458
457
self .assertEqual (tabs_content .text , 'Test content 1' )
459
458
460
- def test_tabs_with_children_undefined (self ):
461
- app = dash .Dash (__name__ )
462
-
463
- app .layout = html .Div ([
464
- html .H1 ('Dash Tabs component demo' ),
465
- dcc .Tabs (id = "tabs" , value = 'tab-1' ),
466
- html .Div (id = 'tabs-content' )
467
- ])
468
-
469
- self .startServer (app = app )
470
-
471
- self .snapshot ('Tabs component with children undefined' )
472
-
473
- def test_tabs_render_without_selected (self ):
474
- app = dash .Dash (__name__ )
475
-
476
- data = [
477
- {'id' : 'one' , 'value' : 1 },
478
- {'id' : 'two' , 'value' : 2 },
479
- ]
480
-
481
-
482
- menu = html .Div ([
483
- html .Div ('one' , id = 'one' ),
484
- html .Div ('two' , id = 'two' )
485
- ])
486
-
487
- tabs_one = html .Div ([
488
- dcc .Tabs ([
489
- dcc .Tab (dcc .Graph (id = 'graph-one' ), label = 'tab-one-one' ),
490
- ])
491
- ], id = 'tabs-one' , style = {'display' : 'none' })
492
-
493
- tabs_two = html .Div ([
494
- dcc .Tabs ([
495
- dcc .Tab (dcc .Graph (id = 'graph-two' ), label = 'tab-two-one' ),
496
- ])
497
- ], id = 'tabs-two' , style = {'display' : 'none' })
498
-
499
-
500
- app .layout = html .Div ([
501
- menu ,
502
- tabs_one ,
503
- tabs_two
504
- ])
505
-
506
- for i in ('one' , 'two' ):
507
-
508
- @app .callback (Output ('tabs-{}' .format (i ), 'style' ),
509
- [Input (i , 'n_clicks' )])
510
- def on_click (n_clicks ):
511
- if n_clicks is None :
512
- raise PreventUpdate
513
-
514
- if n_clicks % 2 == 1 :
515
- return {'display' : 'block' }
516
- return {'display' : 'none' }
517
-
518
-
519
- @app .callback (Output ('graph-{}' .format (i ), 'figure' ),
520
- [Input (i , 'n_clicks' )])
521
- def on_click (n_clicks ):
522
- if n_clicks is None :
523
- raise PreventUpdate
524
-
525
- return {
526
- 'data' : [
527
- {
528
- 'x' : [1 ,2 ,3 ,4 ],
529
- 'y' : [4 ,3 ,2 ,1 ]
530
- }
531
- ]
532
- }
533
-
534
- self .startServer (app = app )
535
-
536
- button_one = self .wait_for_element_by_css_selector ('#one' )
537
- button_two = self .wait_for_element_by_css_selector ('#two' )
538
-
539
- button_one .click ()
540
-
541
- self .snapshot ("Tabs 1 rendered " )
542
-
543
- button_two .click ()
544
- time .sleep (1 )
545
-
546
- self .snapshot ("Tabs 2 rendered " )
547
-
548
- def test_tabs_without_value (self ):
549
- app = dash .Dash (__name__ )
550
-
551
- app .layout = html .Div ([
552
- html .H1 ('Dash Tabs component demo' ),
553
- dcc .Tabs (id = "tabs-example" , children = [
554
- dcc .Tab (label = 'Tab One' , value = 'tab-1-example' ),
555
- dcc .Tab (label = 'Tab Two' , value = 'tab-2-example' ),
556
- ]),
557
- html .Div (id = 'tabs-content-example' )
558
- ])
559
-
560
-
561
- @app .callback (Output ('tabs-content-example' , 'children' ),
562
- [Input ('tabs-example' , 'value' )])
563
- def render_content (tab ):
564
- if tab == 'tab-1-example' :
565
- return html .H3 ('Default selected Tab content 1' )
566
- elif tab == 'tab-2-example' :
567
- return html .H3 ('Tab content 2' )
568
-
569
- self .startServer (app = app )
570
-
571
- default_tab_content = self .wait_for_element_by_css_selector ('#tabs-content-example' )
572
-
573
- self .assertEqual (default_tab_content .text , 'Default selected Tab content 1' )
574
-
575
- self .snapshot ('Tab 1 should be selected by default' )
576
-
577
459
def test_location_link (self ):
578
460
app = dash .Dash (__name__ )
579
461
@@ -724,8 +606,6 @@ def display_page(pathname):
724
606
725
607
self .startServer (app = app )
726
608
727
- time .sleep (2 )
728
-
729
609
#callback is called twice when defined
730
610
self .assertEqual (
731
611
call_count .value ,
@@ -750,7 +630,7 @@ def display_page(pathname):
750
630
#test if callback is only fired once (offset of 2)
751
631
self .assertEqual (
752
632
call_count .value ,
753
- 3
633
+ 2 + 1
754
634
)
755
635
756
636
def test_candlestick (self ):
@@ -861,16 +741,17 @@ def _on_confirmed(submit_n_clicks, cancel_n_clicks,
861
741
if not submit_n_clicks and not cancel_n_clicks :
862
742
return ''
863
743
count .value += 1
864
- if (submit_timestamp and cancel_timestamp is None ) or \
865
- (submit_timestamp and cancel_timestamp ):
744
+ if (
745
+ (submit_timestamp and not cancel_timestamp ) or
746
+ (submit_timestamp > cancel_timestamp )
747
+ ):
866
748
return 'confirmed'
867
749
else :
868
750
return 'canceled'
869
751
870
752
self .startServer (app )
871
753
self .snapshot (test_name + ' -> initial' )
872
754
button = self .wait_for_element_by_css_selector ('#button' )
873
- print (button )
874
755
875
756
button .click ()
876
757
time .sleep (1 )
@@ -960,30 +841,3 @@ def on_click(n_clicks):
960
841
time .sleep (2 )
961
842
962
843
self .driver .switch_to .alert .accept ()
963
-
964
- def test_empty_graph (self ):
965
- app = dash .Dash (__name__ )
966
-
967
- app .layout = html .Div ([
968
- html .Button (id = 'click' , children = 'Click me' ),
969
- dcc .Graph (
970
- id = 'graph' ,
971
- figure = {
972
- 'data' : [dict (x = [1 , 2 , 3 ], y = [1 , 2 , 3 ], type = 'scatter' )]
973
- }
974
- )
975
- ])
976
-
977
- @app .callback (dash .dependencies .Output ('graph' , 'figure' ),
978
- [dash .dependencies .Input ('click' , 'n_clicks' )],
979
- [dash .dependencies .State ('graph' , 'figure' )])
980
- def render_content (click , prev_graph ):
981
- if click :
982
- return {}
983
- return prev_graph
984
-
985
- self .startServer (app )
986
- button = self .wait_for_element_by_css_selector ('#click' )
987
- button .click ()
988
- time .sleep (2 ) # Wait for graph to re-render
989
- self .snapshot ('render-empty-graph' )
0 commit comments