Skip to content

Add unit tests for Health Connect permission fallback and lifecycle reconciliation #42

Description

@coderabbitai

Summary

This issue tracks the addition of unit tests for the Health Connect permission handling and lifecycle reconciliation paths introduced in PR #40.

Context

Raised in: #40 (comment)
Requested by: @Devasy

What needs to be tested

File: workout-logger/lib/screens/profile_screen.dart (lines 36–128)

Using Mockito mocks for IHealthConnectService and SettingsProvider, following Arrange–Act–Assert (AAA) pattern, add tests under test/:

_reconcileHealthConnectState

  • Clears SettingsProvider.healthConnectEnabled when hc.isAvailable() returns false
  • Clears SettingsProvider.healthConnectEnabled when hc.hasPermissions() returns false
  • Does nothing when healthConnectEnabled is already false (no unnecessary plugin calls)
  • Fail-safe: disables flag when an exception is thrown

didChangeAppLifecycleState

  • Triggers _reconcileHealthConnectState when state is AppLifecycleState.resumed
  • Does not trigger reconciliation for other lifecycle states

_requestHealthConnectPermission

  • Shows error snack when hc.isAvailable() returns false
  • Calls settings.setHealthConnectEnabled(true) when permissions are granted
  • Shows warning snack when permissions are denied
  • Fallback: when requestPermissions() throws, re-checks hasPermissions() and handles grant/denial correctly

Notes

  • CI only builds the APK — run flutter test locally before committing.
  • Mock IHealthConnectService methods: isAvailable, hasPermissions, requestPermissions.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions