Skip to content

Commit

Permalink
Improve platform_links_are_direct_and_without_nofollow readability
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 25, 2023
1 parent 772c4f6 commit 60ced40
Showing 1 changed file with 29 additions and 49 deletions.
78 changes: 29 additions & 49 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ mod tests {
use crate::index::api::CrateOwner;
use crate::test::{
assert_cache_control, assert_redirect, assert_redirect_cached, wrapper, TestDatabase,
TestEnvironment,
};
use anyhow::{Context, Error};
use kuchikiki::traits::TendrilSink;
Expand Down Expand Up @@ -1270,6 +1271,25 @@ mod tests {
}
}

fn run_check_links(
env: &TestEnvironment,
url: &str,
extra: &str,
should_contain_redirect: bool,
) {
let response = env.frontend().get(url).send().unwrap();
assert!(response.status().is_success());
check_links(response.text().unwrap(), false, should_contain_redirect);
// Same test with AJAX endpoint.
let response = env
.frontend()
.get(&format!("/-/menus/platforms{url}{extra}"))
.send()
.unwrap();
assert!(response.status().is_success());
check_links(response.text().unwrap(), true, should_contain_redirect);
}

wrapper(|env| {
env.fake_release()
.name("dummy")
Expand All @@ -1281,55 +1301,15 @@ mod tests {
.add_target("x86_64-pc-windows-msvc")
.create()?;

let response = env.frontend().get("/crate/dummy/0.4.0").send()?;
assert!(response.status().is_success());
check_links(response.text()?, false, false);
// Same test with AJAX endpoint.
let response = env
.frontend()
.get("/-/menus/platforms/crate/dummy/0.4.0")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, true, false);

let response = env.frontend().get("/dummy/latest/dummy").send()?;
assert!(response.status().is_success());
check_links(response.text()?, false, true);
// Same test with AJAX endpoint.
let response = env
.frontend()
.get("/-/menus/platforms/dummy/latest/dummy/")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, true, true);

let response = env
.frontend()
.get("/dummy/0.4.0/x86_64-pc-windows-msvc/dummy")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, false, true);
// Same test with AJAX endpoint.
let response = env
.frontend()
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, true, true);

let response = env
.frontend()
.get("/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, false, true);
// Same test with AJAX endpoint.
let response = env
.frontend()
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html")
.send()?;
assert!(response.status().is_success());
check_links(response.text()?, true, true);
run_check_links(env, "/crate/dummy/0.4.0", "", false);
run_check_links(env, "/dummy/latest/dummy", "/", true);
run_check_links(env, "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy", "/", true);
run_check_links(
env,
"/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html",
"/",
true,
);

Ok(())
});
Expand Down

0 comments on commit 60ced40

Please sign in to comment.