wip: test refactors

This commit is contained in:
Jack Wills
2024-07-12 21:56:35 +00:00
parent 3aebc8de15
commit 94e4d693ab
+70 -33
View File
@@ -1348,40 +1348,41 @@ mod tests {
// *********************** // // *********************** //
// Check that the correct solor is applied to the state/status/cpu/memory section // Check that the correct solor is applied to the state/status/cpu/memory section
#[allow(unused)]
fn check_expected(expected: [&str; 6], w: u16, _h: u16, setup: &TuiTestSetup, color: Color) { fn check_expected(expected: [&str; 6], w: u16, _h: u16, setup: &TuiTestSetup, color: Color) {
// let result = &setup.terminal.backend().buffer().content; for (row_index, result_row) in get_result(setup, w) {
// for (row_index, row) in expected.iter().enumerate() { let expected_row = expected_to_vec(&expected, row_index);
// for (char_index, expected_char) in row.chars().enumerate() { for (result_cell_index, result_cell) in result_row.iter().enumerate() {
// let index = row_index * usize::from(w) + char_index; assert_eq!(result_cell.symbol(), expected_row[result_cell_index]);
// let result_cell = &result[index];
// assert_eq!(result_cell.symbol(), expected_char.to_string()); match (row_index, result_cell_index) {
// if (145..=207).contains(&index) { // border
// assert_eq!(result_cell.fg, color); (0 | 5, _) | (1..=4, 0 | 129) => {
// assert_eq!(result_cell.modifier, Modifier::BOLD); assert_eq!(result_cell.fg, Color::LightCyan);
// } }
// } // name, id, image column
// } (1..=3, 4..=14 | 78..=98) => {
assert_eq!(result_cell.fg, Color::Blue);
assert_eq!(1, 2); }
// state, status, cpu, memory column of the first row
// let result = &setup.terminal.backend().buffer().content; (1, 15..=77) => {
assert_eq!(result_cell.fg, color);
// for (row_index, row) in result.chunks(usize::from(w)).enumerate() { }
// let expected_row = expected_to_vec(&expected, row_index); // state, status, cpu, memory column
// for (cell_index, result_cell) in row.iter().enumerate() { (2..=3, 15..=77) => {
// assert_eq!(result_cell.symbol(), expected_row[cell_index]); assert_eq!(result_cell.fg, Color::Green);
// if row_index == 0 || row_index == 5 || cell_index == 0 || cell_index == 11 { }
// assert_eq!(result_cell.fg, Color::LightCyan); // rx column
// } (1..=3, 99..=108) => {
// if row_index == 1 && cell_index > 0 && cell_index < 11 { assert_eq!(result_cell.fg, Color::Rgb(255, 233, 193));
// assert_eq!(result_cell.modifier, Modifier::BOLD); }
// } else { // tx column
// assert!(result_cell.modifier.is_empty()); (1..=3, 109..=118) => {
// } assert_eq!(result_cell.fg, Color::Rgb(205, 140, 140));
// } }
// } _ => assert_eq!(result_cell.fg, Color::Reset),
}
}
}
} }
#[test] #[test]
@@ -1704,6 +1705,7 @@ mod tests {
check_expected(expected, w, h, &setup, Color::LightRed); check_expected(expected, w, h, &setup, Color::LightRed);
} }
#[test] #[test]
/// When container state is restarting, correct colors displayed /// When container state is restarting, correct colors displayed
fn test_draw_blocks_containers_restarting() { fn test_draw_blocks_containers_restarting() {
@@ -1727,9 +1729,44 @@ mod tests {
super::containers(&setup.app_data, setup.area, f, &fd, &setup.gui_state); super::containers(&setup.app_data, setup.area, f, &fd, &setup.gui_state);
}) })
.unwrap(); .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]);
check_expected(expected, w, h, &setup, Color::LightGreen); match (row_index, result_cell_index) {
// border
(0 | 5, _) | (1..=4, 0 | 129) => {
assert_eq!(result_cell.fg, Color::LightCyan);
} }
// name, id, image column
(1..=3, 4..=14 | 79..=99) => {
assert_eq!(result_cell.fg, Color::Blue);
}
// state, status, cpu, memory column of the first row
(1, 15..=78) => {
assert_eq!(result_cell.fg, Color::LightGreen);
}
// state, status, cpu, memory column
(2..=3, 15..=78) => {
assert_eq!(result_cell.fg, Color::Green);
}
// rx column
(1..=3, 100..=109) => {
assert_eq!(result_cell.fg, Color::Rgb(255, 233, 193));
}
// tx column
(1..=3, 110..=119) => {
assert_eq!(result_cell.fg, Color::Rgb(205, 140, 140));
}
_ => {
assert_eq!(result_cell.fg, Color::Reset);
}
}
}
}
}
#[test] #[test]
/// When container state is unknown, correct colors displayed /// When container state is unknown, correct colors displayed
fn test_draw_blocks_containers_unknown() { fn test_draw_blocks_containers_unknown() {