improvements to the sleep timer
This commit is contained in:
@@ -28,6 +28,9 @@ pub struct AutoplaySettings {
|
||||
pub enabled: bool,
|
||||
/// Countdown duration in seconds before auto-playing next episode
|
||||
pub countdown_seconds: u32,
|
||||
/// Maximum number of episodes to auto-play consecutively (0 = unlimited)
|
||||
#[serde(default)]
|
||||
pub max_episodes: u32,
|
||||
}
|
||||
|
||||
impl Default for AutoplaySettings {
|
||||
@@ -35,6 +38,7 @@ impl Default for AutoplaySettings {
|
||||
Self {
|
||||
enabled: true,
|
||||
countdown_seconds: 10,
|
||||
max_episodes: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +60,24 @@ mod tests {
|
||||
let settings = AutoplaySettings::default();
|
||||
assert!(settings.enabled);
|
||||
assert_eq!(settings.countdown_seconds, 10);
|
||||
assert_eq!(settings.max_episodes, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autoplay_settings_backward_compat() {
|
||||
// Deserialize old JSON without max_episodes field
|
||||
let json = r#"{"enabled":true,"countdownSeconds":15}"#;
|
||||
let settings: AutoplaySettings = serde_json::from_str(json).unwrap();
|
||||
assert!(settings.enabled);
|
||||
assert_eq!(settings.countdown_seconds, 15);
|
||||
assert_eq!(settings.max_episodes, 0); // defaults to 0 (unlimited)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autoplay_settings_with_max_episodes() {
|
||||
let json = r#"{"enabled":true,"countdownSeconds":10,"maxEpisodes":5}"#;
|
||||
let settings: AutoplaySettings = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(settings.max_episodes, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -63,6 +85,7 @@ mod tests {
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 2, // Too short
|
||||
max_episodes: 0,
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 5); // Clamped to min
|
||||
@@ -70,6 +93,7 @@ mod tests {
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 60, // Too long
|
||||
max_episodes: 0,
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 30); // Clamped to max
|
||||
@@ -77,6 +101,7 @@ mod tests {
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 15, // Valid
|
||||
max_episodes: 0,
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 15); // Unchanged
|
||||
|
||||
Reference in New Issue
Block a user