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
|
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use web_sys::{HtmlTableCaptionElement, HtmlTableElement, HtmlTableSectionElement};
#[wasm_bindgen(module = "/tests/wasm/element.js")]
extern "C" {
fn new_table() -> HtmlTableElement;
fn new_caption() -> HtmlTableCaptionElement;
fn new_thead() -> HtmlTableSectionElement;
fn new_tfoot() -> HtmlTableSectionElement;
}
#[wasm_bindgen_test]
fn test_table_element() {
let table = new_table();
assert!(
table.caption().is_none(),
"New table element should have no caption element."
);
table.create_caption();
assert!(
table.caption().is_some(),
"Table element should have caption element after create caption."
);
table.delete_caption();
assert!(
table.caption().is_none(),
"Table element should have no caption element after delete caption."
);
table.set_caption(Some(&new_caption()));
assert!(
table.caption().is_some(),
"Table element should have caption element after set."
);
assert!(
table.t_head().is_none(),
"New table element should have no thead element."
);
table.create_t_head();
assert!(
table.t_head().is_some(),
"Table element should have thead element after create thead."
);
table.delete_t_head();
assert!(
table.t_head().is_none(),
"Table element should have no thead element after delete thead."
);
table.set_t_head(Some(&new_thead()));
assert!(
table.t_head().is_some(),
"Table element should have thead element after set."
);
assert!(
table.t_foot().is_none(),
"New table element should have no tfoot element."
);
table.create_t_foot();
assert!(
table.t_foot().is_some(),
"Table element should have tfoot element after create tfoot."
);
table.delete_t_foot();
assert!(
table.t_foot().is_none(),
"Table element should have no tfoot element after delete tfoot."
);
table.set_t_foot(Some(&new_tfoot()));
assert!(
table.t_foot().is_some(),
"Table element should have tfoot element after set."
);
assert!(
table.t_bodies().length() == 0,
"New table element should have no tbody element."
);
table.create_t_body();
assert!(
table.t_bodies().length() == 1,
"Table element should have tbody element after create tbody."
);
assert!(
table.rows().length() == 0,
"New table element should have no rows."
);
table
.insert_row_with_index(0)
.expect("Failed to insert row at index 0");
assert!(
table.rows().length() == 1,
"Table element should have rows after insert row."
);
table
.delete_row(0)
.expect("Failed to delete row at index 0");
assert!(
table.rows().length() == 0,
"Table element should have no rows after delete row."
);
table.set_align("left");
assert_eq!(
table.align(),
"left",
"Table element should have an align property of 'left'"
);
table.set_border("10");
assert_eq!(
table.border(),
"10",
"Table element should have a border property of '10'"
);
table.set_frame("above");
assert_eq!(
table.frame(),
"above",
"Table element should have an frame property of 'above'"
);
table.set_rules("none");
assert_eq!(
table.rules(),
"none",
"Table element should have an rules property of 'none'"
);
table.set_summary("summary");
assert_eq!(
table.summary(),
"summary",
"Table element should have an summary property of 'summary'"
);
table.set_width("1000");
assert_eq!(
table.width(),
"1000",
"Table element should have a width property of '1000'"
);
table.set_bg_color("#ffffff");
assert_eq!(
table.bg_color(),
"#ffffff",
"Table element should have an bgColor property of '#ffffff'"
);
table.set_cell_padding("1");
assert_eq!(
table.cell_padding(),
"1",
"Table element should have an cellPadding property of '1'"
);
table.set_cell_spacing("1");
assert_eq!(
table.cell_spacing(),
"1",
"Table element should have an cellSpacing property of '1'"
);
}
|