Add tests for the home handler

This commit is contained in:
Paul van Tilburg 2018-01-01 21:16:47 +01:00
parent e98324e3fe
commit 8863b87c4e
1 changed files with 20 additions and 0 deletions

View File

@ -21,3 +21,23 @@ fn index(lists: State<ListStore>) -> Template {
let context = IndexTemplateContext { lists: list_kvs };
Template::render("index", &context)
}
#[cfg(test)]
mod tests {
use rocket;
use rocket::http::{Accept, Status};
use rocket::local::Client;
#[test]
fn index() {
let client = Client::new(rocket(Some("test"))).unwrap();
// Try to get the index and verify the body
let mut res = client.get("/").header(Accept::HTML).dispatch();
assert_eq!(res.status(), Status::Ok);
let body = res.body_string().unwrap();
println!("body: {}", body);
assert!(body.contains("<span id=\"list-name\">Test</span>"));
}
}