1 use wasm_bindgen_test::*;
2 use web_sys::HtmlOptionElement;
3
4 #[wasm_bindgen_test]
test_option_element()5 fn test_option_element() {
6 let option = HtmlOptionElement::new_with_text_and_value_and_default_selected_and_selected(
7 "option_text",
8 "option_value",
9 false,
10 true,
11 )
12 .unwrap();
13
14 option.set_disabled(true);
15 assert_eq!(
16 option.disabled(),
17 true,
18 "Option should be disabled after we set it to be disabled."
19 );
20
21 option.set_disabled(false);
22 assert_eq!(
23 option.disabled(),
24 false,
25 "Option should not be disabled after we set it to be not-disabled."
26 );
27
28 assert!(
29 option.form().is_none(),
30 "Our option should not be associated with a form."
31 );
32
33 option.set_label("Well this truly is a neat option");
34 assert_eq!(
35 option.label(),
36 "Well this truly is a neat option",
37 "Option should have the label we gave it."
38 );
39
40 option.set_default_selected(true);
41 assert_eq!(
42 option.default_selected(),
43 true,
44 "Option should be default_selected after we set it to be default_selected."
45 );
46
47 option.set_default_selected(false);
48 assert_eq!(
49 option.default_selected(),
50 false,
51 "Option should not be default_selected after we set it to be not default_selected."
52 );
53
54 option.set_selected(true);
55 assert_eq!(
56 option.selected(),
57 true,
58 "Option should be selected after we set it to be selected."
59 );
60
61 option.set_selected(false);
62 assert_eq!(
63 option.selected(),
64 false,
65 "Option should not be selected after we set it to be not selected."
66 );
67
68 option.set_value("tomato");
69 assert_eq!(
70 option.value(),
71 "tomato",
72 "Option should have the value we gave it."
73 );
74
75 option.set_text("potato");
76 assert_eq!(
77 option.text(),
78 "potato",
79 "Option should have the text we gave it."
80 );
81
82 assert_eq!(
83 option.index(),
84 0,
85 "This should be the first option, since there are no other known options."
86 );
87 }
88