Skip to content

add small test for owner list in top-bar #2527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,13 @@ pub(crate) async fn static_asset_handler(

#[cfg(test)]
mod test {
use crate::{test::*, utils::Dependency, web::cache::CachePolicy, Config};
use crate::{
registry_api::{CrateOwner, OwnerKind},
test::*,
utils::Dependency,
web::cache::CachePolicy,
Config,
};
use anyhow::Context;
use kuchikiki::traits::TendrilSink;
use reqwest::{blocking::ClientBuilder, redirect, StatusCode};
Expand Down Expand Up @@ -2315,6 +2321,60 @@ mod test {
})
}

#[test]
fn test_owner_links_with_team() {
wrapper(|env| {
env.fake_release()
.name("testing")
.version("0.1.0")
.add_owner(CrateOwner {
login: "some-user".into(),
kind: OwnerKind::User,
avatar: "".into(),
})
.add_owner(CrateOwner {
login: "some-team".into(),
kind: OwnerKind::Team,
avatar: "".into(),
})
.create()?;

let dom = kuchikiki::parse_html().one(
env.frontend()
.get("/testing/0.1.0/testing/")
.send()?
.text()?,
);

let owner_links: Vec<_> = dom
.select(r#"#topbar-owners > li > a"#)
.expect("invalid selector")
.map(|el| {
let attributes = el.attributes.borrow();
let url = attributes.get("href").expect("href").trim().to_string();
let name = el.text_contents().trim().to_string();
(name, url)
})
.collect();

assert_eq!(
owner_links,
vec![
(
"some-user".into(),
"https://crates.io/users/some-user".into()
),
(
"some-team".into(),
"https://crates.io/teams/some-team".into()
),
]
);

Ok(())
})
}

#[test]
fn test_dependency_optional_suffix() {
wrapper(|env| {
Expand Down
2 changes: 1 addition & 1 deletion templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

{# Show the crate owners #}
<div class="pure-u-1-2">
<ul class="pure-menu-list">
<ul class="pure-menu-list" id="topbar-owners">
<li class="pure-menu-heading">Owners</li>

{%- for owner in krate.owners -%}
Expand Down
Loading