forked from h2oai/wave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_by_name_updates.py
211 lines (165 loc) · 5.55 KB
/
test_by_name_updates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import os
import signal
from utils import start_waved, AppRunner
import pytest
from playwright.sync_api import Page, expect
@pytest.fixture(scope='module', autouse=True)
def setup_teardown():
waved_p = None
expect.set_options(timeout=10_000)
try:
waved_p = start_waved()
yield
finally:
if waved_p:
os.killpg(os.getpgid(waved_p.pid), signal.SIGTERM)
def test_by_name_updates(page: Page):
code = '''
from h2o_wave import Q, ui, main, app
@app('/')
async def serve(q: Q):
q.page['wizard'] = ui.form_card(box='1 1 2 4', items=[
ui.text_xl(name='text_name', content='Wizard'),
ui.inline(items=[
ui.button(name='back', label='Back'),
]),
])
q.page['wizard'].text_name.content = 'foo1'
q.page['wizard'].back.label = 'foo2'
q.page['header'] = ui.header_card(box='4 6 4 1', title='Header', subtitle='Subtitle', secondary_items=[
ui.button(name='button_name', label='Button'),
])
q.page['header'].button_name.label = 'foo3'
q.page['example'] = ui.form_card(box='5 1 4 5', items=[
ui.buttons([
ui.button(name='primary_button', label='Primary', primary=True),
]),
])
q.page['example'].primary_button.label = 'foo4'
q.page['nav'] = ui.tab_card(
box='1 6 4 1',
items=[
ui.tab(name='#hash', label='Spam'),
ui.tab(name='plaintext', label='Ham'),
],
)
q.page['nav']['#hash'].label = 'foo5'
q.page['nav'].plaintext.label = 'foo6'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("foo1")).to_be_visible()
expect(page.get_by_text("foo2")).to_be_visible()
expect(page.get_by_text("foo3")).to_be_visible()
expect(page.get_by_text("foo4")).to_be_visible()
expect(page.get_by_text("foo5")).to_be_visible()
expect(page.get_by_text("foo6")).to_be_visible()
def test_by_name_updates_dialog_init(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='', dialog=ui.dialog(title='Order Donuts', items=[
ui.button(name='next_step', label='Next')
]))
q.page['meta'].next_step.label = 'New next'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New next")).to_be_visible()
def test_by_name_updates_dialog(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='')
q.page['meta'].dialog = ui.dialog(title='Order Donuts', items=[
ui.button(name='next_step', label='Next')
])
q.page['meta'].next_step.label = 'New next'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New next")).to_be_visible()
def test_by_name_updates_side_panel_init(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='', side_panel=ui.side_panel(title='Order Donuts', items=[
ui.button(name='next_step', label='Next')
]))
q.page['meta'].next_step.label = 'New next'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New next")).to_be_visible()
def test_by_name_updates_side_panel(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='')
q.page['meta'].side_panel = ui.side_panel(title='Order Donuts', items=[
ui.button(name='next_step', label='Next')
])
q.page['meta'].next_step.label = 'New next'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New next")).to_be_visible()
def test_by_name_updates_notification_bar_init(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='', notification_bar=ui.notification_bar(
text='Success notification',
buttons=[ui.button(name='btn1', label='Button 1')]
))
q.page['meta'].btn1.label = 'New text'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New text")).to_be_visible()
def test_by_name_updates_notification_bar(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['meta'] = ui.meta_card(box='')
q.page['meta'].notification_bar = ui.notification_bar(
text='Success notification',
buttons=[ui.button(name='btn1', label='Button 1')]
)
q.page['meta'].btn1.label = 'New text'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
expect(page.get_by_text("New text")).to_be_visible()
def test_by_name_updates_card_commands(page: Page):
code = '''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['form'] = ui.form_card(
box='1 1 3 3',
items=[],
commands=[
ui.command(name='step1', label='Step 1'),
]
)
q.page['form'].step1.label = 'New text'
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
page.click('[data-test="form"]:nth-child(2) > div')
expect(page.get_by_text("New text")).to_be_visible()