Skip to content

Commit 75541b6

Browse files
Add test for target list
1 parent f2e302d commit 75541b6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/web/crate_details.rs

+42
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,48 @@ mod tests {
12741274
});
12751275
}
12761276

1277+
// Ensure that if there are more than a given number of targets, it will not generate them in
1278+
// the HTML directly (they will be loaded by AJAX if the user opens the menu).
1279+
#[test]
1280+
#[allow(clippy::assertions_on_constants)]
1281+
fn platform_menu_ajax() {
1282+
assert!(crate::DEFAULT_MAX_TARGETS > 2);
1283+
1284+
fn check_count(nb_targets: usize, expected: usize) {
1285+
wrapper(|env| {
1286+
let mut rel = env
1287+
.fake_release()
1288+
.name("dummy")
1289+
.version("0.4.0")
1290+
.rustdoc_file("dummy/index.html")
1291+
.rustdoc_file("x86_64-pc-windows-msvc/dummy/index.html")
1292+
.default_target("x86_64-unknown-linux-gnu");
1293+
1294+
for nb in 0..nb_targets - 1 {
1295+
rel = rel.add_target(&format!("x86_64-pc-windows-msvc{nb}"));
1296+
}
1297+
rel.create()?;
1298+
1299+
let response = env.frontend().get("/crate/dummy/0.4.0").send()?;
1300+
assert!(response.status().is_success());
1301+
1302+
let nb_li = kuchikiki::parse_html()
1303+
.one(response.text()?)
1304+
.select(r#"#platforms li a"#)
1305+
.expect("invalid selector")
1306+
.count();
1307+
assert_eq!(nb_li, expected);
1308+
Ok(())
1309+
});
1310+
}
1311+
1312+
// First we check that with 2 releases, the platforms list should be in the HTML.
1313+
check_count(2, 2);
1314+
// Then we check the same thing but with number of targets equal
1315+
// to `DEFAULT_MAX_TARGETS`.
1316+
check_count(crate::DEFAULT_MAX_TARGETS, 0);
1317+
}
1318+
12771319
#[test]
12781320
fn latest_url() {
12791321
wrapper(|env| {

0 commit comments

Comments
 (0)