Skip to content

🧪 [Test] Add unit tests for core TUI UI components#490

Draft
Dexploarer wants to merge 1 commit into
developfrom
test-coverage-tui-components-14764441107623730950
Draft

🧪 [Test] Add unit tests for core TUI UI components#490
Dexploarer wants to merge 1 commit into
developfrom
test-coverage-tui-components-14764441107623730950

Conversation

@Dexploarer
Copy link
Copy Markdown
Owner

🎯 What: Added dedicated, high-quality test suites for previously untested ToolExecutionComponent, AssistantMessageComponent, and UserMessageComponent in src/tui/components/.
📊 Coverage: Added validation of component initialization, Markdown theme bindings, component-specific behavior like loader management, image attachment processing, thinking stream generation, long argument parsing and collapse mechanisms, and final UI layout construction.
Result: Verified reliable layout rules and state progression logic locally across tested TUI UI components and successfully bumped root unit coverage levels without modifying any production logic.


PR created automatically by Jules for task 14764441107623730950 started by @Dexploarer

@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 233fd66a-ff66-4534-a1af-94b50ba66113

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-coverage-tui-components-14764441107623730950

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +108 to +129
it("adds and renders images", () => {
const component = new AssistantMessageComponent();

component.updateContent("Look at this");
component.finalize();

component.addImage({
base64: "dGVzdA==",
mimeType: "image/png",
filename: "test.png"
});

expect(imageInstances.length).toBe(1);

const rendered = component.render(100);
expect(rendered).toEqual([
"",
"Look at this",
"", // spacer
"[Image]"
]);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The test for image addition does not verify the component's behavior when invalid or incomplete image data is provided. This could mask bugs in error handling logic. Consider adding test cases that pass malformed or missing fields in the image object to ensure the component handles such cases gracefully and does not throw uncaught exceptions.

Comment on lines +131 to +142
it("invalidates all sub-components", () => {
const component = new AssistantMessageComponent(true);
component.updateThinking("Hmm");
component.addImage({ base64: "dGVzdA==", mimeType: "image/png" });

component.invalidate();

// Check that at least some invalidates were called
const someMarkdownInvalidated = markdownInstances.some(md => md.invalidate.mock.calls.length > 0);
expect(someMarkdownInvalidated).toBe(true);
expect(imageInstances[0].invalidate).toHaveBeenCalled();
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The invalidation test only checks that at least one markdown instance is invalidated (someMarkdownInvalidated), but does not verify that all markdown and image instances are invalidated as expected. This could allow partial invalidation bugs to go undetected. Consider asserting that every markdown and image instance's invalidate method is called to ensure complete invalidation.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces unit tests for the AssistantMessageComponent, ToolExecutionComponent, and UserMessageComponent to verify their rendering and state logic. The reviewer suggested strengthening assertions for component invalidation, improving the mocking of the Box component to allow for instance verification, and removing an unused require statement.

Comment on lines +139 to +140
const someMarkdownInvalidated = markdownInstances.some(md => md.invalidate.mock.calls.length > 0);
expect(someMarkdownInvalidated).toBe(true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The assertion using .some() is relatively weak as it only verifies that at least one markdown instance was invalidated. Since the component is expected to invalidate all its active sub-components (both the main markdown and the thinking markdown), it's better to verify each one specifically.

Suggested change
const someMarkdownInvalidated = markdownInstances.some(md => md.invalidate.mock.calls.length > 0);
expect(someMarkdownInvalidated).toBe(true);
expect(markdownInstances[0].invalidate).toHaveBeenCalled();
expect(markdownInstances[markdownInstances.length - 1].invalidate).toHaveBeenCalled();

Comment on lines +21 to +23
let boxChildren: any[] = [];
let boxBgFn: Function | null = null;
let loaderInstance: any = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Consider adding a boxInstance variable to capture the Box instance created by the component, allowing you to verify its methods (like invalidate) in tests.

Suggested change
let boxChildren: any[] = [];
let boxBgFn: Function | null = null;
let loaderInstance: any = null;
let boxChildren: any[] = [];
let boxBgFn: Function | null = null;
let boxInstance: any = null;
let loaderInstance: any = null;

Comment on lines +29 to +32
constructor() {
boxChildren = [];
boxBgFn = null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Capture the instance here to enable verification in tests.

Suggested change
constructor() {
boxChildren = [];
boxBgFn = null;
}
constructor() {
boxInstance = this;
boxChildren = [];
boxBgFn = null;
}

Comment on lines +58 to +59
boxBgFn = null;
loaderInstance = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Reset the boxInstance to ensure test isolation.

Suggested change
boxBgFn = null;
loaderInstance = null;
boxBgFn = null;
boxInstance = null;
loaderInstance = null;

Comment on lines +174 to +175
// Grab the mock instance from our mock setup
const { Box } = require("@mariozechner/pi-tui");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This require statement is unused and inconsistent with the ESM import syntax used throughout the project. It appears to be leftover code and should be removed.

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