Skip to content

test(ui): add dummy test data generator#85

Merged
JayanAXHF merged 2 commits intomainfrom
03-08-test_add-tests
Mar 8, 2026
Merged

test(ui): add dummy test data generator#85
JayanAXHF merged 2 commits intomainfrom
03-08-test_add-tests

Conversation

@JayanAXHF
Copy link
Owner

test(ui): add dummy test data generator

test(ui): add UI snapshot tests for the TUI components

@JayanAXHF JayanAXHF marked this pull request as ready for review March 8, 2026 04:59
Copy link
Owner Author

JayanAXHF commented Mar 8, 2026

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR introduces a seeded dummy data generator (src/ui/testing.rs) using the fake crate, and adds snapshot tests for the major TUI components (IssuePreview, StatusBar, TitleBar, TextSearch, HelpComponent). It also correctly centralises the buffer_to_string helper into tests/support/mod.rs, resolving the previous duplication issue. Two bugs are present that need fixing before this is mergeable:

  • use bench_support compile error under --features benches: The unconditional use bench_support::{issue_body_fixture, markdown_fixture} on line 27 of src/ui/testing.rs is only valid when cfg(not(feature = "benches")) (i.e., when the local stub module exists). When the benches feature is active, the stub module is excluded but the use statement remains, causing a path-resolution compile error.
  • AppState::new argument order swapped in test files: AppState::new takes (repo, owner, current_user) but all three affected test files pass "owner" as repo and "repo" as owner. This is confirmed by the committed status_bar snapshot, which renders repo/owner instead of the correct owner/repo. The same swap is present in tests/text_search.rs and tests/status_bar.rs.

Important Files Changed

Filename Overview
src/ui/testing.rs New dummy data generator using the fake crate; contains a compile error: unconditional use bench_support::... breaks when --features benches is active.
tests/support/mod.rs New shared test helper that centralises buffer_to_string (with correct trailing-line stripping) for all integration test files — good improvement.
tests/issue_preview.rs New snapshot tests for IssuePreview; AppState::new arguments are passed in the wrong order (owner/repo swapped), producing incorrect snapshot data.
tests/status_bar.rs New snapshot test for StatusBar; AppState::new arguments are swapped, causing the snapshot to display "repo/owner" instead of "owner/repo".
tests/text_search.rs New snapshot tests for TextSearch; AppState::new arguments are swapped, though this doesn't visibly affect the text-search snapshots since it doesn't render the repo/owner label.
tests/title_bar.rs New snapshot test for TitleBar; no AppState dependency, uses shared support helper correctly.
tests/help.rs New snapshot tests for HelpComponent covering keybinds-only, text-wrapping, mixed content, and empty states; no issues found.
src/ui/mod.rs testing module correctly gated with #[cfg(test)]; no production code change.
src/ui/issue_data.rs Adds intern_test_author (gated by #[cfg(test)]) and upsert_issue helper; correctly scoped and no production impact.
Cargo.toml Adds fake = "4.4.0" and insta = "1.40" to [dev-dependencies] only — correctly scoped, no production binary impact.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[cargo test] --> B{benches feature?}
    B -- OFF --> C[src/ui/testing.rs compiled with cfg test]
    B -- ON --> D[src/ui/testing.rs compiled with cfg test]

    C --> E[local mod bench_support stubs used]
    E --> F[use bench_support resolves OK]
    F --> G[dummy_ui_data_with builds DummyUiData]

    D --> H[use crate::bench_support real fixtures]
    D --> I[use bench_support ERROR - no local module]
    I --> J[compile error]

    G --> K[tests/support/mod.rs\nbuffer_to_string centralised]
    K --> L[tests/issue_preview.rs]
    K --> M[tests/status_bar.rs]
    K --> N[tests/text_search.rs]
    K --> O[tests/title_bar.rs]
    K --> P[tests/help.rs]

    L --> Q[AppState::new swapped args\nrepo=owner owner=repo]
    M --> Q
    N --> Q

    Q --> R[Incorrect snapshot: repo/owner\ninstead of owner/repo]
Loading

Last reviewed commit: e1c789a

@JayanAXHF JayanAXHF force-pushed the 03-08-test_add-tests branch 2 times, most recently from 72606cc to e1c789a Compare March 8, 2026 05:35
Comment on lines +19 to +23
let mut preview = IssuePreview::new(AppState::new(
"owner".to_string(),
"repo".to_string(),
"user".to_string(),
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppState::new argument order swapped

AppState::new is declared as new(repo: String, owner: String, current_user: String) (repo first, owner second), but the call here passes "owner" as the first argument (bound to repo) and "repo" as the second (bound to owner). This causes the wrong values to be stored, and the bug is visible in the committed status_bar snapshot, which displays repo/owner instead of owner/repo.

The same swap occurs in tests/text_search.rs (lines 18–22) and tests/status_bar.rs (lines 19–23).

Suggested change
let mut preview = IssuePreview::new(AppState::new(
"owner".to_string(),
"repo".to_string(),
"user".to_string(),
));
let mut preview = IssuePreview::new(AppState::new(
"repo".to_string(),
"owner".to_string(),
"user".to_string(),
));

Comment on lines +26 to +27
#[allow(unused_imports)]
use bench_support::{issue_body_fixture, markdown_fixture};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditional use bench_support fails to compile with --features benches

The local mod bench_support {} stub is only compiled when cfg(not(feature = "benches")) is active. When the benches feature IS enabled, that module does not exist, so use bench_support::{issue_body_fixture, markdown_fixture} cannot resolve the path and produces a compile error. The #[allow(unused_imports)] only suppresses an unused-import warning; it cannot suppress a path-resolution error.

Running cargo test --features benches will fail to compile this module because of this line.

The fix is to gate this use statement the same way as the stub module:

Suggested change
#[allow(unused_imports)]
use bench_support::{issue_body_fixture, markdown_fixture};
#[cfg(not(feature = "benches"))]
use bench_support::{issue_body_fixture, markdown_fixture};

@JayanAXHF JayanAXHF force-pushed the 03-08-test_add-tests branch from e1c789a to d4351a9 Compare March 8, 2026 05:46
@JayanAXHF JayanAXHF force-pushed the 03-08-test_add-tests branch from d4351a9 to 1bf264a Compare March 8, 2026 05:57
Copy link
Owner Author

JayanAXHF commented Mar 8, 2026

Merge activity

  • Mar 8, 6:04 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 8, 6:05 AM UTC: Graphite rebased this pull request as part of a merge.
  • Mar 8, 6:06 AM UTC: @JayanAXHF merged this pull request with Graphite.

@JayanAXHF JayanAXHF changed the base branch from test/add-benchmarks to graphite-base/85 March 8, 2026 06:04
@JayanAXHF JayanAXHF changed the base branch from graphite-base/85 to main March 8, 2026 06:04
@JayanAXHF JayanAXHF force-pushed the 03-08-test_add-tests branch from 1bf264a to 00d175a Compare March 8, 2026 06:05
@JayanAXHF JayanAXHF merged commit e5150e4 into main Mar 8, 2026
3 checks passed
@JayanAXHF JayanAXHF deleted the 03-08-test_add-tests branch March 8, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant