Skip to content

Commit d6ae6d8

Browse files
soutadeGregory Soutade
and
Gregory Soutade
authored
Fix test can_build_site_with_pagination_for_taxonomy() by taking in account not rendered pages for pagers computation (#2782)
Co-authored-by: Gregory Soutade <[email protected]>
1 parent d7d7d95 commit d6ae6d8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: components/site/tests/site.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ fn can_build_site_with_pagination_for_index() {
600600

601601
#[test]
602602
fn can_build_site_with_pagination_for_taxonomy() {
603+
let mut nb_a_pages = 0;
603604
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
604605
site.config.languages.get_mut("en").unwrap().taxonomies.push(TaxonomyConfig {
605606
name: "tags".to_string(),
@@ -616,6 +617,10 @@ fn can_build_site_with_pagination_for_taxonomy() {
616617

617618
let pages_data = std::mem::replace(&mut library.pages, AHashMap::new());
618619
for (i, (_, mut page)) in pages_data.into_iter().enumerate() {
620+
// Discard not rendered pages
621+
if i % 2 == 0 && page.meta.render {
622+
nb_a_pages += 1;
623+
}
619624
page.meta.taxonomies = {
620625
let mut taxonomies = HashMap::new();
621626
taxonomies.insert(
@@ -633,7 +638,8 @@ fn can_build_site_with_pagination_for_taxonomy() {
633638
site.populate_taxonomies().unwrap();
634639
(site, false)
635640
});
636-
641+
let nb_a_pagers: usize =
642+
if nb_a_pages % 2 == 0 { nb_a_pages / 2 } else { (nb_a_pages / 2) + 1 };
637643
assert!(&public.exists());
638644

639645
assert!(file_exists!(public, "index.html"));
@@ -661,7 +667,7 @@ fn can_build_site_with_pagination_for_taxonomy() {
661667
"tags/a/page/1/index.html",
662668
"http-equiv=\"refresh\" content=\"0; url=https://replace-this-with-your-url.com/tags/a/\""
663669
));
664-
assert!(file_contains!(public, "tags/a/index.html", "Num pagers: 9"));
670+
assert!(file_contains!(public, "tags/a/index.html", &format!("Num pagers: {nb_a_pagers}")));
665671
assert!(file_contains!(public, "tags/a/index.html", "Page size: 2"));
666672
assert!(file_contains!(public, "tags/a/index.html", "Current index: 1"));
667673
assert!(!file_contains!(public, "tags/a/index.html", "has_prev"));
@@ -671,11 +677,13 @@ fn can_build_site_with_pagination_for_taxonomy() {
671677
"tags/a/index.html",
672678
"First: https://replace-this-with-your-url.com/tags/a/"
673679
));
680+
674681
assert!(file_contains!(
675682
public,
676683
"tags/a/index.html",
677-
"Last: https://replace-this-with-your-url.com/tags/a/page/9/"
684+
&format!("Last: https://replace-this-with-your-url.com/tags/a/page/{nb_a_pagers}/")
678685
));
686+
679687
assert!(!file_contains!(public, "tags/a/index.html", "has_prev"));
680688

681689
// sitemap contains the pager pages

0 commit comments

Comments
 (0)