Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for StaticRouter #168

Merged
merged 2 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/sycamore-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,57 @@ pub fn navigate(url: &str) {
fn meta_keys_pressed(kb_event: &KeyboardEvent) -> bool {
kb_event.meta_key() || kb_event.ctrl_key() || kb_event.shift_key() || kb_event.alt_key()
}

#[cfg(test)]
mod tests {
use sycamore::prelude::*;

use super::*;

#[test]
fn static_router() {
#[derive(Route)]
enum Routes {
#[to("/")]
Home,
#[to("/about")]
About,
#[not_found]
NotFound,
}

#[component(Comp<G>)]
fn comp(path: String) -> Template<G> {
template! {
StaticRouter((path, |route: Routes| {
match route {
Routes::Home => template! {
"Home"
},
Routes::About => template! {
"About"
},
Routes::NotFound => template! {
"Not Found"
}
}
}))
}
}

assert_eq!(
sycamore::render_to_string(|| template! { Comp("/".to_string()) }),
"Home"
);

assert_eq!(
sycamore::render_to_string(|| template! { Comp("/about".to_string()) }),
"About"
);

assert_eq!(
sycamore::render_to_string(|| template! { Comp("/404".to_string()) }),
"Not Found"
);
}
}
4 changes: 2 additions & 2 deletions website/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn content(
p { "This is unreleased documentation for Sycamore next version." }
p {
"For up-to-date documentation, see the "
a(href=format!("/docs/{}/getting_started/hello_world", crate::LATEST_MAJOR_VERSION)) {
a(href=format!("/docs/{}/getting_started/installation", crate::LATEST_MAJOR_VERSION)) {
"latest version"
}
" (" (crate::LATEST_MAJOR_VERSION) ")."
Expand All @@ -140,7 +140,7 @@ pub fn content(
p { "This is outdated documentation for Sycamore." }
p {
"For up-to-date documentation, see the "
a(href=format!("/docs/{}/getting_started/hello_world", crate::LATEST_MAJOR_VERSION)) {
a(href=format!("/docs/{}/getting_started/installation", crate::LATEST_MAJOR_VERSION)) {
"latest version"
}
" (" (crate::LATEST_MAJOR_VERSION) ")."
Expand Down