on 00a42e3 help sign in
dodrio/tests/web/render.rs
243 lines 5.7 kB history raw
1use super::{assert_rendered, before_after, create_element, RenderFn};
2use dodrio::{builder::*, Vdom};
3use futures::prelude::*;
4use std::rc::Rc;
5use wasm_bindgen_test::*;
7#[wasm_bindgen_test]
8fn render_initial_text() {
9 let hello = Rc::new(RenderFn(|_bump| text("hello")));
11 let container = create_element("div");
12 let _vdom = Vdom::new(&container, hello.clone());
13 assert_rendered(&container, &hello);
16#[wasm_bindgen_test]
17fn render_initial_node() {
18 let hello = Rc::new(RenderFn(|bump| {
19 div(bump)
20 .attr("id", "hello-world")
21 .children([text("Hello "), span(bump).child(text("World!")).finish()])
22 .finish()
23 }));
25 let container = create_element("div");
26 let _vdom = Vdom::new(&container, hello.clone());
27 assert_rendered(&container, &hello);
30#[wasm_bindgen_test]
31fn container_is_emptied_upon_drop() {
32 let container = create_element("div");
33 let vdom = Vdom::new(&container, RenderFn(|_bump| text("blah")));
34 drop(vdom);
35 assert!(container.first_child().is_none());
38before_after! {
39 same_text {
40 before(_bump) {
41 text("hello")
42 }
43 after(_bump) {
44 text("hello")
45 }
46 }
48 update_text {
49 before(_bump) {
50 text("before")
51 }
52 after(_bump) {
53 text("after")
54 }
55 }
57 replace_text_with_elem {
58 before(_bump) {
59 text("before")
60 }
61 after(bump) {
62 div(bump).finish()
63 }
64 }
66 replace_elem_with_text {
67 before(bump) {
68 div(bump).finish()
69 }
70 after(_bump) {
71 text("before")
72 }
73 }
75 same_elem {
76 before(bump) {
77 div(bump).finish()
78 }
79 after(bump) {
80 div(bump).finish()
81 }
82 }
84 elems_with_different_tag_names {
85 before(bump) {
86 span(bump).finish()
87 }
88 after(bump) {
89 div(bump).finish()
90 }
91 }
93 same_tag_name_update_attribute {
94 before(bump) {
95 div(bump).attr("value", "1").finish()
96 }
97 after(bump) {
98 div(bump).attr("value", "2").finish()
99 }
100 }
102 same_tag_name_remove_attribute {
103 before(bump) {
104 div(bump).attr("value", "1").finish()
105 }
106 after(bump) {
107 div(bump).finish()
108 }
109 }
111 same_tag_name_add_attribute {
112 before(bump) {
113 div(bump).finish()
114 }
115 after(bump) {
116 div(bump).attr("value", "2").finish()
117 }
118 }
120 same_tag_name_many_attributes {
121 before(bump) {
122 div(bump)
123 .attr("before-1", "1")
124 .attr("shared-1", "1")
125 .attr("modified-1", "1")
126 .attr("before-2", "2")
127 .attr("shared-2", "2")
128 .attr("modified-2", "2")
129 .attr("before-3", "3")
130 .attr("shared-3", "3")
131 .attr("modified-3", "3")
132 .finish()
133 }
134 after(bump) {
135 div(bump)
136 .attr("after-1", "1")
137 .attr("shared-1", "1")
138 .attr("modified-1", "100")
139 .attr("after-2", "2")
140 .attr("shared-2", "2")
141 .attr("modified-2", "200")
142 .attr("after-3", "3")
143 .attr("shared-3", "3")
144 .attr("modified-3", "300")
145 .finish()
146 }
147 }
149 same_tag_same_children {
150 before(bump) {
151 div(bump).child(text("child")).finish()
152 }
153 after(bump) {
154 div(bump).child(text("child")).finish()
155 }
156 }
158 same_tag_update_child {
159 before(bump) {
160 div(bump).child(text("before")).finish()
161 }
162 after(bump) {
163 div(bump).child(text("after")).finish()
164 }
165 }
167 same_tag_add_child {
168 before(bump) {
169 div(bump).finish()
170 }
171 after(bump) {
172 div(bump).child(text("child")).finish()
173 }
174 }
176 same_tag_remove_child {
177 before(bump) {
178 div(bump).child(text("child")).finish()
179 }
180 after(bump) {
181 div(bump).finish()
182 }
183 }
185 same_tag_update_many_children {
186 before(bump) {
187 div(bump)
188 .children([
189 div(bump).finish(),
190 span(bump).finish(),
191 p(bump).finish(),
192 ])
193 .finish()
194 }
195 after(bump) {
196 div(bump)
197 .children([
198 span(bump).finish(),
199 p(bump).finish(),
200 div(bump).finish(),
201 ])
202 .finish()
203 }
204 }
206 same_tag_remove_many_children {
207 before(bump) {
208 div(bump)
209 .children([
210 div(bump).finish(),
211 span(bump).finish(),
212 p(bump).finish(),
213 ])
214 .finish()
215 }
216 after(bump) {
217 div(bump)
218 .children([
219 div(bump).finish(),
220 ])
221 .finish()
222 }
223 }
225 same_tag_add_many_children {
226 before(bump) {
227 div(bump)
228 .children([
229 div(bump).finish(),
230 ])
231 .finish()
232 }
233 after(bump) {
234 div(bump)
235 .children([
236 div(bump).finish(),
237 span(bump).finish(),
238 p(bump).finish(),
239 ])
240 .finish()
241 }
242 }