diff --git a/dom/examples/todo/src/integration_tests.rs b/dom/examples/todo/src/integration_tests.rs index 4493511ca..51b35f45c 100644 --- a/dom/examples/todo/src/integration_tests.rs +++ b/dom/examples/todo/src/integration_tests.rs @@ -12,9 +12,15 @@ use wasm_bindgen_test::wasm_bindgen_test; #[wasm_bindgen_test] pub async fn add_2_todos() { let test = Test::new(); - test.add_todo("learn testing").await; - test.add_todo("be cool").await; - // TODO assert .todo-list has two
  • in the right order + let (first, second) = ("learn testing", "be cool"); + test.add_todo(first).await; + test.add_todo(second).await; + test.assert_todos(&[first, second]).await; +} + +#[wasm_bindgen_test] +pub async fn add_default_todos() { + Test::new().add_default_todos().await; } struct Test { @@ -38,6 +44,17 @@ impl Test { Test { root } } + #[track_caller] + async fn assert_todos(&self, expected: &[&str]) { + assert_eq!( + self.query_selector_all(".todo-list li") + .iter() + .map(|t| t.get_inner_text()) + .collect::>(), + expected + ); + } + async fn add_todo(&self, todo: &str) { self.input().keyboardln(todo); // wait for it to show up @@ -46,6 +63,15 @@ impl Test { self.find().by_text(todo).until().many().await.unwrap(); } + async fn add_default_todos(&self) { + info!("adding default TODOs"); + let expected = &[TODO_ITEM_ONE, TODO_ITEM_TWO, TODO_ITEM_THREE]; + for todo in expected { + self.add_todo(todo).await; + } + self.assert_todos(expected).await; + } + fn input(&self) -> Node { self.find().by_placeholder_text(INPUT_PLACEHOLDER).one().unwrap() } @@ -61,3 +87,6 @@ impl Drop for Test { } const INPUT_PLACEHOLDER: &str = "What needs to be done?"; +const TODO_ITEM_ONE: &str = "buy some cheese"; +const TODO_ITEM_TWO: &str = "feed the cat"; +const TODO_ITEM_THREE: &str = "book a doctors appointment";