Skip to content

feat(tests): add comprehensive unit/widget tests and fix deprecations#9

Merged
ppamorim merged 1 commit intomasterfrom
feature/implUnitTests
Apr 17, 2026
Merged

feat(tests): add comprehensive unit/widget tests and fix deprecations#9
ppamorim merged 1 commit intomasterfrom
feature/implUnitTests

Conversation

@ppamorim
Copy link
Copy Markdown

Summary

  • New test files: exceptions_test.dart, models_test.dart, platform_interface_test.dart, with_foreground_task_test.dart, method_channel_test.dart — collectively covering exception classes, model copyWith/toJson, all FlutterForegroundTaskPlatform abstract methods, the WithForegroundTask widget, and the method channel layer.
  • Expanded existing tests: task_handler_test.dart now includes a MinimalTaskHandler that exercises the default no-op bodies of the optional TaskHandler callbacks.
  • Fix WillPopScope deprecation: replaced with PopScope + onPopInvokedWithResult in lib/ui/with_foreground_task.dart; app minimizes when service is running, exits via SystemNavigator.pop() otherwise.
  • Fix deprecated Color getters: lib/utils/color_extension.dart now uses (r/g/b * 255.0).round().clamp(0, 255) instead of the removed .red/.green/.blue properties.
  • Refactor else if chains: converted to independent if blocks in saveData (flutter_foreground_task_controller.dart) and platform-conditional serialisation (service_options.dart).
  • CI: added flutter analyze step to .github/workflows/unit-test.yml so analysis failures block the build.

Test plan

  • flutter analyze reports no issues
  • flutter test --coverage passes with all new tests green
  • Coverage for lib/ui/with_foreground_task.dart, lib/utils/color_extension.dart, lib/errors/*.dart, lib/models/*.dart, and lib/flutter_foreground_task_platform_interface.dart is at or near 100 %

- Add test/exceptions_test.dart covering all four exception classes
- Add test/models_test.dart covering model copyWith, toJson, and enums
- Add test/platform_interface_test.dart verifying all abstract methods throw UnimplementedError
- Add test/with_foreground_task_test.dart as a widget test for WithForegroundTask
- Expand test/method_channel_test.dart and test/task_handler_test.dart for full branch coverage
- Replace deprecated WillPopScope with PopScope in lib/ui/with_foreground_task.dart
- Fix deprecated Color.red/green/blue getters in lib/utils/color_extension.dart
- Refactor else-if chains into independent if blocks in lib/flutter_foreground_task_controller.dart and lib/models/service_options.dart
- Add flutter analyze step to .github/workflows/unit-test.yml
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
25.3% Duplication on New Code (required ≤ 3%)
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@ppamorim ppamorim merged commit 520d8a5 into master Apr 17, 2026
1 of 2 checks passed
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