diff --git a/crates/web-sys/README.md b/crates/web-sys/README.md index cb69fa2e..9241f682 100644 --- a/crates/web-sys/README.md +++ b/crates/web-sys/README.md @@ -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 diff --git a/crates/web-sys/tests/wasm/element.js b/crates/web-sys/tests/wasm/element.js index 6e0d5ccb..583fca65 100644 --- a/crates/web-sys/tests/wasm/element.js +++ b/crates/web-sys/tests/wasm/element.js @@ -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() { diff --git a/crates/web-sys/tests/wasm/main.rs b/crates/web-sys/tests/wasm/main.rs index 59efa62a..4d386493 100644 --- a/crates/web-sys/tests/wasm/main.rs +++ b/crates/web-sys/tests/wasm/main.rs @@ -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; diff --git a/crates/web-sys/tests/wasm/mod_elements.rs b/crates/web-sys/tests/wasm/mod_elements.rs new file mode 100644 index 00000000..f7dacdff --- /dev/null +++ b/crates/web-sys/tests/wasm/mod_elements.rs @@ -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."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/olist_element.rs b/crates/web-sys/tests/wasm/olist_element.rs new file mode 100644 index 00000000..411b73cf --- /dev/null +++ b/crates/web-sys/tests/wasm/olist_element.rs @@ -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."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/optgroup_element.rs b/crates/web-sys/tests/wasm/optgroup_element.rs new file mode 100644 index 00000000..1a7dccfc --- /dev/null +++ b/crates/web-sys/tests/wasm/optgroup_element.rs @@ -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."); +} \ No newline at end of file diff --git a/crates/web-sys/tests/wasm/option_element.rs b/crates/web-sys/tests/wasm/option_element.rs new file mode 100644 index 00000000..6dddb0f9 --- /dev/null +++ b/crates/web-sys/tests/wasm/option_element.rs @@ -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."); +} \ No newline at end of file