Skip to content

Commit 4da711c

Browse files
committed
add test for release-link partial
1 parent 5cf899f commit 4da711c

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/web/rustdoc.rs

+30-7
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,15 @@ mod test {
22492249
})
22502250
}
22512251

2252+
fn parse_release_links_from_menu(body: &str) -> Vec<String> {
2253+
kuchikiki::parse_html()
2254+
.one(body)
2255+
.select(r#"ul > li > a"#)
2256+
.expect("invalid selector")
2257+
.map(|elem| elem.attributes.borrow().get("href").unwrap().to_string())
2258+
.collect()
2259+
}
2260+
22522261
#[test_case(true)]
22532262
#[test_case(false)]
22542263
fn test_version_link_goes_to_docs(archive_storage: bool) {
@@ -2264,6 +2273,7 @@ mod test {
22642273
.version("0.3.1")
22652274
.archive_storage(archive_storage)
22662275
.rustdoc_file("hexponent/index.html")
2276+
.rustdoc_file("hexponent/something.html")
22672277
.create()?;
22682278

22692279
// test rustdoc pages stay on the documentation
@@ -2273,14 +2283,27 @@ mod test {
22732283
.send()?;
22742284
assert!(releases_response.status().is_success());
22752285
assert_cache_control(&releases_response, CachePolicy::ForeverInCdn, &env.config());
2276-
let page = kuchikiki::parse_html().one(releases_response.text()?);
2277-
let selector =
2278-
r#"ul > li a[href="/crate/hexponent/0.3.1/target-redirect/hexponent/index.html"]"#
2279-
.to_string();
22802286
assert_eq!(
2281-
page.select(&selector).unwrap().count(),
2282-
1,
2283-
"link to /target-redirect/ not found"
2287+
parse_release_links_from_menu(&releases_response.text()?),
2288+
vec![
2289+
"/crate/hexponent/0.3.1/target-redirect/hexponent/index.html".to_owned(),
2290+
"/crate/hexponent/0.3.0/target-redirect/hexponent/index.html".to_owned(),
2291+
]
2292+
);
2293+
2294+
// test if target-redirect inludes path
2295+
let releases_response = env
2296+
.frontend()
2297+
.get("/crate/hexponent/0.3.1/menus/releases/hexponent/something.html")
2298+
.send()?;
2299+
assert!(releases_response.status().is_success());
2300+
assert_cache_control(&releases_response, CachePolicy::ForeverInCdn, &env.config());
2301+
assert_eq!(
2302+
parse_release_links_from_menu(&releases_response.text()?),
2303+
vec![
2304+
"/crate/hexponent/0.3.1/target-redirect/hexponent/something.html".to_owned(),
2305+
"/crate/hexponent/0.3.0/target-redirect/hexponent/something.html".to_owned(),
2306+
]
22842307
);
22852308

22862309
// test /crate pages stay on /crate

0 commit comments

Comments
 (0)