test: Use insta, closes #57

Use insta for UI tests, adds snapshots of UI layout
This commit is contained in:
Jack Wills
2025-04-16 11:16:45 +00:00
parent 8f959c5408
commit 9362d7b481
126 changed files with 2059 additions and 1773 deletions
+9 -35
View File
@@ -57,30 +57,19 @@ pub fn draw(
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use insta::assert_snapshot;
use ratatui::style::Color;
use crate::{
config::AppColors,
ui::draw_blocks::tests::{expected_to_vec, get_result, test_setup},
ui::draw_blocks::tests::{get_result, test_setup},
};
#[test]
/// Info box drawn in bottom right
fn test_draw_blocks_info() {
let (w, h) = (45, 9);
let mut setup = test_setup(w, h, true, true);
let mut setup = test_setup(45, 9, true, true);
let expected = [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" test ",
" ",
];
let colors = setup.app_data.lock().config.app_colors;
setup
@@ -96,11 +85,10 @@ mod tests {
})
.unwrap();
for (row_index, result_row) in get_result(&setup, w) {
let expected_row = expected_to_vec(&expected, row_index);
for (result_cell_index, result_cell) in result_row.iter().enumerate() {
assert_eq!(result_cell.symbol(), expected_row[result_cell_index]);
assert_snapshot!(setup.terminal.backend());
for (row_index, result_row) in get_result(&setup) {
for (result_cell_index, result_cell) in result_row.iter().enumerate() {
let (bg, fg) = match (row_index, result_cell_index) {
(6..=8, 32..=44) => (Color::Blue, Color::White),
_ => (Color::Reset, Color::Reset),
@@ -114,23 +102,11 @@ mod tests {
#[test]
/// Info box drawn in bottom right with custom colors applied
fn test_draw_blocks_info_custom_color() {
let (w, h) = (45, 9);
let mut setup = test_setup(w, h, true, true);
let mut setup = test_setup(45, 9, true, true);
let mut colors = AppColors::new();
colors.popup_info.background = Color::Red;
colors.popup_info.text = Color::Black;
let expected = [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" test ",
" ",
];
setup
.terminal
@@ -145,11 +121,9 @@ mod tests {
})
.unwrap();
for (row_index, result_row) in get_result(&setup, w) {
let expected_row = expected_to_vec(&expected, row_index);
assert_snapshot!(setup.terminal.backend());
for (row_index, result_row) in get_result(&setup) {
for (result_cell_index, result_cell) in result_row.iter().enumerate() {
assert_eq!(result_cell.symbol(), expected_row[result_cell_index]);
let (bg, fg) = match (row_index, result_cell_index) {
(6..=8, 32..=44) => (Color::Red, Color::Black),
_ => (Color::Reset, Color::Reset),