From a51696fd5310c5641ccb251ebb73d04261d0aee0 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Fri, 21 Jun 2024 16:13:54 +0200 Subject: [PATCH] add small test for owner list in top-bar --- src/web/rustdoc.rs | 62 ++++++++++++++++++++++++++++++++++- templates/rustdoc/topbar.html | 2 +- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index f68125a47..8b36a7a0a 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -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}; @@ -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| { diff --git a/templates/rustdoc/topbar.html b/templates/rustdoc/topbar.html index dace3c4e5..c6593e388 100644 --- a/templates/rustdoc/topbar.html +++ b/templates/rustdoc/topbar.html @@ -107,7 +107,7 @@ {# Show the crate owners #}
-