feat(readarr): add the blocklist UI
Render the Readarr blocklist table with the item details popup, the remove item prompt and the clear blocklist prompt, and dispatch it from ReadarrUi so the tab is reachable. The snapshot suite covers every block in BLOCKLIST_BLOCKS plus loading and empty states. A second set of snapshots seeds a two row fixture with distinct values in every column and selects the second row, so that reading items[0] instead of the current selection cannot pass.
This commit is contained in:
14 files changed
+557
-3
No files matched your search
@@ -0,0 +1,147 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::readarr::readarr_data::{ActiveReadarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::readarr_ui::blocklist::BlocklistUi;
|
||||
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_ui_accepts() {
|
||||
ActiveReadarrBlock::iter().for_each(|active_readarr_block| {
|
||||
if BLOCKLIST_BLOCKS.contains(&active_readarr_block) {
|
||||
assert!(BlocklistUi::accepts(active_readarr_block.into()));
|
||||
} else {
|
||||
assert!(!BlocklistUi::accepts(active_readarr_block.into()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mod snapshot_tests {
|
||||
use chrono::DateTime;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::readarr_models::{Author, BlocklistItem};
|
||||
use crate::models::servarr_models::{Quality, QualityWrapper};
|
||||
use crate::ui::ui_test_utils::test_utils::TerminalSize;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_ui_renders_loading() {
|
||||
let mut app = App::test_default();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(ActiveReadarrBlock::Blocklist.into());
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
BlocklistUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blocklist_ui_renders_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveReadarrBlock::Blocklist.into());
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
BlocklistUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(output);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_ui_renders(
|
||||
#[values(
|
||||
ActiveReadarrBlock::Blocklist,
|
||||
ActiveReadarrBlock::BlocklistItemDetails,
|
||||
ActiveReadarrBlock::DeleteBlocklistItemPrompt,
|
||||
ActiveReadarrBlock::BlocklistClearAllItemsPrompt,
|
||||
ActiveReadarrBlock::BlocklistSortPrompt
|
||||
)]
|
||||
active_readarr_block: ActiveReadarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_readarr_block.into());
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
BlocklistUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(format!("blocklist_tab_{active_readarr_block}"), output);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_blocklist_ui_renders_second_item_selected(
|
||||
#[values(
|
||||
ActiveReadarrBlock::Blocklist,
|
||||
ActiveReadarrBlock::BlocklistItemDetails,
|
||||
ActiveReadarrBlock::DeleteBlocklistItemPrompt
|
||||
)]
|
||||
active_readarr_block: ActiveReadarrBlock,
|
||||
) {
|
||||
let mut app = App::test_default();
|
||||
app.data.readarr_data.blocklist.set_items(blocklist_vec());
|
||||
app.data.readarr_data.blocklist.select_index(Some(1));
|
||||
app.push_navigation_stack(active_readarr_block.into());
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
BlocklistUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(
|
||||
format!("blocklist_second_item_selected_{active_readarr_block}"),
|
||||
output
|
||||
);
|
||||
}
|
||||
|
||||
fn blocklist_vec() -> Vec<BlocklistItem> {
|
||||
vec![
|
||||
BlocklistItem {
|
||||
id: 1,
|
||||
author_id: 1,
|
||||
source_title: "First Source Title".to_owned(),
|
||||
quality: QualityWrapper {
|
||||
quality: Quality {
|
||||
name: "EPUB".to_owned(),
|
||||
},
|
||||
},
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2023-05-20T21:29:16Z").unwrap()),
|
||||
protocol: "usenet".to_owned(),
|
||||
indexer: "DrunkenSlug".to_owned(),
|
||||
message: "first blocklist message".to_owned(),
|
||||
author: Author {
|
||||
id: 1,
|
||||
author_name: "First Author".into(),
|
||||
..Author::default()
|
||||
},
|
||||
..BlocklistItem::default()
|
||||
},
|
||||
BlocklistItem {
|
||||
id: 2,
|
||||
author_id: 2,
|
||||
source_title: "Second Source Title".to_owned(),
|
||||
quality: QualityWrapper {
|
||||
quality: Quality {
|
||||
name: "MOBI".to_owned(),
|
||||
},
|
||||
},
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-08-14T09:03:47Z").unwrap()),
|
||||
protocol: "torrent".to_owned(),
|
||||
indexer: "Nyaa".to_owned(),
|
||||
message: "second blocklist message".to_owned(),
|
||||
author: Author {
|
||||
id: 2,
|
||||
author_name: "Second Author".into(),
|
||||
..Author::default()
|
||||
},
|
||||
..BlocklistItem::default()
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
use crate::app::App;
|
||||
use crate::models::Route;
|
||||
use crate::models::readarr_models::BlocklistItem;
|
||||
use crate::models::servarr_data::readarr::readarr_data::{ActiveReadarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::styles::{ManagarrStyle, secondary_style};
|
||||
use crate::ui::utils::layout_block_top_border;
|
||||
use crate::ui::widgets::confirmation_prompt::ConfirmationPrompt;
|
||||
use crate::ui::widgets::managarr_table::ManagarrTable;
|
||||
use crate::ui::widgets::message::Message;
|
||||
use crate::ui::widgets::popup::{Popup, Size};
|
||||
use ratatui::Frame;
|
||||
use ratatui::layout::{Alignment, Constraint, Rect};
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::{Line, Text};
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "blocklist_ui_tests.rs"]
|
||||
mod blocklist_ui_tests;
|
||||
|
||||
pub(super) struct BlocklistUi;
|
||||
|
||||
impl DrawUi for BlocklistUi {
|
||||
fn accepts(route: Route) -> bool {
|
||||
if let Route::Readarr(active_readarr_block, _) = route {
|
||||
return BLOCKLIST_BLOCKS.contains(&active_readarr_block);
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Readarr(active_readarr_block, _) = app.get_current_route() {
|
||||
draw_blocklist_table(f, app, area);
|
||||
|
||||
match active_readarr_block {
|
||||
ActiveReadarrBlock::BlocklistItemDetails => {
|
||||
draw_blocklist_item_details_popup(f, app);
|
||||
}
|
||||
ActiveReadarrBlock::DeleteBlocklistItemPrompt => {
|
||||
let prompt = format!(
|
||||
"Do you want to remove this item from your blocklist: \n{}?",
|
||||
app
|
||||
.data
|
||||
.readarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.source_title
|
||||
);
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Remove Item from Blocklist")
|
||||
.prompt(&prompt)
|
||||
.yes_no_value(app.data.readarr_data.prompt_confirm);
|
||||
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::MediumPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
ActiveReadarrBlock::BlocklistClearAllItemsPrompt => {
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Clear Blocklist")
|
||||
.prompt("Do you want to clear your blocklist?")
|
||||
.yes_no_value(app.data.readarr_data.prompt_confirm);
|
||||
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::SmallPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_blocklist_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Route::Readarr(active_readarr_block, _) = app.get_current_route() {
|
||||
let blocklist_row_mapping = |blocklist_item: &BlocklistItem| {
|
||||
let BlocklistItem {
|
||||
source_title,
|
||||
author,
|
||||
quality,
|
||||
date,
|
||||
..
|
||||
} = blocklist_item;
|
||||
|
||||
let title = author.author_name.text.to_owned();
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(title),
|
||||
Cell::from(source_title.to_owned()),
|
||||
Cell::from(quality.quality.name.to_owned()),
|
||||
Cell::from(date.to_string()),
|
||||
])
|
||||
.primary()
|
||||
};
|
||||
let blocklist_table = ManagarrTable::new(
|
||||
Some(&mut app.data.readarr_data.blocklist),
|
||||
blocklist_row_mapping,
|
||||
)
|
||||
.block(layout_block_top_border())
|
||||
.loading(app.is_loading)
|
||||
.sorting(active_readarr_block == ActiveReadarrBlock::BlocklistSortPrompt)
|
||||
.headers(["Author Name", "Source Title", "Quality", "Date"])
|
||||
.constraints([
|
||||
Constraint::Percentage(27),
|
||||
Constraint::Percentage(43),
|
||||
Constraint::Percentage(13),
|
||||
Constraint::Percentage(17),
|
||||
]);
|
||||
|
||||
f.render_widget(blocklist_table, area);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_blocklist_item_details_popup(f: &mut Frame<'_>, app: &mut App<'_>) {
|
||||
let current_selection = if app.data.readarr_data.blocklist.items.is_empty() {
|
||||
BlocklistItem::default()
|
||||
} else {
|
||||
app.data.readarr_data.blocklist.current_selection().clone()
|
||||
};
|
||||
let BlocklistItem {
|
||||
source_title,
|
||||
protocol,
|
||||
indexer,
|
||||
message,
|
||||
..
|
||||
} = current_selection;
|
||||
let text = Text::from(vec![
|
||||
Line::from(vec![
|
||||
"Name: ".bold().secondary(),
|
||||
source_title.to_owned().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Protocol: ".bold().secondary(),
|
||||
protocol.to_owned().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Indexer: ".bold().secondary(),
|
||||
indexer.to_owned().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Message: ".bold().secondary(),
|
||||
message.to_owned().secondary(),
|
||||
]),
|
||||
]);
|
||||
|
||||
let message = Message::new(text)
|
||||
.title("Details")
|
||||
.style(secondary_style())
|
||||
.alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(Popup::new(message).size(Size::NarrowMessage), f.area());
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name Source Title Quality Date
|
||||
First Author First Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
=> Second Author Second Source Title MOBI 2024-08-14 09:03:47 UTC
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name Source Title Quality Date
|
||||
First Author First Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
=> Second Author Second Source Title MOBI 2024-08-14 09:03:47 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭─────────────────────────────────── Details ───────────────────────────────────╮
|
||||
│Name: Second Source Title │
|
||||
│Protocol: torrent │
|
||||
│Indexer: Nyaa │
|
||||
│Message: second blocklist message │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰─────────────────────────────────────────────────────────────────────────────────╯
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name Source Title Quality Date
|
||||
First Author First Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
=> Second Author Second Source Title MOBI 2024-08-14 09:03:47 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭────────────── Remove Item from Blocklist ───────────────╮
|
||||
│ Do you want to remove this item from your blocklist: │
|
||||
│ Second Source Title? │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│╭────────────────────────────╮╭───────────────────────────╮│
|
||||
││ Yes ││ No ││
|
||||
│╰────────────────────────────╯╰───────────────────────────╯│
|
||||
╰───────────────────────────────────────────────────────────╯
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name ▼ Source Title Quality Date
|
||||
=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name ▼ Source Title Quality Date
|
||||
=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭────── Clear Blocklist ──────╮
|
||||
│ Do you want to clear your │
|
||||
│ blocklist? │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│╭──────────────╮╭─────────────╮│
|
||||
││ Yes ││ No ││
|
||||
│╰──────────────╯╰─────────────╯│
|
||||
╰───────────────────────────────╯
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name ▼ Source Title Quality Date
|
||||
=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭─────────────────────────────────── Details ───────────────────────────────────╮
|
||||
│Name: Test Source Title │
|
||||
│Protocol: usenet │
|
||||
│Indexer: DrunkenSlug │
|
||||
│Message: test message │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰─────────────────────────────────────────────────────────────────────────────────╯
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name Source Title Quality Date
|
||||
=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭───────────────────────────────╮
|
||||
│Something │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰───────────────────────────────╯
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Author Name ▼ Source Title Quality Date
|
||||
=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭────────────── Remove Item from Blocklist ───────────────╮
|
||||
│ Do you want to remove this item from your blocklist: │
|
||||
│ Test Source Title? │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│╭────────────────────────────╮╭───────────────────────────╮│
|
||||
││ Yes ││ No ││
|
||||
│╰────────────────────────────╯╰───────────────────────────╯│
|
||||
╰───────────────────────────────────────────────────────────╯
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: src/ui/readarr_ui/blocklist/blocklist_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Loading ...
|
||||
@@ -21,6 +21,7 @@ use super::{
|
||||
},
|
||||
widgets::loading_block::LoadingBlock,
|
||||
};
|
||||
use crate::ui::readarr_ui::blocklist::BlocklistUi;
|
||||
use crate::ui::utils::{extract_monitored_disk_space_vec, extract_monitored_root_folders};
|
||||
use crate::{
|
||||
app::App,
|
||||
@@ -34,6 +35,7 @@ use crate::{
|
||||
utils::convert_to_gb,
|
||||
};
|
||||
|
||||
mod blocklist;
|
||||
mod library;
|
||||
mod readarr_ui_utils;
|
||||
|
||||
@@ -54,6 +56,7 @@ impl DrawUi for ReadarrUi {
|
||||
|
||||
match route {
|
||||
_ if LibraryUi::accepts(route) => LibraryUi::draw(f, app, content_area),
|
||||
_ if BlocklistUi::accepts(route) => BlocklistUi::draw(f, app, content_area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@ expression: output
|
||||
---
|
||||
╭ Authors ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Library │ Downloads │ Blocklist │ History │ Root Folders │ Indexers │ System │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Author Name ▼ Source Title Quality Date │
|
||||
│=> Test Author Test Source Title EPUB 2023-05-20 21:29:16 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
|
||||
Reference in new issue
Block a user