Skip to content

Commit

Permalink
Add test for target list
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 8, 2023
1 parent ce7e5a8 commit ab3421c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,47 @@ mod tests {
});
}

// Ensure that if there are more than a given number of targets, it will not generate them in
// the HTML directly (they will be loaded by AJAX if the user opens the menu).
#[test]
fn platform_menu_ajax() {
assert!(crate::DEFAULT_MAX_TARGETS > 2);

fn check_count(nb_targets: usize, expected: usize) {
wrapper(|env| {
let mut rel = env
.fake_release()
.name("dummy")
.version("0.4.0")
.rustdoc_file("dummy/index.html")
.rustdoc_file("x86_64-pc-windows-msvc/dummy/index.html")
.default_target("x86_64-unknown-linux-gnu");

for nb in 0..nb_targets - 1 {
rel = rel.add_target(&format!("x86_64-pc-windows-msvc{nb}"));
}
rel.create()?;

let response = env.frontend().get("/crate/dummy/0.4.0").send()?;
assert!(response.status().is_success());

let nb_li = kuchikiki::parse_html()
.one(response.text()?)
.select(r#"#platforms li a"#)
.expect("invalid selector")
.count();
assert_eq!(nb_li, expected);
Ok(())
});
}

// First we check that with 2 releases, the platforms list should be in the HTML.
check_count(2, 2);
// Then we check the same thing but with number of targets equal
// to `DEFAULT_MAX_TARGETS`.
check_count(crate::DEFAULT_MAX_TARGETS, 0);
}

#[test]
fn latest_url() {
wrapper(|env| {
Expand Down

0 comments on commit ab3421c

Please sign in to comment.