1
0

diff_dynamic_node.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use dioxus::dioxus_core::{ElementId, Mutation::*};
  2. use dioxus::prelude::*;
  3. use pretty_assertions::assert_eq;
  4. #[test]
  5. fn toggle_option_text() {
  6. let mut dom = VirtualDom::new(|| {
  7. let gen = generation();
  8. let text = if gen % 2 != 0 { Some("hello") } else { None };
  9. rsx! {
  10. div {
  11. {text}
  12. }
  13. }
  14. });
  15. // load the div and then assign the None as a placeholder
  16. assert_eq!(
  17. dom.rebuild_to_vec().sanitize().edits,
  18. [
  19. LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
  20. AssignId { path: &[0], id: ElementId(2,) },
  21. AppendChildren { id: ElementId(0), m: 1 },
  22. ]
  23. );
  24. // Rendering again should replace the placeholder with an text node
  25. dom.mark_dirty(ScopeId::APP);
  26. assert_eq!(
  27. dom.render_immediate_to_vec().sanitize().edits,
  28. [
  29. CreateTextNode { value: "hello".to_string(), id: ElementId(3,) },
  30. ReplaceWith { id: ElementId(2,), m: 1 },
  31. ]
  32. );
  33. // Rendering again should replace the placeholder with an text node
  34. dom.mark_dirty(ScopeId::APP);
  35. assert_eq!(
  36. dom.render_immediate_to_vec().sanitize().edits,
  37. [
  38. CreatePlaceholder { id: ElementId(2,) },
  39. ReplaceWith { id: ElementId(3,), m: 1 },
  40. ]
  41. );
  42. }