Most of our application is visual but the filtering logic is just normal Rust. We can test it without opening a GPUI window.
Add these tests at the bottom of main.rs:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_view_shows_every_active_issue() {
let app = App::new();
assert_eq!(app.visible_issues().len(), 5);
}
#[test]
fn assigned_tab_filters_the_issue_collection() {
let mut app = App::new();
app.active_tab = IssueTab::AssignedToMe;
assert_eq!(app.visible_issues().len(), 3);
}
#[test]
fn completed_issues_leave_the_active_view_but_remain_in_projects() {
let mut app = App::new();
app.issues[0].completed = true;
assert_eq!(app.visible_issues().len(), 4);
app.navigation = Navigation::Projects;
assert_eq!(app.visible_issues().len(), 5);
}
#[test]
fn navigation_and_tabs_are_combined() {
let mut app = App::new();
app.navigation = Navigation::MyIssues;
app.active_tab = IssueTab::CreatedByMe;
let issues = app.visible_issues();
assert_eq!(issues.len(), 1);
assert_eq!(issues[0].id, "ENG-122");
}
}Run them with:
cargo testYou should see:
test result: ok. 4 passed; 0 failedOnce the tests pass, launch the application one final time:
cargo runNow check the complete interaction flow:
- Click every sidebar item and watch the heading change.
- Switch between all three tabs.
- Select several issue cards.
- Complete an issue from Active issues.
- Open Projects and restore it.
- Confirm that all visible counts update.
- Produce a filter with no results and check the empty state.
GPUI Kit tests component state without launching a normal application window as well. Its button tests construct buttons, resolve their selected and disabled styles and assert the result directly in source.