Skip to content

Commit df4bbb2

Browse files
committed
add test for release-link partial
1 parent ddd6939 commit df4bbb2

3 files changed

+59
-29
lines changed

.sqlx/query-23457d8f5ff3b551d5c4039615b4e72a4609ebfb0390708f5a61f7ab66db8808.json

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-3b5412eff4406994b584d50e5aa30734fafc218f83ba856e2db6ddcfe423e72b.json

-22
This file was deleted.

src/web/rustdoc.rs

+30-7
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,15 @@ mod test {
22292229
})
22302230
}
22312231

2232+
fn parse_release_links_from_menu(body: &str) -> Vec<String> {
2233+
kuchikiki::parse_html()
2234+
.one(body)
2235+
.select(r#"ul > li > a"#)
2236+
.expect("invalid selector")
2237+
.map(|elem| elem.attributes.borrow().get("href").unwrap().to_string())
2238+
.collect()
2239+
}
2240+
22322241
#[test_case(true)]
22332242
#[test_case(false)]
22342243
fn test_version_link_goes_to_docs(archive_storage: bool) {
@@ -2244,6 +2253,7 @@ mod test {
22442253
.version("0.3.1")
22452254
.archive_storage(archive_storage)
22462255
.rustdoc_file("hexponent/index.html")
2256+
.rustdoc_file("hexponent/something.html")
22472257
.create()?;
22482258

22492259
// test rustdoc pages stay on the documentation
@@ -2253,14 +2263,27 @@ mod test {
22532263
.send()?;
22542264
assert!(releases_response.status().is_success());
22552265
assert_cache_control(&releases_response, CachePolicy::ForeverInCdn, &env.config());
2256-
let page = kuchikiki::parse_html().one(releases_response.text()?);
2257-
let selector =
2258-
r#"ul > li a[href="/crate/hexponent/0.3.1/target-redirect/hexponent/index.html"]"#
2259-
.to_string();
22602266
assert_eq!(
2261-
page.select(&selector).unwrap().count(),
2262-
1,
2263-
"link to /target-redirect/ not found"
2267+
parse_release_links_from_menu(&releases_response.text()?),
2268+
vec![
2269+
"/crate/hexponent/0.3.1/target-redirect/hexponent/index.html".to_owned(),
2270+
"/crate/hexponent/0.3.0/target-redirect/hexponent/index.html".to_owned(),
2271+
]
2272+
);
2273+
2274+
// test if target-redirect inludes path
2275+
let releases_response = env
2276+
.frontend()
2277+
.get("/crate/hexponent/0.3.1/menus/releases/hexponent/something.html")
2278+
.send()?;
2279+
assert!(releases_response.status().is_success());
2280+
assert_cache_control(&releases_response, CachePolicy::ForeverInCdn, &env.config());
2281+
assert_eq!(
2282+
parse_release_links_from_menu(&releases_response.text()?),
2283+
vec![
2284+
"/crate/hexponent/0.3.1/target-redirect/hexponent/something.html".to_owned(),
2285+
"/crate/hexponent/0.3.0/target-redirect/hexponent/something.html".to_owned(),
2286+
]
22642287
);
22652288

22662289
// test /crate pages stay on /crate

0 commit comments

Comments
 (0)