forked from o2sh/onefetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squash! Convert author tests to snapshot tests
This creates snapshot tests of the styled output
- Loading branch information
1 parent
039a511
commit a44a629
Showing
7 changed files
with
45 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +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() { | ||
|
@@ -190,9 +192,8 @@ mod test { | |
assert_eq!(authors_info.title(), "Authors"); | ||
} | ||
|
||
// TODO Move these snapshot tests to a more appropriate module so that the title and value are tested together | ||
#[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()), | ||
|
@@ -204,12 +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_snapshot!(authors_info.value()); | ||
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()), | ||
|
@@ -230,14 +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_snapshot!(authors_info.value()); | ||
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()), | ||
|
@@ -260,6 +268,12 @@ mod test { | |
authors: vec![author, author_2, author_3], | ||
}; | ||
|
||
assert_snapshot!(authors_info.value()); | ||
let colors = TextColors::new(&[], DynColors::Rgb(0xFF, 0xFF, 0xFF)); | ||
let mut buffer = String::new(); | ||
authors_info | ||
.write_styled(&mut buffer, false, &colors) | ||
.unwrap(); | ||
|
||
assert_snapshot!(buffer); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...nfo/snapshots/onefetch__info__author__test__author_info_alignment_with_three_authors.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: src/info/author.rs | ||
expression: buffer | ||
--- | ||
[38;2;255;255;255;1mAuthors[0m[39;1m:[0m [39m75% John Doe <[email protected]> 1500[0m | ||
[39m 80% Roberto Berto 240[0m | ||
[39m 1% Jane Doe 1[0m | ||
|
7 changes: 0 additions & 7 deletions
7
...apshots/onefetch__info__author__test__author_info_value_alignment_with_three_authors.snap
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/info/snapshots/onefetch__info__author__test__author_info_value_with_one_author.snap
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/info/snapshots/onefetch__info__author__test__author_info_value_with_two_authors.snap
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/info/snapshots/onefetch__info__author__test__author_info_with_one_author.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
source: src/info/author.rs | ||
expression: buffer | ||
--- | ||
[38;2;255;255;255;1mAuthor[0m[39;1m:[0m [39m75% John Doe <[email protected]> 1500[0m | ||
|
7 changes: 7 additions & 0 deletions
7
src/info/snapshots/onefetch__info__author__test__author_info_with_two_authors.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
source: src/info/author.rs | ||
expression: buffer | ||
--- | ||
[38;2;255;255;255;1mAuthors[0m[39;1m:[0m [39m75% John Doe <[email protected]> 1500[0m | ||
[39m 80% Roberto Berto 240[0m | ||
|