[gui] Flutter unit tests: Custom widgets and extensions#5068
Open
sharder996 wants to merge 12 commits into
Open
[gui] Flutter unit tests: Custom widgets and extensions#5068sharder996 wants to merge 12 commits into
sharder996 wants to merge 12 commits into
Conversation
Contributor
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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