Unit test LoginFormBLoC state transitions
epic-email-password-login-auth-logic-task-011 — Write bloc_test unit tests for LoginFormBLoC covering: field validation transitions, loading state emission on submit, all error state branches (credential, network, rate limit, server), success state with session and role, and session restoration on init. Use mock AuthService and CredentialValidator. Verify discrete error state types are emitted (not a generic error state) to confirm accessibility requirement compliance.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
The key insight for accessibility compliance: assert `isA
For session restoration tests, set up the mock before constructing the BLoC since restoration fires in the constructor. Use `wait` parameter in blocTest if restoration is async.
Testing Requirements
Use bloc_test package's blocTest
Verify accessibility requirement by asserting specific error state types (not base class) — this confirms each error surface point is individually identifiable for screen readers and error UI. File: `test/auth/login_form_bloc_test.dart`.
Supabase GoTrue returns HTTP error codes and string messages that may change between SDK versions. Incorrect or incomplete mapping could cause the wrong user-facing message to be shown (e.g., showing a generic error instead of a specific credential error), violating the plain-language feedback acceptance criteria and potentially exposing security-sensitive information.
Mitigation & Contingency
Mitigation: Pin the supabase_flutter SDK to a specific minor version in pubspec.yaml. Write integration tests that mock the Supabase HTTP layer and assert each error code maps to the correct domain exception. Document the mapping table as a constant in AuthService.
Contingency: If an unrecognized error code is received at runtime, catch it as an UnknownAuthException and display a generic safe message. Alert via crash reporting for triage and SDK update.
If the user taps the sign-in button multiple times rapidly, concurrent authentication requests could result in race conditions: duplicate network calls, out-of-order state emissions, or multiple session tokens being written to secure storage.
Mitigation & Contingency
Mitigation: Use bloc concurrency transformer (droppable or restartable) to ensure only one authentication event is processed at a time. The BLoC should guard against submission while in LoginLoading state.
Contingency: Add a UI-level disable on the submit button when loading state is active as a secondary guard independent of BLoC concurrency control.