Skip to content

Commit

Permalink
test: added tests for reactive state example
Browse files Browse the repository at this point in the history
This adds important tests that verify a significant component of
Perseus' reactive state platform.
  • Loading branch information
arctic-hen7 committed Feb 8, 2022
1 parent 578b08b commit ad71957
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/core/rx_state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] }
sycamore = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[dev-dependencies]
fantoccini = "0.17"
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
1 change: 0 additions & 1 deletion examples/core/rx_state/src/templates/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub fn about_page() -> View<G> {
p { (format!("Greetings, {}!", username.get())) }

a(href = "") { "Index" }
a(href = "test") { "Test" }
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/core/rx_state/src/templates/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn index_page(state: IndexPageStateRx) -> View<G> {
p { (format!("Greetings, {}!", username.get())) }
input(bind:value = username_2, placeholder = "Username")

a(href = "about") { "About" }
a(href = "about", id = "about-link") { "About" }
}
}

Expand Down
35 changes: 35 additions & 0 deletions examples/core/rx_state/tests/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use fantoccini::{Client, Locator};
use perseus::wait_for_checkpoint;

#[perseus::test]
async fn main(c: &mut Client) -> Result<(), fantoccini::error::CmdError> {
c.goto("http://localhost:8080").await?;
wait_for_checkpoint!("begin", 0, c);
let url = c.current_url().await?;
assert!(url.as_ref().starts_with("http://localhost:8080"));
wait_for_checkpoint!("initial_state_present", 0, c);
wait_for_checkpoint!("page_visible", 0, c);

// The initial greeting should be to an empty string
let mut greeting = c.find(Locator::Css("p")).await?;
assert_eq!(greeting.text().await?, "Greetings, !");
// Now type some text in, and it should be reactively reflected straight away
c.find(Locator::Css("input"))
.await?
.send_keys("Test User")
.await?;
assert_eq!(greeting.text().await?, "Greetings, Test User!");

// Go to the about page and make sure the changed greeting is reflected there too
// This tests that pages can access each others' states
c.find(Locator::Id("about-link")).await?.click().await?;
let url = c.current_url().await?;
assert!(url.as_ref().starts_with("http://localhost:8080/about"));
wait_for_checkpoint!("initial_state_not_present", 0, c);
wait_for_checkpoint!("page_visible", 1, c);

let greeting = c.find(Locator::Css("p")).await?.text().await?;
assert_eq!(greeting, "Greetings, Test User!");

Ok(())
}

0 comments on commit ad71957

Please sign in to comment.