pulsedeck 0.2.0

A focused terminal internet radio player with fast search, saved stations, themes, visualizers, and resilient playback
use super::*;

impl App {
    pub(super) fn toggle_help(&mut self) {
        self.show_help = !self.show_help;
        if self.show_help {
            self.show_settings = false;
        }
    }

    pub(super) fn toggle_settings(&mut self) {
        self.show_settings = !self.show_settings;
        if self.show_settings {
            self.show_help = false;
        }
    }

    pub(super) fn cycle_layout(&mut self) {
        self.layout_mode = match self.layout_mode {
            LayoutMode::Split => LayoutMode::LeftOnly,
            LayoutMode::LeftOnly => LayoutMode::RightOnly,
            LayoutMode::RightOnly => LayoutMode::Split,
        };
        super::ui_state::save_ui_state_or_notice(self);
    }

    pub(super) fn toggle_visualizer_mode(&mut self) {
        self.visualizer_mode = (self.visualizer_mode + 1) % 3;
        super::ui_state::save_ui_state_or_notice(self);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::favorites::Library;

    fn test_app() -> App {
        App::new(Library::in_memory(vec![]))
    }

    #[test]
    fn toggle_help_closes_settings() {
        let mut app = test_app();
        app.show_settings = true;

        app.toggle_help();

        assert!(app.show_help);
        assert!(!app.show_settings);
    }

    #[test]
    fn toggle_settings_closes_help() {
        let mut app = test_app();
        app.show_help = true;

        app.toggle_settings();

        assert!(app.show_settings);
        assert!(!app.show_help);
    }

    #[test]
    fn cycle_layout_wraps() {
        let mut app = test_app();

        app.cycle_layout();
        assert_eq!(app.layout_mode, LayoutMode::LeftOnly);
        app.cycle_layout();
        assert_eq!(app.layout_mode, LayoutMode::RightOnly);
        app.cycle_layout();
        assert_eq!(app.layout_mode, LayoutMode::Split);
    }

    #[test]
    fn toggle_visualizer_mode_wraps() {
        let mut app = test_app();

        app.toggle_visualizer_mode();
        assert_eq!(app.visualizer_mode, 1);
        app.toggle_visualizer_mode();
        assert_eq!(app.visualizer_mode, 2);
        app.toggle_visualizer_mode();
        assert_eq!(app.visualizer_mode, 0);
    }
}