-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
test_reactive.py
126 lines (72 loc) · 3.05 KB
/
test_reactive.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
import param
import pytest
pytest.importorskip("playwright")
from playwright.sync_api import expect
from panel.reactive import ReactiveHTML
from panel.tests.util import serve_component, wait_until
pytestmark = pytest.mark.ui
class ReactiveComponent(ReactiveHTML):
count = param.Integer(default=0)
event = param.Event()
_template = """
<div id="reactive" class="reactive" onclick="${script('click')}"></div>
"""
_scripts = {
'render': 'data.count += 1; reactive.innerText = `${data.count}`;',
'click': 'data.count += 1; reactive.innerText = `${data.count}`;',
'event': 'data.count += 1; reactive.innerText = `${data.count}`;',
}
class ReactiveLiteral(ReactiveHTML):
value = param.String()
_template = """
<div class="reactive">{{value}}</div>
"""
def test_reactive_html_click_js_event(page):
component = ReactiveComponent()
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('1')
page.locator(".reactive").click()
expect(page.locator(".reactive")).to_have_text('2')
wait_until(lambda: component.count == 2, page)
def test_reactive_html_param_event(page):
component = ReactiveComponent()
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('1')
component.param.trigger('event')
expect(page.locator(".reactive")).to_have_text('2')
component.param.trigger('event')
expect(page.locator(".reactive")).to_have_text('3')
component.param.trigger('event')
component.param.trigger('event')
expect(page.locator(".reactive")).to_have_text('5')
wait_until(lambda: component.count == 5, page)
def test_reactive_html_set_loading_no_rerender(page):
component = ReactiveComponent()
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('1')
component.loading = True
expect(page.locator(".reactive")).to_have_text('1')
component.loading = False
expect(page.locator(".reactive")).to_have_text('1')
def test_reactive_html_changing_css_classes_rerenders(page):
component = ReactiveComponent()
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('1')
component.css_classes = ['custom']
expect(page.locator(".reactive")).to_have_text('1')
component.loading = True
expect(page.locator(".reactive")).to_have_text('1')
component.css_classes = []
expect(page.locator(".reactive")).to_have_text('1')
def test_reactive_html_set_background_no_rerender(page):
component = ReactiveComponent()
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('1')
component.styles = dict(background='red')
expect(page.locator(".reactive")).to_have_text('1')
component.styles = dict(background='green')
expect(page.locator(".reactive")).to_have_text('1')
def test_reactive_literal_backtick(page):
component = ReactiveLiteral(value="Backtick: `")
serve_component(page, component)
expect(page.locator(".reactive")).to_have_text('Backtick: `')