option_element.rs 2.1 KB

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