mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-11 21:37:16 +00:00
Add unit tests for more 'web-sys' HTML bindings (#617)
That list includes: * HtmlOptionElement * HtmlOptGroupElement * HtmlOListElement * HtmlModElement
This commit is contained in:
parent
4a78769349
commit
d47fc61c36
@ -221,11 +221,11 @@ bindings are fully working and have full test coverage.
|
||||
- [ ] HTMLMenuItemElement.webidl
|
||||
- [ ] HTMLMetaElement.webidl
|
||||
- [ ] HTMLMeterElement.webidl
|
||||
- [ ] HTMLModElement.webidl
|
||||
- [x] HTMLModElement.webidl
|
||||
- [ ] HTMLObjectElement.webidl
|
||||
- [ ] HTMLOListElement.webidl
|
||||
- [ ] HTMLOptGroupElement.webidl
|
||||
- [ ] HTMLOptionElement.webidl
|
||||
- [x] HTMLOListElement.webidl
|
||||
- [x] HTMLOptGroupElement.webidl
|
||||
- [x] HTMLOptionElement.webidl
|
||||
- [x] HTMLOptionsCollection.webidl
|
||||
- [x] HTMLOutputElement.webidl
|
||||
- [x] HTMLParagraphElement.webidl
|
||||
|
@ -14,6 +14,10 @@ export function new_button() {
|
||||
return document.createElement("button");
|
||||
}
|
||||
|
||||
export function new_del() {
|
||||
return document.createElement("del");
|
||||
}
|
||||
|
||||
export function new_div() {
|
||||
return document.createElement("div");
|
||||
}
|
||||
@ -22,6 +26,10 @@ export function new_form() {
|
||||
return document.createElement("form");
|
||||
}
|
||||
|
||||
export function new_food_options_collection() {
|
||||
return new_select_with_food_opts().options;
|
||||
}
|
||||
|
||||
export function new_head() {
|
||||
return document.createElement("head");
|
||||
}
|
||||
@ -42,8 +50,16 @@ export function new_input() {
|
||||
return document.createElement("input");
|
||||
}
|
||||
|
||||
export function new_food_options_collection() {
|
||||
return new_select_with_food_opts().options;
|
||||
export function new_ins() {
|
||||
return document.createElement("ins");
|
||||
}
|
||||
|
||||
export function new_olist() {
|
||||
return document.createElement("ol");
|
||||
}
|
||||
|
||||
export function new_optgroup() {
|
||||
return document.createElement("optgroup");
|
||||
}
|
||||
|
||||
export function new_output() {
|
||||
|
@ -25,6 +25,10 @@ pub mod hr_element;
|
||||
pub mod html_element;
|
||||
pub mod html_html_element;
|
||||
pub mod input_element;
|
||||
pub mod mod_elements;
|
||||
pub mod olist_element;
|
||||
pub mod optgroup_element;
|
||||
pub mod option_element;
|
||||
pub mod options_collection;
|
||||
pub mod output_element;
|
||||
pub mod paragraph_element;
|
||||
|
28
crates/web-sys/tests/wasm/mod_elements.rs
Normal file
28
crates/web-sys/tests/wasm/mod_elements.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::HtmlModElement;
|
||||
|
||||
#[wasm_bindgen(module = "./tests/wasm/element.js")]
|
||||
extern {
|
||||
fn new_del() -> HtmlModElement;
|
||||
fn new_ins() -> HtmlModElement;
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_mod_elements() {
|
||||
let del = new_del();
|
||||
|
||||
del.set_cite("https://www.rust-lang.org/en-US/");
|
||||
assert_eq!(del.cite(), "https://www.rust-lang.org/en-US/", "Option should have the cite URI we gave it.");
|
||||
|
||||
del.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)");
|
||||
assert_eq!(del.date_time(), "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", "Option should have the date_time we gave it.");
|
||||
|
||||
let ins = new_ins();
|
||||
|
||||
ins.set_cite("https://www.rust-lang.org/en-US/");
|
||||
assert_eq!(ins.cite(), "https://www.rust-lang.org/en-US/", "Option should have the cite URI we gave it.");
|
||||
|
||||
ins.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)");
|
||||
assert_eq!(ins.date_time(), "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", "Option should have the date_time we gave it.");
|
||||
}
|
34
crates/web-sys/tests/wasm/olist_element.rs
Normal file
34
crates/web-sys/tests/wasm/olist_element.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::HtmlOListElement;
|
||||
|
||||
#[wasm_bindgen(module = "./tests/wasm/element.js")]
|
||||
extern {
|
||||
fn new_olist() -> HtmlOListElement;
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_olist_element() {
|
||||
let olist = new_olist();
|
||||
|
||||
olist.set_reversed(true);
|
||||
assert_eq!(olist.reversed(), true, "Olist should be reversed after we set it to be reversed.");
|
||||
|
||||
olist.set_reversed(false);
|
||||
assert_eq!(olist.reversed(), false, "Olist should not be reversed after we set it to be not reversed.");
|
||||
|
||||
olist.set_start(23);
|
||||
assert_eq!(olist.start(), 23, "Olist should have the start value we gave it.");
|
||||
|
||||
olist.set_type("A");
|
||||
assert_eq!(olist.type_(), "A", "Olist should be type 'A' after we set it to be type 'A'.");
|
||||
|
||||
olist.set_type("I");
|
||||
assert_eq!(olist.type_(), "I", "Olist should be type 'I' after we set it to be type 'I'.");
|
||||
|
||||
olist.set_compact(true);
|
||||
assert_eq!(olist.compact(), true, "Olist should be compact after we set it to be compact.");
|
||||
|
||||
olist.set_compact(false);
|
||||
assert_eq!(olist.compact(), false, "Olist should not be compact after we set it to be not compact.");
|
||||
}
|
22
crates/web-sys/tests/wasm/optgroup_element.rs
Normal file
22
crates/web-sys/tests/wasm/optgroup_element.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::HtmlOptGroupElement;
|
||||
|
||||
#[wasm_bindgen(module = "./tests/wasm/element.js")]
|
||||
extern {
|
||||
fn new_optgroup() -> HtmlOptGroupElement;
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_optgroup_element() {
|
||||
let optgroup = new_optgroup();
|
||||
|
||||
optgroup.set_disabled(true);
|
||||
assert_eq!(optgroup.disabled(), true, "Optgroup should be disabled after we set it to be disabled.");
|
||||
|
||||
optgroup.set_disabled(false);
|
||||
assert_eq!(optgroup.disabled(), false, "Optgroup should not be disabled after we set it to be not-disabled.");
|
||||
|
||||
optgroup.set_label("Group of options below");
|
||||
assert_eq!(optgroup.label(), "Group of options below", "Optgroup should have the label we gave it.");
|
||||
}
|
44
crates/web-sys/tests/wasm/option_element.rs
Normal file
44
crates/web-sys/tests/wasm/option_element.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::HtmlOptionElement;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_option_element() {
|
||||
let option = HtmlOptionElement::new(
|
||||
"option_text",
|
||||
"option_value",
|
||||
false,
|
||||
true
|
||||
).unwrap();
|
||||
|
||||
option.set_disabled(true);
|
||||
assert_eq!(option.disabled(), true, "Option should be disabled after we set it to be disabled.");
|
||||
|
||||
option.set_disabled(false);
|
||||
assert_eq!(option.disabled(), false, "Option should not be disabled after we set it to be not-disabled.");
|
||||
|
||||
assert!(option.form().is_none(), "Our option should not be associated with a form.");
|
||||
|
||||
option.set_label("Well this truly is a neat option");
|
||||
assert_eq!(option.label(), "Well this truly is a neat option", "Option should have the label we gave it.");
|
||||
|
||||
option.set_default_selected(true);
|
||||
assert_eq!(option.default_selected(), true, "Option should be default_selected after we set it to be default_selected.");
|
||||
|
||||
option.set_default_selected(false);
|
||||
assert_eq!(option.default_selected(), false, "Option should not be default_selected after we set it to be not default_selected.");
|
||||
|
||||
option.set_selected(true);
|
||||
assert_eq!(option.selected(), true, "Option should be selected after we set it to be selected.");
|
||||
|
||||
option.set_selected(false);
|
||||
assert_eq!(option.selected(), false, "Option should not be selected after we set it to be not selected.");
|
||||
|
||||
option.set_value("tomato");
|
||||
assert_eq!(option.value(), "tomato", "Option should have the value we gave it.");
|
||||
|
||||
option.set_text("potato");
|
||||
assert_eq!(option.text(), "potato", "Option should have the text we gave it.");
|
||||
|
||||
assert_eq!(option.index(), 0, "This should be the first option, since there are no other known options.");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user