|
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_click_simple(dash_duo):
|
10 |
| - call_count = Value('i', 0) |
| 10 | + call_count = Value("i", 0) |
11 | 11 |
|
12 | 12 | app = dash.Dash(__name__)
|
13 |
| - app.layout = html.Div([ |
14 |
| - html.Div(id='container'), |
15 |
| - html.Button('Click', id='button', n_clicks=0) |
16 |
| - ]) |
17 |
| - |
18 |
| - @app.callback(Output('container', 'children'), Input('button', 'n_clicks')) |
| 13 | + app.layout = html.Div( |
| 14 | + [ |
| 15 | + html.Div(id="container"), |
| 16 | + html.Button("Click", id="button", n_clicks=0), |
| 17 | + html.Iframe(id="video", allow="fullscreen", referrerPolicy="origin"), |
| 18 | + ] |
| 19 | + ) |
| 20 | + |
| 21 | + @app.callback(Output("container", "children"), Input("button", "n_clicks")) |
19 | 22 | def update_output(n_clicks):
|
20 | 23 | call_count.value += 1
|
21 |
| - return 'clicked {} times'.format(n_clicks) |
| 24 | + return "clicked {} times".format(n_clicks) |
22 | 25 |
|
23 | 26 | dash_duo.start_server(app)
|
24 | 27 |
|
25 |
| - dash_duo.find_element('#container') |
| 28 | + dash_duo.find_element("#container") |
26 | 29 |
|
27 |
| - dash_duo.wait_for_text_to_equal( |
28 |
| - '#container', 'clicked 0 times') |
| 30 | + dash_duo.wait_for_text_to_equal("#container", "clicked 0 times") |
29 | 31 | assert call_count.value == 1
|
30 |
| - dash_duo.percy_snapshot('button initialization') |
| 32 | + dash_duo.percy_snapshot("button initialization") |
31 | 33 |
|
32 |
| - dash_duo.find_element('#button').click() |
| 34 | + dash_duo.find_element("#button").click() |
33 | 35 |
|
34 |
| - dash_duo.wait_for_text_to_equal( |
35 |
| - '#container', 'clicked 1 times') |
| 36 | + dash_duo.wait_for_text_to_equal("#container", "clicked 1 times") |
36 | 37 | assert call_count.value == 2
|
37 |
| - dash_duo.percy_snapshot('button click') |
| 38 | + dash_duo.percy_snapshot("button click") |
38 | 39 |
|
39 | 40 | assert not dash_duo.get_logs()
|
40 | 41 |
|
| 42 | + assert dash_duo.find_element("#video").get_attribute("allow") == "fullscreen" |
| 43 | + assert dash_duo.find_element("#video").get_attribute("referrerpolicy") == "origin" |
| 44 | + |
41 | 45 |
|
42 | 46 | def test_click_prev(dash_duo):
|
43 |
| - call_count = Value('i', 0) |
44 |
| - timestamp_1 = Value('d', -5) |
45 |
| - timestamp_2 = Value('d', -5) |
| 47 | + call_count = Value("i", 0) |
| 48 | + timestamp_1 = Value("d", -5) |
| 49 | + timestamp_2 = Value("d", -5) |
46 | 50 |
|
47 | 51 | app = dash.Dash(__name__)
|
48 |
| - app.layout = html.Div([ |
49 |
| - html.Div(id='container'), |
50 |
| - html.Button('Click', id='button-1', n_clicks=0, n_clicks_timestamp=-1), |
51 |
| - html.Button('Click', id='button-2', n_clicks=0, n_clicks_timestamp=-1) |
52 |
| - ]) |
| 52 | + app.layout = html.Div( |
| 53 | + [ |
| 54 | + html.Div(id="container"), |
| 55 | + html.Button("Click", id="button-1", n_clicks=0, n_clicks_timestamp=-1), |
| 56 | + html.Button("Click", id="button-2", n_clicks=0, n_clicks_timestamp=-1), |
| 57 | + ] |
| 58 | + ) |
53 | 59 |
|
54 | 60 | @app.callback(
|
55 |
| - Output('container', 'children'), |
56 |
| - [Input('button-1', 'n_clicks'), |
57 |
| - Input('button-1', 'n_clicks_timestamp'), |
58 |
| - Input('button-2', 'n_clicks'), |
59 |
| - Input('button-2', 'n_clicks_timestamp')]) |
| 61 | + Output("container", "children"), |
| 62 | + [ |
| 63 | + Input("button-1", "n_clicks"), |
| 64 | + Input("button-1", "n_clicks_timestamp"), |
| 65 | + Input("button-2", "n_clicks"), |
| 66 | + Input("button-2", "n_clicks_timestamp"), |
| 67 | + ], |
| 68 | + ) |
60 | 69 | def update_output(*args):
|
61 | 70 | print(args)
|
62 | 71 | call_count.value += 1
|
63 | 72 | timestamp_1.value = args[1]
|
64 | 73 | timestamp_2.value = args[3]
|
65 |
| - return '{}, {}'.format(args[0], args[2]) |
| 74 | + return "{}, {}".format(args[0], args[2]) |
66 | 75 |
|
67 | 76 | dash_duo.start_server(app)
|
68 | 77 |
|
69 |
| - dash_duo.wait_for_text_to_equal('#container', '0, 0') |
| 78 | + dash_duo.wait_for_text_to_equal("#container", "0, 0") |
70 | 79 | assert timestamp_1.value == -1
|
71 | 80 | assert timestamp_2.value == -1
|
72 | 81 | assert call_count.value == 1
|
73 |
| - dash_duo.percy_snapshot('button initialization 1') |
| 82 | + dash_duo.percy_snapshot("button initialization 1") |
74 | 83 |
|
75 |
| - dash_duo.find_element('#button-1').click() |
76 |
| - dash_duo.wait_for_text_to_equal('#container', '1, 0') |
| 84 | + dash_duo.find_element("#button-1").click() |
| 85 | + dash_duo.wait_for_text_to_equal("#container", "1, 0") |
77 | 86 | assert timestamp_1.value > ((time.time() - (24 * 60 * 60)) * 1000)
|
78 | 87 | assert timestamp_2.value == -1
|
79 | 88 | assert call_count.value == 2
|
80 |
| - dash_duo.percy_snapshot('button-1 click') |
| 89 | + dash_duo.percy_snapshot("button-1 click") |
81 | 90 | prev_timestamp_1 = timestamp_1.value
|
82 | 91 |
|
83 |
| - dash_duo.find_element('#button-2').click() |
84 |
| - dash_duo.wait_for_text_to_equal('#container', '1, 1') |
| 92 | + dash_duo.find_element("#button-2").click() |
| 93 | + dash_duo.wait_for_text_to_equal("#container", "1, 1") |
85 | 94 | assert timestamp_1.value == prev_timestamp_1
|
86 | 95 | assert timestamp_2.value > ((time.time() - 24 * 60 * 60) * 1000)
|
87 | 96 | assert call_count.value == 3
|
88 |
| - dash_duo.percy_snapshot('button-2 click') |
| 97 | + dash_duo.percy_snapshot("button-2 click") |
89 | 98 | prev_timestamp_2 = timestamp_2.value
|
90 | 99 |
|
91 |
| - dash_duo.find_element('#button-2').click() |
92 |
| - dash_duo.wait_for_text_to_equal('#container', '1, 2') |
| 100 | + dash_duo.find_element("#button-2").click() |
| 101 | + dash_duo.wait_for_text_to_equal("#container", "1, 2") |
93 | 102 | assert timestamp_1.value == prev_timestamp_1
|
94 | 103 | assert timestamp_2.value > prev_timestamp_2
|
95 | 104 | assert timestamp_2.value > timestamp_1.value
|
96 | 105 | assert call_count.value == 4
|
97 |
| - dash_duo.percy_snapshot('button-2 click again') |
| 106 | + dash_duo.percy_snapshot("button-2 click again") |
98 | 107 |
|
99 | 108 | assert not dash_duo.get_logs()
|
0 commit comments