Write unit tests with mocked NativeSpeechApiBridge
epic-speech-to-text-input-speech-engine-task-008 — Write comprehensive unit tests using flutter_test and mockito covering: initialization success and failure paths, permission denial flows, startListening/stopListening lifecycle, partial and final event emission sequences, all error code paths, locale selection logic, and dispose idempotency. Mock NativeSpeechApiBridge entirely — no platform channels invoked in unit tests.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
Generate MockNativeSpeechApiBridge with @GenerateMocks([NativeSpeechApiBridge]) and run build_runner once. Structure test file as speech_recognition_service_test.dart with nested group() blocks. For stream testing, collect all emitted events using stream.toList() with a bounded expectation, or use StreamQueue for step-by-step assertion. Example pattern for event sequence test: final queue = StreamQueue(service.startListening()); bridge.simulatePartialResult('hei'); expect(await queue.next, isA
Use FakeAsync from fake_async package for timeout-related tests to avoid real delays. Add a test for the Norwegian accessibility use case: confirm 'nb-NO' locale is used since HLF and Blindeforbundet users are Norwegian-speaking.
Testing Requirements
Pure unit tests using flutter_test and mockito. Group tests by behavior area: 'initialization', 'session lifecycle', 'event streaming', 'error handling', 'locale selection', 'disposal'. Use StreamQueue from async package for ordered stream assertions. Use verify() and verifyNever() for bridge interaction assertions.
Use throwsA(isA
The speech_to_text Flutter package delegates accuracy entirely to the OS-native engine. Norwegian accuracy for domain-specific vocabulary (medical terms, organisation names, accessibility terminology) may fall below the 85% acceptance threshold on older devices or in noisy environments, causing user frustration and manual correction overhead that negates the time saving.
Mitigation & Contingency
Mitigation: Configure the SpeechRecognitionService with Norwegian as the explicit locale and test against a representative corpus of peer mentoring vocabulary on target devices. Expose locale switching so users can fallback to Bokmål vs Nynorsk. Clearly set user expectations in the UI that transcription is a starting point for editing, not a finished product.
Contingency: If accuracy is consistently below threshold on specific device/OS combinations, add a device-capability check that hides the dictation button with an explanatory message rather than offering a degraded experience. Document affected device models for QA and org contacts.
The speech_to_text Flutter package is a third-party dependency that may introduce breaking API changes or deprecations on major version upgrades, requiring rework of SpeechRecognitionService when Flutter or platform OS versions are updated.
Mitigation & Contingency
Mitigation: Wrap all speech_to_text API calls behind the SpeechRecognitionService interface so that package changes are isolated to one file. Pin the package version in pubspec.yaml and review changelogs before any upgrade. Write integration tests that exercise the package contract so regressions are caught immediately.
Contingency: If the package is abandoned or has unresolvable issues, NativeSpeechApiBridge already provides the platform-channel abstraction needed to implement a direct plugin replacement with minimal changes to SpeechRecognitionService.