Skip to content

[gui] Flutter unit tests: Custom widgets and extensions#5068

Open
sharder996 wants to merge 12 commits into
mainfrom
feature/flutter-unit-tests-part2
Open

[gui] Flutter unit tests: Custom widgets and extensions#5068
sharder996 wants to merge 12 commits into
mainfrom
feature/flutter-unit-tests-part2

Conversation

@sharder996

Copy link
Copy Markdown
Collaborator

This PR is the next in line for adding unit testing in the GUI. This time we test some of the custom widgets used in the GUI and some custom extensions.

Some edits were made to the GUI production code in order to cover some edge cases that were previously uncovered.


MULTI-2521

@sharder996 sharder996 requested review from a team, Copilot and jimporter and removed request for a team July 10, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new batch of Flutter unit/widget tests for custom GUI widgets/extensions and introduces small production hardening changes to cover previously untested edge cases (parsing and boundary inputs).

Changes:

  • Added widget tests for custom UI components (Switch, MemoryUsage, DisableSection) and CPU sparkline provider behavior.
  • Added unit tests for numeric/unit conversion and extension helpers.
  • Hardened production code against invalid inputs (non-parseable memory strings, sub-sector mapping inputs, malformed CPU times).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/client/gui/test/switch_test.dart Adds widget tests validating custom Switch layout/behavior and enabled/disabled interactions.
src/client/gui/test/memory_usage_test.dart Adds widget tests for MemoryUsage progress, color thresholds, label formatting, and edge cases.
src/client/gui/test/mapping_slider_test.dart Adds unit tests for mapping/conversion helpers and non-linear mapping edge cases.
src/client/gui/test/extensions_test.dart Adds unit tests for string/nullable/widget/TextSpan extension helpers.
src/client/gui/test/disable_section_test.dart Adds widget tests for DisableSection tap-blocking and opacity dimming behavior.
src/client/gui/test/cpu_sparkline_test.dart Adds unit tests for CPU usage history tracking and robustness to malformed/reset samples.
src/client/gui/lib/vm_details/memory_usage.dart Avoids exceptions by using int.tryParse in memory label formatting.
src/client/gui/lib/vm_details/mapping_slider.dart Prevents invalid log2 inputs by early-returning for sub-sector values.
src/client/gui/lib/vm_details/cpu_sparkline.dart Makes CPU usage parsing more defensive and returns a fresh history instance on updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 62 to +66
.cpuTimes
.split(' ')
.skip(2)
.take(8)
.map(int.parse)
.map(int.tryParse)
Comment on lines +137 to +147
testWidgets('clamps to full when used exceeds total', (tester) async {
// value > 1.0 is clamped by LinearProgressIndicator; almostFullColor applied.
await tester.pumpWidget(buildWidget('2000', '1000'));
await tester.pumpAndSettle();

final indicator = tester.widget<LinearProgressIndicator>(
find.byType(LinearProgressIndicator),
);
expect(indicator.value, 2.0);
expect(indicator.color, MemoryUsage.almostFullColor);
});
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.71%. Comparing base (456dd60) to head (8fe6ab9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5068      +/-   ##
==========================================
- Coverage   73.12%   71.71%   -1.40%     
==========================================
  Files         331      338       +7     
  Lines       17712    18238     +526     
==========================================
+ Hits        12950    13078     +128     
- Misses       4762     5160     +398     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants