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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use web_sys::HtmlInputElement;
#[wasm_bindgen(module = "/tests/wasm/element.js")]
extern "C" {
fn new_input() -> HtmlInputElement;
}
#[wasm_bindgen_test]
fn test_input_element() {
let element = new_input();
let location = web_sys::window().unwrap().location().href().unwrap();
assert_eq!(element.accept(), "", "Shouldn't have an accept");
element.set_accept("audio/*");
assert_eq!(element.accept(), "audio/*", "Should have an accept");
assert_eq!(element.alt(), "", "Shouldn't have an alt");
element.set_alt("alt text");
assert_eq!(element.alt(), "alt text", "Should have an alt");
element.set_type("text");
assert_eq!(element.autocomplete(), "", "Shouldn't have an autocomplete");
element.set_autocomplete("on");
assert_eq!(
element.autocomplete(),
"on",
"Shouldn't have an autocomplete"
);
assert!(!element.autofocus(), "Shouldn't have an autofocus");
element.set_autofocus(true);
assert!(element.autofocus(), "Should have an autofocus");
element.set_type("checkbox");
assert!(
!element.default_checked(),
"Shouldn't have an default_checked"
);
element.set_default_checked(true);
assert!(element.default_checked(), "Should have an default_checked");
assert!(element.checked(), "Should be checked");
element.set_checked(false);
assert!(!element.checked(), "Shouldn't be checked");
assert!(!element.disabled(), "Shouldn't be disabled");
element.set_disabled(true);
assert!(element.disabled(), "Should be disabled");
match element.form() {
None => assert!(true, "Shouldn't have a form"),
_ => assert!(false, "Shouldn't have a form"),
};
assert_eq!(
element.form_action(),
location,
"Should have the pages location"
);
element.set_form_action("http://boop.com/");
assert_eq!(
element.form_action(),
"http://boop.com/",
"Should have a form_action"
);
assert_eq!(element.form_enctype(), "", "Should have no enctype");
element.set_form_enctype("text/plain");
assert_eq!(
element.form_enctype(),
"text/plain",
"Should have a plain text enctype"
);
assert_eq!(element.form_method(), "", "Should have no method");
element.set_form_method("POST");
assert_eq!(element.form_method(), "post", "Should have a POST method");
assert!(!element.form_no_validate(), "Should validate");
element.set_form_no_validate(true);
assert!(element.form_no_validate(), "Should not validate");
assert_eq!(element.form_target(), "", "Should have no target");
element.set_form_target("_blank");
assert_eq!(
element.form_target(),
"_blank",
"Should have a _blank target"
);
assert_eq!(element.height(), 0, "Should have no height");
element.set_height(12);
assert_eq!(element.height(), 0, "Should have no height");
assert_eq!(
element.get_attribute("height").unwrap(),
"12",
"The height attribute should be 12"
);
element.set_type("checkbox");
element.set_indeterminate(true);
assert!(element.indeterminate(), "Should be indeterminate");
element.set_indeterminate(false);
assert!(!element.indeterminate(), "Shouldn't be indeterminate");
/*TODO add tests
pub fn indeterminate(&self) -> bool
pub fn set_indeterminate(&self, indeterminate: bool)
pub fn input_mode(&self) -> String
pub fn set_input_mode(&self, input_mode: &str)
pub fn list(&self) -> Option<HtmlElement>
pub fn max(&self) -> String
pub fn set_max(&self, max: &str)
pub fn max_length(&self) -> i32
pub fn set_max_length(&self, max_length: i32)
pub fn min(&self) -> String
pub fn set_min(&self, min: &str)
pub fn min_length(&self) -> i32
pub fn set_min_length(&self, min_length: i32)
pub fn multiple(&self) -> bool
pub fn set_multiple(&self, multiple: bool)
*/
assert_eq!(element.name(), "", "Should not have a name");
element.set_name("namey");
assert_eq!(element.name(), "namey", "Should have a name");
/*TODO add tests
pub fn pattern(&self) -> String
pub fn set_pattern(&self, pattern: &str)
*/
assert_eq!(element.placeholder(), "", "Should not have a placeholder");
element.set_placeholder("some text");
assert_eq!(
element.placeholder(),
"some text",
"Should have a placeholder"
);
assert!(!element.read_only(), "Should have not be readonly");
element.set_read_only(true);
assert!(element.read_only(), "Should be readonly");
assert!(!element.required(), "Should have not be required");
element.set_required(true);
assert!(element.required(), "Should be required");
/*TODO add tests
pub fn size(&self) -> u32
pub fn set_size(&self, size: u32)
*/
element.set_type("image");
assert_eq!(element.src(), "", "Should have no src");
const EMPTY_IMAGE: &str = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E";
element.set_src(EMPTY_IMAGE);
assert_eq!(element.src(), EMPTY_IMAGE, "Should have a src");
/*TODO add tests
pub fn src(&self) -> String
pub fn set_src(&self, src: &str)
pub fn step(&self) -> String
pub fn set_step(&self, step: &str)
pub fn type_(&self) -> String
pub fn set_type(&self, type_: &str)
pub fn default_value(&self) -> String
pub fn set_default_value(&self, default_value: &str)
*/
assert_eq!(element.value(), "", "Should have no value");
element.set_value("hey!");
assert_eq!(element.value(), "hey!", "Should have a value");
element.set_type("number");
element.set_value("1");
assert_eq!(element.value_as_number(), 1.0, "Should have value 1");
element.set_value_as_number(2.0);
assert_eq!(element.value(), "2", "Should have value 2");
assert_eq!(element.width(), 0, "Should have no width");
element.set_width(12);
assert_eq!(element.width(), 0, "Should have no width");
assert_eq!(
element.get_attribute("width").unwrap(),
"12",
"The width attribute should be 12"
);
assert_eq!(element.will_validate(), false, "Shouldn't validate");
assert_eq!(
element.validation_message().unwrap(),
"",
"Shouldn't have a value"
);
assert_eq!(element.check_validity(), true, "Should be valid");
assert_eq!(element.report_validity(), true, "Should be valid");
element.set_custom_validity("Boop"); // Method exists but doesn't impact validity ?!??! TODO look into
assert_eq!(element.check_validity(), true, "Should be valid");
assert_eq!(element.report_validity(), true, "Should be valid");
/*TODO add tests
pub fn labels(&self) -> Option<NodeList>
pub fn select(&self)
pub fn selection_direction(&self) -> Result<Option<String>, JsValue>
pub fn set_selection_direction(
&self,
selection_direction: Option<&str>
) -> Result<(), JsValue>
pub fn set_range_text(&self, replacement: &str) -> Result<(), JsValue>
pub fn set_selection_range(
&self,
start: u32,
end: u32,
direction: &str
) -> Result<(), JsValue>
*/
assert_eq!(element.align(), "", "Should have no align");
element.set_align("left");
assert_eq!(element.align(), "left", "Should have an align");
/*TODO add tests
pub fn use_map(&self) -> String
pub fn set_use_map(&self, use_map: &str)
pub fn text_length(&self) -> i32
pub fn webkitdirectory(&self) -> bool
pub fn set_webkitdirectory(&self, webkitdirectory: bool)
pub fn set_focus_state(&self, a_is_focused: bool)
*/
}
|