@@ -452,3 +452,95 @@ def test_pch005_clientside_duplicate(dash_duo):
452
452
453
453
dash_duo .find_element ("#click2" ).click ()
454
454
dash_duo .wait_for_text_to_equal ("#output" , "click2" )
455
+
456
+
457
+ def test_pch006_base_operators (dash_duo ):
458
+ app = Dash ()
459
+
460
+ app .layout = [
461
+ dcc .Store (data = 2 , id = "store" ),
462
+ html .Button ("add-one" , id = "add-one" ),
463
+ html .Button ("remove-one" , id = "remove-one" ),
464
+ html .Button ("mul-two" , id = "mul-two" ),
465
+ html .Button ("div-two" , id = "div-two" ),
466
+ html .Button ("merge" , id = "merge" ),
467
+ dcc .Store (data = {"initial" : "initial" }, id = "dict-store" ),
468
+ html .Div (id = "store-output" ),
469
+ html .Div (id = "dict-store-output" ),
470
+ ]
471
+
472
+ @app .callback (
473
+ Output ("store" , "data" ), Input ("add-one" , "n_clicks" ), prevent_initial_call = True
474
+ )
475
+ def on_add (_ ):
476
+ patched = Patch ()
477
+ patched += 1
478
+ return patched
479
+
480
+ @app .callback (
481
+ Output ("store" , "data" , allow_duplicate = True ),
482
+ Input ("remove-one" , "n_clicks" ),
483
+ prevent_initial_call = True ,
484
+ )
485
+ def on_remove (_ ):
486
+ patched = Patch ()
487
+ patched -= 1
488
+ return patched
489
+
490
+ @app .callback (
491
+ Output ("store" , "data" , allow_duplicate = True ),
492
+ Input ("mul-two" , "n_clicks" ),
493
+ prevent_initial_call = True ,
494
+ )
495
+ def on_mul (_ ):
496
+ patched = Patch ()
497
+ patched *= 2
498
+ return patched
499
+
500
+ @app .callback (
501
+ Output ("store" , "data" , allow_duplicate = True ),
502
+ Input ("div-two" , "n_clicks" ),
503
+ prevent_initial_call = True ,
504
+ )
505
+ def on_div (_ ):
506
+ patched = Patch ()
507
+ patched /= 2
508
+ return patched
509
+
510
+ @app .callback (
511
+ Output ("dict-store" , "data" , allow_duplicate = True ),
512
+ Input ("merge" , "n_clicks" ),
513
+ prevent_initial_call = True ,
514
+ )
515
+ def on_merge (_ ):
516
+ patched = Patch ()
517
+ patched |= {"merged" : "merged" }
518
+ return patched
519
+
520
+ app .clientside_callback (
521
+ "data => data" , Output ("store-output" , "children" ), Input ("store" , "data" )
522
+ )
523
+ app .clientside_callback (
524
+ "data => JSON.stringify(data)" ,
525
+ Output ("dict-store-output" , "children" ),
526
+ Input ("dict-store" , "data" ),
527
+ )
528
+
529
+ dash_duo .start_server (app )
530
+
531
+ dash_duo .find_element ("#add-one" ).click ()
532
+ dash_duo .wait_for_text_to_equal ("#store-output" , "3" )
533
+
534
+ dash_duo .find_element ("#remove-one" ).click ()
535
+ dash_duo .wait_for_text_to_equal ("#store-output" , "2" )
536
+
537
+ dash_duo .find_element ("#mul-two" ).click ()
538
+ dash_duo .wait_for_text_to_equal ("#store-output" , "4" )
539
+
540
+ dash_duo .find_element ("#div-two" ).click ()
541
+ dash_duo .wait_for_text_to_equal ("#store-output" , "2" )
542
+
543
+ dash_duo .find_element ("#merge" ).click ()
544
+ dash_duo .wait_for_text_to_equal (
545
+ "#dict-store-output" , '{"initial":"initial","merged":"merged"}'
546
+ )
0 commit comments