use pagetop::prelude::*; #[pagetop::test] async fn single_page_renders_nothing() { let mut pager = Pager::new() .with_base_path("/list") .with_items_per_page(20) .with_total_items(5); let html = pager.render(&mut Context::default()).await.into_string(); assert_eq!(html, ""); } #[pagetop::test] async fn default_aria_label_is_page_navigation() { let mut pager = Pager::new() .with_base_path("/list") .with_current_page(1) .with_items_per_page(10) .with_total_items(50); let html = pager.render(&mut Context::default()).await.into_string(); assert!(html.contains(r#"aria-label="Page navigation""#)); } #[pagetop::test] async fn with_aria_label_overrides_the_default() { let mut pager = Pager::new() .with_base_path("/list") .with_current_page(1) .with_items_per_page(10) .with_total_items(50) .with_aria_label(L10n::n("Users pagination")); let html = pager.render(&mut Context::default()).await.into_string(); assert!(html.contains(r#"aria-label="Users pagination""#)); assert!(!html.contains(r#"aria-label="Page navigation""#)); } #[pagetop::test] async fn summary_is_hidden_by_default() { let mut pager = Pager::new() .with_base_path("/list") .with_current_page(1) .with_items_per_page(20) .with_total_items(97); let html = pager.render(&mut Context::default()).await.into_string(); assert!(!html.contains("pager-summary")); } #[pagetop::test] async fn summary_shows_the_range_of_the_current_page() { let mut first_page = Pager::new() .with_base_path("/list") .with_current_page(1) .with_items_per_page(20) .with_total_items(97) .with_summary(true); let html = first_page .render(&mut Context::default()) .await .into_string(); assert!(html.contains(r#"Showing 1-20 of 97"#)); // Last page: fewer items than `items_per_page`, so `last` stops at `total_items`. let mut last_page = Pager::new() .with_base_path("/list") .with_current_page(5) .with_items_per_page(20) .with_total_items(97) .with_summary(true); let html = last_page .render(&mut Context::default()) .await .into_string(); assert!(html.contains(r#"Showing 81-97 of 97"#)); } #[pagetop::test] async fn renders_page_links_and_current_page() { let mut pager = Pager::new() .with_base_path("/admin/users") .with_current_page(2) .with_items_per_page(20) .with_total_items(45); let html = pager.render(&mut Context::default()).await.into_string(); assert!(html.contains(r#"href="/admin/users?page=1""#)); assert!(html.contains(r#"href="/admin/users?page=2" aria-current="page""#)); assert!(html.contains(r#"href="/admin/users?page=3""#)); assert!(html.contains(r#"