test: Wrote snapshot tests for all Sonarr UI

This commit is contained in:
2025-12-16 14:12:10 -07:00
parent e0fcbc71e1
commit 0532d59746
257 changed files with 8089 additions and 1029 deletions
@@ -4,16 +4,13 @@ mod tests {
use crate::app::App;
use crate::models::BlockSelectionState;
use crate::models::servarr_data::modals::EditIndexerModal;
use crate::models::servarr_data::sonarr::sonarr_data::{
ActiveSonarrBlock, EDIT_INDEXER_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
};
use crate::models::servarr_models::{Indexer, IndexerField};
use crate::models::stateful_table::StatefulTable;
use crate::models::servarr_models::Indexer;
use crate::ui::DrawUi;
use crate::ui::sonarr_ui::indexers::edit_indexer_ui::EditIndexerUi;
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
use serde_json::json;
#[test]
fn test_edit_indexer_ui_accepts() {
@@ -27,39 +24,52 @@ mod tests {
}
mod snapshot_tests {
use crate::models::servarr_data::sonarr::sonarr_data::EDIT_INDEXER_NZB_SELECTION_BLOCKS;
use crate::network::sonarr_network::sonarr_network_test_utils::test_utils::indexer;
use crate::ui::ui_test_utils::test_utils::TerminalSize;
use super::*;
#[test]
fn test_edit_indexer_ui_renders_edit_indexer_modal() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveSonarrBlock::EditIndexerNameInput.into());
app.data.sonarr_data.indexers = StatefulTable::default();
app.data.sonarr_data.indexers.set_items(vec![Indexer {
id: 1,
name: Some("Test Indexer".to_owned()),
enable_rss: true,
priority: 25,
fields: Some(vec![
IndexerField {
name: Some("baseUrl".to_owned()),
value: Some(json!("https://test.indexer.com")),
},
IndexerField {
name: Some("apiKey".to_owned()),
value: Some(json!("test-api-key")),
},
IndexerField {
name: Some("seedCriteria.seedRatio".to_owned()),
value: Some(json!(1.0)),
},
]),
..Indexer::default()
}]);
fn test_edit_indexer_ui_renders_loading() {
let mut app = App::test_default_fully_populated();
app.is_loading = true;
app.data.sonarr_data.edit_indexer_modal = None;
app.push_navigation_stack(ActiveSonarrBlock::EditIndexerPrompt.into());
app.data.sonarr_data.selected_block =
BlockSelectionState::new(EDIT_INDEXER_TORRENT_SELECTION_BLOCKS);
app.data.sonarr_data.edit_indexer_modal = Some(EditIndexerModal::from(&app.data.sonarr_data));
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
EditIndexerUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[test]
fn test_edit_indexer_ui_renders_edit_torrent_indexer() {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::EditIndexerPrompt.into());
app.data.sonarr_data.selected_block =
BlockSelectionState::new(EDIT_INDEXER_TORRENT_SELECTION_BLOCKS);
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
EditIndexerUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[test]
fn test_edit_indexer_ui_renders_edit_usenet_indexer() {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::EditIndexerPrompt.into());
app.data.sonarr_data.indexers.set_items(vec![Indexer {
protocol: "usenet".into(),
..indexer()
}]);
app.data.sonarr_data.selected_block =
BlockSelectionState::new(EDIT_INDEXER_NZB_SELECTION_BLOCKS);
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
EditIndexerUi::draw(f, app, f.area());