various: remove dead code; fix skipped tests

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9100489be899f9e9fbd32f6aca3080196a6a6964
This commit is contained in:
raf 2026-02-05 00:18:02 +03:00
commit cfdc3d0622
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
18 changed files with 1445 additions and 28 deletions

View file

@ -293,7 +293,6 @@ pub struct CreateSavedSearchRequest {
pub sort_order: Option<String>,
}
#[allow(dead_code)]
impl ApiClient {
pub fn new(base_url: &str, api_key: Option<&str>) -> Self {
let mut headers = header::HeaderMap::new();
@ -1124,3 +1123,40 @@ impl ApiClient {
.unwrap_or_else(|_| Client::new());
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_base_url() {
let client = ApiClient::new("http://localhost:3000", None);
assert_eq!(client.base_url(), "http://localhost:3000");
}
#[test]
fn test_stream_url() {
let client = ApiClient::new("http://localhost:3000", None);
let url = client.stream_url("test-id-123");
assert_eq!(url, "http://localhost:3000/api/v1/media/test-id-123/stream");
}
#[test]
fn test_thumbnail_url() {
let client = ApiClient::new("http://localhost:3000", None);
let url = client.thumbnail_url("test-id-456");
assert_eq!(url, "http://localhost:3000/api/v1/media/test-id-456/thumbnail");
}
#[test]
fn test_client_creation_with_api_key() {
let client = ApiClient::new("http://localhost:3000", Some("test-key"));
assert_eq!(client.base_url(), "http://localhost:3000");
}
#[test]
fn test_base_url_trailing_slash() {
let client = ApiClient::new("http://localhost:3000/", None);
assert_eq!(client.base_url(), "http://localhost:3000");
}
}

View file

@ -5,7 +5,7 @@ use super::markdown_viewer::MarkdownViewer;
use super::media_player::MediaPlayer;
use super::pdf_viewer::PdfViewer;
use super::utils::{format_duration, format_size, media_category, type_badge_class};
use crate::client::{MediaResponse, MediaUpdateEvent, TagResponse};
use crate::client::{ApiClient, MediaResponse, MediaUpdateEvent, TagResponse};
#[component]
pub fn Detail(
@ -100,9 +100,11 @@ pub fn Detail(
let has_system_fields = !system_fields.is_empty();
let has_user_fields = !user_fields.is_empty();
// Media preview URLs
let stream_url = format!("{}/api/v1/media/{}/stream", server_url, media.id);
let thumbnail_url = format!("{}/api/v1/media/{}/thumbnail", server_url, media.id);
// Media preview URLs - use ApiClient methods for consistent URL building
let client = ApiClient::new(&server_url, None);
tracing::trace!("Using API base URL: {}", client.base_url());
let stream_url = client.stream_url(&media.id);
let thumbnail_url = client.thumbnail_url(&media.id);
let category = media_category(&media.media_type);
let has_thumbnail = media.has_thumbnail;

View file

@ -42,19 +42,16 @@ impl Default for PlayQueue {
impl PlayQueue {
/// Check if the queue is empty.
#[allow(dead_code)]
pub fn is_empty(&self) -> bool {
self.items.is_empty()
}
/// Get the current item in the queue.
#[allow(dead_code)]
pub fn current(&self) -> Option<&QueueItem> {
self.items.get(self.current_index)
}
/// Advance to the next item based on repeat mode.
#[allow(dead_code)]
pub fn next(&mut self) -> Option<&QueueItem> {
if self.items.is_empty() {
return None;
@ -77,7 +74,6 @@ impl PlayQueue {
}
/// Go to the previous item based on repeat mode.
#[allow(dead_code)]
pub fn previous(&mut self) -> Option<&QueueItem> {
if self.items.is_empty() {
return None;
@ -91,13 +87,11 @@ impl PlayQueue {
}
/// Add an item to the queue.
#[allow(dead_code)]
pub fn add(&mut self, item: QueueItem) {
self.items.push(item);
}
/// Remove an item from the queue by index.
#[allow(dead_code)]
pub fn remove(&mut self, index: usize) {
if index < self.items.len() {
self.items.remove(index);
@ -108,14 +102,12 @@ impl PlayQueue {
}
/// Clear all items from the queue.
#[allow(dead_code)]
pub fn clear(&mut self) {
self.items.clear();
self.current_index = 0;
}
/// Toggle between repeat modes: Off -> All -> One -> Off.
#[allow(dead_code)]
pub fn toggle_repeat(&mut self) {
self.repeat = match self.repeat {
RepeatMode::Off => RepeatMode::All,
@ -125,7 +117,6 @@ impl PlayQueue {
}
/// Toggle shuffle mode on/off.
#[allow(dead_code)]
pub fn toggle_shuffle(&mut self) {
self.shuffle = !self.shuffle;
}
@ -536,3 +527,178 @@ pub fn QueuePanel(
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_play_queue_is_empty() {
let queue = PlayQueue::default();
assert!(queue.is_empty());
}
#[test]
fn test_play_queue_add() {
let mut queue = PlayQueue::default();
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Test Song".to_string(),
artist: Some("Test Artist".to_string()),
duration_secs: Some(180.0),
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
assert!(!queue.is_empty());
assert_eq!(queue.items.len(), 1);
}
#[test]
fn test_play_queue_current() {
let mut queue = PlayQueue::default();
assert!(queue.current().is_none());
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Test Song".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
assert!(queue.current().is_some());
assert_eq!(queue.current().unwrap().media_id, "test1");
}
#[test]
fn test_play_queue_next() {
let mut queue = PlayQueue::default();
queue.repeat = RepeatMode::Off;
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Song 1".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
queue.add(QueueItem {
media_id: "test2".to_string(),
title: "Song 2".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test2".to_string(),
thumbnail_url: None,
});
let next = queue.next();
assert!(next.is_some());
assert_eq!(next.unwrap().media_id, "test2");
}
#[test]
fn test_play_queue_previous() {
let mut queue = PlayQueue::default();
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Song 1".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
queue.add(QueueItem {
media_id: "test2".to_string(),
title: "Song 2".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test2".to_string(),
thumbnail_url: None,
});
queue.current_index = 1;
let prev = queue.previous();
assert!(prev.is_some());
assert_eq!(prev.unwrap().media_id, "test1");
}
#[test]
fn test_play_queue_remove() {
let mut queue = PlayQueue::default();
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Song 1".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
queue.add(QueueItem {
media_id: "test2".to_string(),
title: "Song 2".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test2".to_string(),
thumbnail_url: None,
});
queue.remove(0);
assert_eq!(queue.items.len(), 1);
assert_eq!(queue.items[0].media_id, "test2");
}
#[test]
fn test_play_queue_clear() {
let mut queue = PlayQueue::default();
queue.add(QueueItem {
media_id: "test1".to_string(),
title: "Song 1".to_string(),
artist: None,
duration_secs: None,
media_type: "audio".to_string(),
stream_url: "/stream/test1".to_string(),
thumbnail_url: None,
});
queue.clear();
assert!(queue.is_empty());
assert_eq!(queue.current_index, 0);
}
#[test]
fn test_play_queue_toggle_repeat() {
let mut queue = PlayQueue::default();
assert_eq!(queue.repeat, RepeatMode::Off);
queue.toggle_repeat();
assert_eq!(queue.repeat, RepeatMode::All);
queue.toggle_repeat();
assert_eq!(queue.repeat, RepeatMode::One);
queue.toggle_repeat();
assert_eq!(queue.repeat, RepeatMode::Off);
}
#[test]
fn test_play_queue_toggle_shuffle() {
let mut queue = PlayQueue::default();
assert!(!queue.shuffle);
queue.toggle_shuffle();
assert!(queue.shuffle);
queue.toggle_shuffle();
assert!(!queue.shuffle);
}
}