Skip to content

Commit

Permalink
[todomvc] add test with default todos
Browse files Browse the repository at this point in the history
  • Loading branch information
anp committed Sep 13, 2020
1 parent 5ba9bbd commit 3344493
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions dom/examples/todo/src/integration_tests.rs
Expand Up @@ -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 <li> 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 {
Expand All @@ -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::<Vec<_>>(),
expected
);
}

async fn add_todo(&self, todo: &str) {
self.input().keyboardln(todo);
// wait for it to show up
Expand All @@ -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()
}
Expand All @@ -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";

0 comments on commit 3344493

Please sign in to comment.