bitpill 0.3.3

A personal medication management TUI application built in Rust.
Documentation
// Internal imports first
use crate::presentation::tui::templates::screen_template::ScreenTemplate;

// External crates
use ratatui::Frame;
use ratatui::widgets::Paragraph;

use crate::presentation::tui::styles::content_style;

pub struct ScheduleResultInput {
    pub created_count: usize,
}

pub struct ScheduleResultPresenter;

impl ScheduleResultPresenter {
    pub fn present(&self, f: &mut Frame, input: &ScheduleResultInput) {
        let msg = format!(
            "  {} dose(s) scheduled. Press any key to return.",
            input.created_count
        );

        ScreenTemplate {
            subtitle: "Schedule Result",
            help: " [any key] Back",
            mode: "NORMAL",
        }
        .render(f, |f, area| {
            f.render_widget(Paragraph::new(msg).style(content_style()), area);
        });
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use ratatui::Terminal;
    use ratatui::backend::TestBackend;

    #[test]
    fn present_renders_scheduled_count() {
        let mut terminal = Terminal::new(TestBackend::new(80, 24)).unwrap();
        let input = ScheduleResultInput { created_count: 3 };
        terminal
            .draw(|f| ScheduleResultPresenter.present(f, &input))
            .unwrap();
        let content: String = terminal
            .backend()
            .buffer()
            .content
            .iter()
            .map(|c| c.symbol())
            .collect();
        assert!(content.contains('3'));
    }

    #[test]
    fn present_with_zero_count_does_not_panic() {
        let mut terminal = Terminal::new(TestBackend::new(80, 24)).unwrap();
        let input = ScheduleResultInput { created_count: 0 };
        terminal
            .draw(|f| ScheduleResultPresenter.present(f, &input))
            .unwrap();
    }
}