Skip to content

Commit

Permalink
Convert author value tests to styled snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack authored Nov 14, 2023
1 parent f3c4438 commit 25d17d9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/info/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ impl InfoField for AuthorsInfo {
#[cfg(test)]
mod test {
use super::*;
use crate::ui::text_colors::TextColors;
use insta::assert_snapshot;
use owo_colors::DynColors;

#[test]
fn test_display_author() {
Expand Down Expand Up @@ -190,7 +193,7 @@ mod test {
}

#[test]
fn test_author_info_value_with_one_author() {
fn test_author_info_with_one_author() {
let author = Author::new(
"John Doe".into(),
Some("[email protected]".into()),
Expand All @@ -202,15 +205,17 @@ mod test {
let authors_info = AuthorsInfo {
authors: vec![author],
};
let colors = TextColors::new(&[], DynColors::Rgb(0xFF, 0xFF, 0xFF));
let mut buffer = String::new();
authors_info
.write_styled(&mut buffer, false, &colors)
.unwrap();

assert_eq!(
authors_info.value(),
"75% John Doe <[email protected]> 1500".to_string()
);
assert_snapshot!(buffer);
}

#[test]
fn test_author_info_value_with_two_authors() {
fn test_author_info_with_two_authors() {
let author = Author::new(
"John Doe".into(),
Some("[email protected]".into()),
Expand All @@ -231,16 +236,16 @@ mod test {
authors: vec![author, author_2],
};

assert!(authors_info
.value()
.contains(&"75% John Doe <[email protected]> 1500".to_string()));
let colors = TextColors::new(&[], DynColors::Rgb(0xFF, 0xFF, 0xFF));
let mut buffer = String::new();
authors_info
.write_styled(&mut buffer, false, &colors)
.unwrap();

assert!(authors_info
.value()
.contains(&"80% Roberto Berto 240".to_string()));
assert_snapshot!(buffer);
}
#[test]
fn test_author_info_value_alignment_with_three_authors() {
fn test_author_info_alignment_with_three_authors() {
let author = Author::new(
"John Doe".into(),
Some("[email protected]".into()),
Expand All @@ -263,15 +268,12 @@ mod test {
authors: vec![author, author_2, author_3],
};

assert!(authors_info
.value()
.contains(&"75% John Doe <[email protected]> 1500".to_string()));

assert!(authors_info
.value()
.contains(&"80% Roberto Berto 240".to_string()));
let colors = TextColors::new(&[], DynColors::Rgb(0xFF, 0xFF, 0xFF));
let mut buffer = String::new();
authors_info
.write_styled(&mut buffer, false, &colors)
.unwrap();

// Note the extra leading space to right-align the percentages
assert!(authors_info.value().contains(&" 1% Jane Doe 1".to_string()));
assert_snapshot!(buffer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: src/info/author.rs
expression: buffer
---
Authors: 75% John Doe <[email protected]> 1500
 80% Roberto Berto 240
 1% Jane Doe 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/info/author.rs
expression: buffer
---
Author: 75% John Doe <[email protected]> 1500

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: src/info/author.rs
expression: buffer
---
Authors: 75% John Doe <[email protected]> 1500
 80% Roberto Berto 240

0 comments on commit 25d17d9

Please sign in to comment.