Skip to content

Commit 714f5c2

Browse files
reeseJoshua Nelson
authored and
Joshua Nelson
committed
Add tests to verify showing and hiding clipboard.
1 parent 690f0fd commit 714f5c2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/web/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ impl ToJson for MetaData {
520520
#[cfg(test)]
521521
mod test {
522522
use crate::test::*;
523+
use html5ever::tendril::TendrilSink;
523524
use web::{match_version, MatchVersion};
524525

525526
const DEFAULT_ID: i32 = 0;
@@ -539,6 +540,12 @@ mod test {
539540
MatchVersion::Exact((version.into(), DEFAULT_ID)).strip_id()
540541
}
541542

543+
fn clipboard_is_present_for_path(path: &str, web: &TestFrontend) -> bool {
544+
let data = web.get(path).send().unwrap().text().unwrap();
545+
let node = kuchiki::parse_html().one(data);
546+
node.select("#clipboard").unwrap().count() == 1
547+
}
548+
542549
#[test]
543550
fn test_index_returns_success() {
544551
wrapper(|env| {
@@ -548,6 +555,50 @@ mod test {
548555
});
549556
}
550557

558+
#[test]
559+
fn test_show_clipboard_for_crate_pages() {
560+
wrapper(|env| {
561+
env.db()
562+
.fake_release()
563+
.name("fake_crate")
564+
.version("0.0.1")
565+
.source_file("test.rs", &[])
566+
.create()
567+
.unwrap();
568+
let web = env.frontend();
569+
assert!(clipboard_is_present_for_path(
570+
"/crate/fake_crate/0.0.1",
571+
web
572+
));
573+
assert!(clipboard_is_present_for_path(
574+
"/crate/fake_crate/0.0.1/source/",
575+
web
576+
));
577+
Ok(())
578+
});
579+
}
580+
581+
#[test]
582+
fn test_hide_clipboard_for_non_crate_pages() {
583+
wrapper(|env| {
584+
env.db()
585+
.fake_release()
586+
.name("fake_crate")
587+
.version("0.0.1")
588+
.create()
589+
.unwrap();
590+
let web = env.frontend();
591+
assert!(!clipboard_is_present_for_path("/about", web));
592+
assert!(!clipboard_is_present_for_path("/releases", web));
593+
assert!(!clipboard_is_present_for_path("/", web));
594+
assert!(!clipboard_is_present_for_path(
595+
"/fake_crate/0.0.1/fake_crate",
596+
web
597+
));
598+
Ok(())
599+
});
600+
}
601+
551602
#[test]
552603
fn standard_library_redirects() {
553604
wrapper(|env| {

0 commit comments

Comments
 (0)