Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate page on how to test UI #589

Closed
kdheepak opened this issue May 2, 2024 · 3 comments
Closed

Add separate page on how to test UI #589

kdheepak opened this issue May 2, 2024 · 3 comments
Labels
good first issue Good for newcomers

Comments

@kdheepak
Copy link
Contributor

kdheepak commented May 2, 2024

Currently an example for how to write tests is only shown in the tutorial. It would be nice to have it as a separate page to make it easier for search engines to find it. It'll also be easier to read for users who are interested in just that one aspect of Ratatui

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

    #[test]
    fn render() {
        let app = App::default();
        let mut buf = Buffer::empty(Rect::new(0, 0, 50, 4));

        app.render(buf.area, &mut buf);

        let mut expected = Buffer::with_lines(vec![
            "┏━━━━━━━━━━━━━ Counter App Tutorial ━━━━━━━━━━━━━┓",
            "┃                    Value: 0                    ┃",
            "┃                                                ┃",
            "┗━ Decrement <Left> Increment <Right> Quit <Q> ━━┛",
        ]);
        let title_style = Style::new().bold();
        let counter_style = Style::new().yellow();
        let key_style = Style::new().blue().bold();
        expected.set_style(Rect::new(14, 0, 22, 1), title_style);
        expected.set_style(Rect::new(28, 1, 1, 1), counter_style);
        expected.set_style(Rect::new(13, 3, 6, 1), key_style);
        expected.set_style(Rect::new(30, 3, 7, 1), key_style);
        expected.set_style(Rect::new(43, 3, 4, 1), key_style);

        // note ratatui also has an assert_buffer_eq! macro that can be used to
        // compare buffers and display the differences in a more readable way
        assert_eq!(buf, expected);
    }
}
@kdheepak kdheepak changed the title Add separate page on how to set UI Add separate page on how to test UI May 2, 2024
@kdheepak
Copy link
Contributor Author

kdheepak commented May 2, 2024

This should probably go into how-to/develop-apps: https://github.com/ratatui-org/ratatui-website/tree/main/src/content/docs/how-to/develop-apps

@kdheepak kdheepak added the good first issue Good for newcomers label May 2, 2024
@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented May 2, 2024

Should probably wait until ratatui/ratatui#1007 is settled.

@kdheepak
Copy link
Contributor Author

kdheepak commented May 2, 2024

Turns out this is a duplicate of this issue: #358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants