1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3 use web_sys::{HtmlTableCaptionElement, HtmlTableElement, HtmlTableSectionElement};
4
5 #[wasm_bindgen(module = "/tests/wasm/element.js")]
6 extern "C" {
new_table() -> HtmlTableElement7 fn new_table() -> HtmlTableElement;
new_caption() -> HtmlTableCaptionElement8 fn new_caption() -> HtmlTableCaptionElement;
new_thead() -> HtmlTableSectionElement9 fn new_thead() -> HtmlTableSectionElement;
new_tfoot() -> HtmlTableSectionElement10 fn new_tfoot() -> HtmlTableSectionElement;
11 }
12
13 #[wasm_bindgen_test]
test_table_element()14 fn test_table_element() {
15 let table = new_table();
16 assert!(
17 table.caption().is_none(),
18 "New table element should have no caption element."
19 );
20
21 table.create_caption();
22 assert!(
23 table.caption().is_some(),
24 "Table element should have caption element after create caption."
25 );
26
27 table.delete_caption();
28 assert!(
29 table.caption().is_none(),
30 "Table element should have no caption element after delete caption."
31 );
32
33 table.set_caption(Some(&new_caption()));
34 assert!(
35 table.caption().is_some(),
36 "Table element should have caption element after set."
37 );
38
39 assert!(
40 table.t_head().is_none(),
41 "New table element should have no thead element."
42 );
43
44 table.create_t_head();
45 assert!(
46 table.t_head().is_some(),
47 "Table element should have thead element after create thead."
48 );
49
50 table.delete_t_head();
51 assert!(
52 table.t_head().is_none(),
53 "Table element should have no thead element after delete thead."
54 );
55
56 table.set_t_head(Some(&new_thead()));
57 assert!(
58 table.t_head().is_some(),
59 "Table element should have thead element after set."
60 );
61
62 assert!(
63 table.t_foot().is_none(),
64 "New table element should have no tfoot element."
65 );
66
67 table.create_t_foot();
68 assert!(
69 table.t_foot().is_some(),
70 "Table element should have tfoot element after create tfoot."
71 );
72
73 table.delete_t_foot();
74 assert!(
75 table.t_foot().is_none(),
76 "Table element should have no tfoot element after delete tfoot."
77 );
78
79 table.set_t_foot(Some(&new_tfoot()));
80 assert!(
81 table.t_foot().is_some(),
82 "Table element should have tfoot element after set."
83 );
84
85 assert!(
86 table.t_bodies().length() == 0,
87 "New table element should have no tbody element."
88 );
89
90 table.create_t_body();
91 assert!(
92 table.t_bodies().length() == 1,
93 "Table element should have tbody element after create tbody."
94 );
95
96 assert!(
97 table.rows().length() == 0,
98 "New table element should have no rows."
99 );
100
101 table
102 .insert_row_with_index(0)
103 .expect("Failed to insert row at index 0");
104 assert!(
105 table.rows().length() == 1,
106 "Table element should have rows after insert row."
107 );
108
109 table
110 .delete_row(0)
111 .expect("Failed to delete row at index 0");
112 assert!(
113 table.rows().length() == 0,
114 "Table element should have no rows after delete row."
115 );
116
117 table.set_align("left");
118 assert_eq!(
119 table.align(),
120 "left",
121 "Table element should have an align property of 'left'"
122 );
123
124 table.set_border("10");
125 assert_eq!(
126 table.border(),
127 "10",
128 "Table element should have a border property of '10'"
129 );
130
131 table.set_frame("above");
132 assert_eq!(
133 table.frame(),
134 "above",
135 "Table element should have an frame property of 'above'"
136 );
137
138 table.set_rules("none");
139 assert_eq!(
140 table.rules(),
141 "none",
142 "Table element should have an rules property of 'none'"
143 );
144
145 table.set_summary("summary");
146 assert_eq!(
147 table.summary(),
148 "summary",
149 "Table element should have an summary property of 'summary'"
150 );
151
152 table.set_width("1000");
153 assert_eq!(
154 table.width(),
155 "1000",
156 "Table element should have a width property of '1000'"
157 );
158
159 table.set_bg_color("#ffffff");
160 assert_eq!(
161 table.bg_color(),
162 "#ffffff",
163 "Table element should have an bgColor property of '#ffffff'"
164 );
165
166 table.set_cell_padding("1");
167 assert_eq!(
168 table.cell_padding(),
169 "1",
170 "Table element should have an cellPadding property of '1'"
171 );
172
173 table.set_cell_spacing("1");
174 assert_eq!(
175 table.cell_spacing(),
176 "1",
177 "Table element should have an cellSpacing property of '1'"
178 );
179 }
180