use sauron::{ html::{attributes::*, *}, *, }; use test_fixtures::simple_program; use wasm_bindgen_test::*; mod test_fixtures; wasm_bindgen_test_configure!(run_in_browser); // Issue: When there is diff_keyed_elements // the first update is OK, however, the subsequent update // will error with: // // : panicked at 'must have a tag here', // sauron/crates/sauron-core/src/dom/apply_patches.rs:109:32 #[wasm_bindgen_test] fn subsequent_updates() { console_log::init_with_level(log::Level::Trace).ok(); console_error_panic_hook::set_once(); let document = web_sys::window().unwrap().document().unwrap(); let old: Node<()> = main( vec![class("editor")], vec![ section( vec![class("lines")], vec![ div( vec![key("hash0")], vec![ div(vec![], vec![text("0")]), div(vec![], vec![text("line0")]), ], ), div( vec![key("hash1")], vec![ div(vec![], vec![text("1")]), div(vec![], vec![text("line1")]), ], ), div( vec![key("hash2")], vec![ div(vec![], vec![text("2")]), div(vec![], vec![text("line2")]), ], ), div( vec![key("hash3")], vec![ div(vec![], vec![text("3")]), div(vec![], vec![text("line3")]), ], ), ], ), footer(vec![], vec![text("line:0, col:0")]), ], ); let update1: Node<()> = main( vec![class("editor")], vec![ section( vec![class("lines")], vec![ div( vec![key("hashXXX")], vec![ div(vec![], vec![text("0")]), div(vec![], vec![text("lineXXX")]), ], ), div( vec![key("hash0")], vec![ div(vec![], vec![text("1")]), div(vec![], vec![text("line0")]), ], ), div( vec![key("hash1")], vec![ div(vec![], vec![text("2")]), div(vec![], vec![text("line1")]), ], ), div( vec![key("hash2")], vec![ div(vec![], vec![text("3")]), div(vec![], vec![text("line2")]), ], ), div( vec![key("hash3")], vec![ div(vec![], vec![text("4")]), div(vec![], vec![text("line3")]), ], ), ], ), footer(vec![], vec![text("line:0, col:0")]), ], ); let patches1 = diff(&old, &update1); log::trace!("patches1: {:#?} at line: {}", patches1, line!()); let old_html = old.render_to_string(); log::trace!("old html: {}", old_html); let expected_old = "
\
\
\
0
\
line0
\
\
\
1
\
line1
\
\
\
2
\
line2
\
\
\
3
\
line3
\
\
\ \
"; assert_eq!(old_html, expected_old); let mut simple_program = simple_program(); simple_program .update_dom_with_vdom(old.clone()) .expect("must not error"); let container = document .query_selector(".editor") .expect("must not error") .expect("must exist"); let expected = "
\
\
\
0
\
line0
\
\
\
1
\
line1
\
\
\
2
\
line2
\
\
\
3
\
line3
\
\
\ \
"; assert_eq!(old.render_to_string(), expected); assert_eq!(expected, container.outer_html()); simple_program .update_dom_with_vdom(update1.clone()) .expect("must not error"); let container = document .query_selector(".editor") .expect("must not error") .expect("must exist"); log::trace!("expected1 {:?}", container.outer_html()); let expected1 = "
\
\
\
0
\
lineXXX
\
\
\
1
\
line0
\
\
\
2
\
line1
\
\
\
3
\
line2
\
\
\
4
\
line3
\
\
\ \
"; assert_eq!(expected1, update1.render_to_string()); assert_eq!(expected1, container.outer_html()); let update2: Node<()> = main( vec![class("editor")], vec![ section( vec![class("lines")], vec![ div( vec![key("hashYYY")], vec![ div(vec![], vec![text("0")]), div(vec![], vec![text("lineYYY")]), ], ), div( vec![key("hashXXX")], vec![ div(vec![], vec![text("1")]), div(vec![], vec![text("lineXXX")]), ], ), div( vec![key("hash0")], vec![ div(vec![], vec![text("2")]), div(vec![], vec![text("line0")]), ], ), div( vec![key("hash1")], vec![ div(vec![], vec![text("3")]), div(vec![], vec![text("line1")]), ], ), div( vec![key("hash2")], vec![ div(vec![], vec![text("4")]), div(vec![], vec![text("line2")]), ], ), div( vec![key("hash3")], vec![ div(vec![], vec![text("5")]), div(vec![], vec![text("line3")]), ], ), ], ), footer(vec![], vec![text("line:0, col:0")]), ], ); { let root_node = simple_program.root_node.borrow(); let root_node_html = root_node.as_ref().unwrap().outer_html(); log::trace!("current root node: {}", root_node_html); } let patches2 = diff(&update1, &update2); log::trace!("-->patches2: {:#?}", patches2); log::info!("Updating dom with update2"); simple_program .update_dom_with_vdom(update2.clone()) .expect("must not error"); log::info!("Done doing updates2"); let container = document .query_selector(".editor") .expect("must not error") .expect("must exist"); let expected2 = "
\
\
\
0
\
lineYYY
\
\
\
1
\
lineXXX
\
\
\
2
\
line0
\
\
\
3
\
line1
\
\
\
4
\
line2
\
\
\
5
\
line3
\
\
\ \
"; assert_eq!(expected2, update2.render_to_string()); assert_eq!(expected2, container.outer_html()); let update3: Node<()> = main( vec![class("editor")], vec![ section( vec![class("lines")], vec![ div( vec![key("hashZZZ")], vec![div(vec![], vec![text("0")]), div(vec![], vec![text("\n")])], ), div( vec![key("hashYYY")], vec![ div(vec![], vec![text("1")]), div(vec![], vec![text("lineYYY")]), ], ), div( vec![key("hashXXX")], vec![ div(vec![], vec![text("2")]), div(vec![], vec![text("lineXXX")]), ], ), div( vec![key("hash0")], vec![ div(vec![], vec![text("3")]), div(vec![], vec![text("line0")]), ], ), div( vec![key("hash1")], vec![ div(vec![], vec![text("4")]), div(vec![], vec![text("line1")]), ], ), div( vec![key("hash2")], vec![ div(vec![], vec![text("5")]), div(vec![], vec![text("line2")]), ], ), div( vec![key("hash3")], vec![ div(vec![], vec![text("6")]), div(vec![], vec![text("line3")]), ], ), ], ), footer(vec![], vec![text("line:0, col:0")]), ], ); let patches3 = diff(&update2, &update3); log::trace!("\n---->patches3: {:#?}", patches3); simple_program .update_dom_with_vdom(update3.clone()) .expect("must not error"); let container = document .query_selector(".editor") .expect("must not error") .expect("must exist"); let expected3 = "
\
\
\
0
\
\n
\
\
\
1
\
lineYYY
\
\
\
2
\
lineXXX
\
\
\
3
\
line0
\
\
\
4
\
line1
\
\
\
5
\
line2
\
\
\
6
\
line3
\
\
\ \
"; assert_eq!(expected3, update3.render_to_string()); assert_eq!(expected3, container.outer_html()); }