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());
@@ -7,7 +7,6 @@ mod tests {
use crate::models::servarr_data::sonarr::sonarr_data::{
ActiveSonarrBlock, INDEXER_SETTINGS_BLOCKS, INDEXER_SETTINGS_SELECTION_BLOCKS,
};
use crate::models::sonarr_models::IndexerSettings;
use crate::ui::DrawUi;
use crate::ui::sonarr_ui::indexers::indexer_settings_ui::IndexerSettingsUi;
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
@@ -30,11 +29,10 @@ mod tests {
#[test]
fn test_indexer_settings_ui_renders_indexer_settings() {
let mut app = App::test_default();
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::IndexerSettingsMinimumAgeInput.into());
app.data.sonarr_data.selected_block =
BlockSelectionState::new(INDEXER_SETTINGS_SELECTION_BLOCKS);
app.data.sonarr_data.indexer_settings = Some(IndexerSettings::default());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexerSettingsUi::draw(f, app, f.area());
+88 -25
View File
@@ -7,7 +7,6 @@ mod tests {
ActiveSonarrBlock, EDIT_INDEXER_BLOCKS, INDEXER_SETTINGS_BLOCKS, INDEXERS_BLOCKS,
};
use crate::models::servarr_models::Indexer;
use crate::models::stateful_table::StatefulTable;
use crate::ui::DrawUi;
use crate::ui::sonarr_ui::indexers::IndexersUi;
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
@@ -30,13 +29,19 @@ mod tests {
}
mod snapshot_tests {
use crate::models::BlockSelectionState;
use crate::models::servarr_data::sonarr::sonarr_data::{
EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
};
use crate::network::sonarr_network::sonarr_network_test_utils::test_utils::indexer;
use crate::ui::ui_test_utils::test_utils::TerminalSize;
use rstest::rstest;
use super::*;
#[test]
fn test_indexers_ui_renders_loading_state() {
let mut app = App::test_default();
fn test_indexers_ui_renders_loading() {
let mut app = App::test_default_fully_populated();
app.is_loading = true;
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
@@ -47,11 +52,67 @@ mod tests {
insta::assert_snapshot!(output);
}
#[test]
fn test_indexers_ui_renders_loading_test_results() {
let mut app = App::test_default_fully_populated();
app.is_loading = true;
app.push_navigation_stack(ActiveSonarrBlock::TestIndexer.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[test]
fn test_indexers_ui_renders_loading_test_results_when_indexer_test_errors_is_none() {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::TestIndexer.into());
app.data.sonarr_data.indexer_test_errors = None;
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[test]
fn test_indexers_ui_renders_empty_indexers() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
app.data.sonarr_data.indexers = StatefulTable::default();
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[rstest]
fn test_indexers_ui_renders(
#[values(
ActiveSonarrBlock::DeleteIndexerPrompt,
ActiveSonarrBlock::Indexers,
ActiveSonarrBlock::TestIndexer
)]
active_sonarr_block: ActiveSonarrBlock,
) {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(active_sonarr_block.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(format!("indexers_ui_{active_sonarr_block}"), output);
}
#[test]
fn test_indexers_ui_renders_test_all_over_indexers() {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::TestAllIndexers.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
@@ -61,27 +122,29 @@ mod tests {
}
#[test]
fn test_indexers_ui_renders_with_indexers() {
let mut app = App::test_default();
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
app.data.sonarr_data.indexers = StatefulTable::default();
app.data.sonarr_data.indexers.set_items(vec![
Indexer {
id: 1,
name: Some("Test Indexer 1".to_owned()),
enable_rss: true,
enable_automatic_search: true,
enable_interactive_search: true,
priority: 25,
..Indexer::default()
},
Indexer {
id: 2,
name: Some("Test Indexer 2".to_owned()),
enable_rss: false,
..Indexer::default()
},
]);
fn test_indexers_ui_renders_edit_usenet_indexer_over_indexers() {
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_NZB_SELECTION_BLOCKS);
app.data.sonarr_data.indexers.set_items(vec![Indexer {
protocol: "usenet".into(),
..indexer()
}]);
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
IndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[test]
fn test_indexers_ui_renders_edit_torrent_indexer_over_indexers() {
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| {
IndexersUi::draw(f, app, f.area());
@@ -0,0 +1,42 @@
---
source: src/ui/sonarr_ui/indexers/edit_indexer_ui_tests.rs
expression: output
---
╭──────────────────────────────────────────────── Edit Indexer ─────────────────────────────────────────────────╮
│ │
│ ╭─────────────────────────╮ ╭─────────────────────────╮ │
│ Name: │DrunkenSlug │ URL: │http://127.0.0.1:9696/1/ │ │
│ ╰─────────────────────────╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable RSS: │ ✔ │ API Key: │someApiKey │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Automatic Search: │ ✔ │ Seed Ratio: │ratio │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Interactive Search: │ ✔ │ Tags: │25 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭─────────────────────────╮ │
│ Indexer Priority ▴▾: │1 │ │
│ ╰─────────────────────────╯ │
│ │
│ │
│ │
│ │
│ ╭───────────────────────────╮╭──────────────────────────╮ │
│ │ Save ││ Cancel │ │
│ ╰───────────────────────────╯╰──────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -18,16 +18,16 @@ expression: output
╭──────────────────────────────────────────────── Edit Indexer ─────────────────────────────────────────────────╮
│ │
│ ╭─────────────────────────╮ ╭─────────────────────────╮ │
│ Name: │Test Indexer │ URL: │https://test.indexer.com │ │
│ Name: │DrunkenSlug │ URL: │http://127.0.0.1:9696/1/ │ │
│ ╰─────────────────────────╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable RSS: │ ✔ │ API Key: │test-api-key │ │
│ Enable RSS: │ ✔ │ API Key: │someApiKey │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Automatic Search: │ │ Tags: │ │ │
│ Enable Automatic Search: │ │ Tags: │25 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Interactive Search: │ │ Indexer Priority ▴▾: │25 │ │
│ Enable Interactive Search: │ │ Indexer Priority ▴▾: │1 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ │
│ │
@@ -0,0 +1,42 @@
---
source: src/ui/sonarr_ui/indexers/edit_indexer_ui_tests.rs
expression: output
---
╭──────────────────────────────────────────────── Edit Indexer ─────────────────────────────────────────────────╮
│ │
│ │
│ Loading ... │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -21,16 +21,16 @@ expression: output
│ │
│ │
│ ╭────────────────────────────────╮ │
│ Minimum Age (minutes) ▴▾: │0 │ │
│ Minimum Age (minutes) ▴▾: │1 │ │
│ ╰────────────────────────────────╯ │
│ ╭────────────────────────────────╮ │
│ Retention (days) ▴▾: │0 │ │
│ Retention (days) ▴▾: │1 │ │
│ ╰────────────────────────────────╯ │
│ ╭────────────────────────────────╮ │
│ Maximum Size (MB) ▴▾: │0 │ │
│ Maximum Size (MB) ▴▾: │12345 │ │
│ ╰────────────────────────────────╯ │
│ ╭────────────────────────────────╮ │
│ RSS Sync Interval (minutes) ▴▾: │0 │ │
│ RSS Sync Interval (minutes) ▴▾: │60 │ │
│ ╰────────────────────────────────╯ │
│ │
│ │
@@ -0,0 +1,38 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭──────────────────── Delete Indexer ─────────────────────╮
│ Do you really want to delete this indexer: │
│ Test Indexer? │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│╭────────────────────────────╮╭───────────────────────────╮│
││ Yes ││ No ││
│╰────────────────────────────╯╰───────────────────────────╯│
╰───────────────────────────────────────────────────────────╯
@@ -4,5 +4,4 @@ expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer 1 Enabled Enabled Enabled 25
Test Indexer 2 Disabled Disabled Disabled 0
=> Test Indexer Enabled Enabled Enabled 25 alex
@@ -0,0 +1,35 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭─────────────── Error ───────────────╮
│ error │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰───────────────────────────────────────╯
@@ -0,0 +1,42 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭──────────────────────────────────────────────── Edit Indexer ─────────────────────────────────────────────────╮
│ │
│ ╭─────────────────────────╮ ╭─────────────────────────╮ │
│ Name: │DrunkenSlug │ URL: │http://127.0.0.1:9696/1/ │ │
│ ╰─────────────────────────╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable RSS: │ ✔ │ API Key: │someApiKey │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Automatic Search: │ ✔ │ Seed Ratio: │ratio │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Interactive Search: │ ✔ │ Tags: │25 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭─────────────────────────╮ │
│ Indexer Priority ▴▾: │1 │ │
│ ╰─────────────────────────╯ │
│ │
│ │
│ │
│ │
│ ╭───────────────────────────╮╭──────────────────────────╮ │
│ │ Save ││ Cancel │ │
│ ╰───────────────────────────╯╰──────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,42 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭──────────────────────────────────────────────── Edit Indexer ─────────────────────────────────────────────────╮
│ │
│ ╭─────────────────────────╮ ╭─────────────────────────╮ │
│ Name: │DrunkenSlug │ URL: │http://127.0.0.1:9696/1/ │ │
│ ╰─────────────────────────╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable RSS: │ ✔ │ API Key: │someApiKey │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Automatic Search: │ ✔ │ Tags: │25 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ ╭───╮ ╭─────────────────────────╮ │
│ Enable Interactive Search: │ ✔ │ Indexer Priority ▴▾: │1 │ │
│ ╰───╯ ╰─────────────────────────╯ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ ╭───────────────────────────╮╭──────────────────────────╮ │
│ │ Save ││ Cancel │ │
│ ╰───────────────────────────╯╰──────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,35 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Loading ...
╭ Testing Indexer ────────────────────╮
│ │
│ │
│ Loading ... │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰───────────────────────────────────────╯
@@ -0,0 +1,35 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭ Testing Indexer ────────────────────╮
│ │
│ │
│ Loading ... │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰───────────────────────────────────────╯
@@ -0,0 +1,48 @@
---
source: src/ui/sonarr_ui/indexers/indexers_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Indexer RSS Automatic Search Interactive Search Priority Tags
=> Test Indexer Enabled Enabled Enabled 25 alex
╭ Test All Indexers ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Indexer Pass/Fail Failure Messages │
│=> DrunkenSlug ❌ Some failure │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,48 @@
---
source: src/ui/sonarr_ui/indexers/test_all_indexers_ui_tests.rs
expression: output
---
╭ Test All Indexers ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Indexer Pass/Fail Failure Messages │
│=> DrunkenSlug ❌ Some failure │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
@@ -25,8 +25,8 @@ mod tests {
use super::*;
#[test]
fn test_test_all_indexers_ui_renders_loading_state() {
let mut app = App::test_default();
fn test_test_all_indexers_ui_renders_loading() {
let mut app = App::test_default_fully_populated();
app.is_loading = true;
app.push_navigation_stack(ActiveSonarrBlock::TestAllIndexers.into());
@@ -36,5 +36,17 @@ mod tests {
insta::assert_snapshot!(output);
}
#[test]
fn test_test_all_indexers_ui_renders() {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(ActiveSonarrBlock::TestAllIndexers.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
TestAllIndexersUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
}
}