Skip to content

Improve the styling of the coverage in the dropdown #961

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 2 commits into from
Aug 13, 2020
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
21 changes: 12 additions & 9 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ impl<'a> FakeRelease<'a> {
docsrs_version: "docs.rs 1.0.0 (000000000 1970-01-01)".into(),
build_log: "It works!".into(),
successful: true,
doc_coverage: Some(DocCoverage {
total_items: 10,
documented_items: 6,
}),
doc_coverage: None,
},
source_files: Vec::new(),
rustdoc_files: Vec::new(),
Expand Down Expand Up @@ -186,6 +183,14 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn coverage(mut self, documented_items: i32, total_items: i32) -> Self {
self.build_result.doc_coverage = Some(DocCoverage {
total_items,
documented_items,
});
self
}

/// Returns the release_id
pub(crate) fn create(self) -> Result<i32, Error> {
use std::fs;
Expand Down Expand Up @@ -277,11 +282,9 @@ impl<'a> FakeRelease<'a> {
&self.registry_crate_data,
)?;
crate::db::add_build_into_database(&mut db.conn(), release_id, &self.build_result)?;
crate::db::add_doc_coverage(
&mut db.conn(),
release_id,
self.build_result.doc_coverage.clone().unwrap(),
)?;
if let Some(coverage) = self.build_result.doc_coverage {
crate::db::add_doc_coverage(&mut db.conn(), release_id, coverage)?;
}

Ok(release_id)
}
Expand Down
37 changes: 18 additions & 19 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,6 @@ mod test {
node.select("#clipboard").unwrap().count() == 1
}

fn check_doc_coverage_is_present_for_path(path: &str, web: &TestFrontend) -> bool {
let data = web.get(path).send().unwrap().text().unwrap();
let node = kuchiki::parse_html().one(data);
node.select(".pure-menu-heading")
.unwrap()
.any(|e| e.text_contents().contains("Coverage"))
}

#[test]
fn test_index_returns_success() {
wrapper(|env| {
Expand All @@ -689,20 +681,27 @@ mod test {
fn test_doc_coverage_for_crate_pages() {
wrapper(|env| {
env.fake_release()
.name("fake_crate")
.name("foo")
.version("0.0.1")
.source_file("test.rs", &[])
.create()
.unwrap();
.coverage(6, 10)
.create()?;
let web = env.frontend();
assert!(check_doc_coverage_is_present_for_path(
"/crate/fake_crate/0.0.1",
web
));
assert!(check_doc_coverage_is_present_for_path(
"/fake_crate/0.0.1/fake_crate",
web
));

let foo_crate = kuchiki::parse_html().one(web.get("/crate/foo/0.0.1").send()?.text()?);
for value in &["60%", "6", "10"] {
assert!(foo_crate
.select(".pure-menu-item b")
.unwrap()
.any(|e| e.text_contents().contains(value)));
}

let foo_doc = kuchiki::parse_html().one(web.get("/foo/0.0.1/foo").send()?.text()?);
assert!(foo_doc
.select(".pure-menu-link b")
.unwrap()
.any(|e| e.text_contents().contains("60%")));

Ok(())
});
}
Expand Down
2 changes: 1 addition & 1 deletion templates/crate/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{%- if details.documented_items and details.total_items -%}
{% set percent = details.documented_items * 100 / details.total_items %}
<li class="pure-menu-heading">Coverage</li>
<li class="pure-menu-item" style="text-align:center;"><b>{{ percent | round(precision=2) }} %</b><br>
<li class="pure-menu-item" style="text-align:center;"><b>{{ percent | round(precision=2) }}%</b><br>
<span style="font-size: 13px;"><b>{{ details.documented_items }}</b> out of <b>{{ details.total_items }}</b> items documented</span>
</li>
{%- endif -%}
Expand Down
31 changes: 16 additions & 15 deletions templates/rustdoc/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,7 @@
</div>
</div>

{%- if krate.documented_items and krate.total_items -%}
{% set percent = krate.documented_items * 100 / krate.total_items %}
<div class="pure-g menu-item-divided">
<div class="pure-u-1">
<ul class="pure-menu-list">
<li class="pure-menu-heading">Coverage</li>
<li class="pure-menu-link"><b>{{ percent | round(precision=2) }} %</b><br>
<span><b>{{ krate.documented_items }}</b> out of <b>{{ krate.total_items }}</b> items documented</span>
</li>
</ul>
</div>
</div>
{%- endif -%}

<div class="pure-g">
<div class="pure-g menu-item-divided">
<div class="pure-u-1-2 right-border">
<ul class="pure-menu-list">
<li class="pure-menu-heading">Dependencies</li>
Expand Down Expand Up @@ -169,6 +155,21 @@
</ul>
</div>
</div>
{%- if krate.documented_items and krate.total_items -%}
{% set percent = krate.documented_items * 100 / krate.total_items %}
<div class="pure-g">
<div class="pure-u-1">
<ul class="pure-menu-list">
<li>
<a href="{{ crate_url | safe }}" class="pure-menu-link">
<b>{{ percent | round(precision=2) }}%</b>
of the crate is documented
</a>
</li>
</ul>
</div>
</div>
{%- endif -%}
</div>
</li>

Expand Down