use pagetop::prelude::*; async fn render(mut tile: Tile) -> String { tile.render(&mut Context::default()).await.into_string() } enum TestRoute { Open, Signed, } impl Endpoint for TestRoute { fn path(&self) -> CowStr { match self { Self::Open => "/open".into(), Self::Signed => "/signed".into(), } } fn access(&self) -> Access { match self { Self::Open => Access::Public, Self::Signed => Access::Authenticated, } } } #[pagetop::test] async fn tile_is_a_link_with_its_title_and_accent() { let html = render(Tile::link(Lc::n("Orders"), "/orders")).await; assert!( html.starts_with(r#""#), "{html}" ); assert!(html.contains(r#"Orders"#)); assert!(html.ends_with("")); let html = render(Tile::link(Lc::n("Orders"), "/orders").with_accent(Accent::Orange)).await; assert!(html.contains(r#"class="tile accent-orange""#)); } #[pagetop::test] async fn description_icon_and_image_are_optional() { let html = render(Tile::link(Lc::n("Orders"), "/orders")).await; assert!(!html.contains("tile-description")); assert!(!html.contains("tile-icon")); assert!(!html.contains("Check the orders"#)); assert!(html.contains(r#""#), "{html}" ); assert!(!html.contains("href")); } #[pagetop::test] async fn tile_is_only_shown_with_access_to_its_route() { let html = render(Tile::link(Lc::n("Open"), TestRoute::Open)).await; assert!(html.contains(r#"href="/open""#)); // Without a request nobody is signed in. assert!( render(Tile::link(Lc::n("Signed"), TestRoute::Signed)) .await .is_empty() ); } #[pagetop::test] async fn tile_keeps_a_target_set_with_props() { let html = render(Tile::link(Lc::n("Orders"), "/orders").with_prop(PropsOp::set("target", "_top"))) .await; assert!(html.contains(r#"target="_top""#), "{html}"); }