Integration tests for full activity type CRUD flow
epic-activity-type-configuration-admin-interface-task-012 — Write flutter_test integration tests covering the full coordinator CRUD workflow: (1) navigate to admin screen, verify empty state; (2) open create form, fill all fields including Bufdir category, submit, verify list updates; (3) tap item, edit display name and metadata flag, submit, verify changes reflected; (4) archive item, verify removed from active list, toggle archived filter, verify it appears; (5) verify RLS prevents access from peer mentor role. Run against Supabase local emulator. Achieve 100% coverage of form validation error paths.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 10 - 11 tasks
Can start after Tier 9 completes
Implementation Notes
Structure the test file as `test/integration/activity_type_crud_test.dart`. Use a shared `TestSupabaseClient` singleton initialised once per suite (not per test) to avoid connection overhead — reset data between tests using a SQL truncate via the Supabase admin REST endpoint. Override Riverpod providers in tests using `ProviderScope(overrides: [...])` to inject the test Supabase client. For the RLS peer_mentor test, call `supabaseAdmin.auth.admin.createUser({email, password, role: 'peer_mentor'})` in setUp, sign in as that user in the app, and attempt navigation to the admin route.
Use `flutter drive` or the `integration_test` runner for CI. Add a `Makefile` target `make test-integration` that starts the Supabase emulator, runs the suite, and tears down — document this in the feature README. Avoid `Future.delayed` in tests; use `pumpAndSettle` or `pump(Duration)` with explicit tick counts for snackbar timing assertions.
Testing Requirements
This task IS the testing deliverable. Use `flutter_test` with the `integration_test` package. Structure tests using `group()` with `setUp` (seed database, authenticate user) and `tearDown` (reset database to clean state). Use `WidgetTester.pumpAndSettle()` after async operations.
Use `find.byType()`, `find.text()`, and `find.byKey()` for element location — add `Key` annotations to key widgets if missing. For RLS testing, call the Supabase admin API to create a peer_mentor-scoped JWT. Include a `test_helpers/seed_activity_types.dart` utility that inserts known test records. Verify coverage with `flutter test --coverage`; target 100% on all form validation branches.
The Bufdir reporting category list is defined externally by Bufdir and may change between reporting years. If the dropdown in ActivityTypeFormScreen is hardcoded, existing activity type mappings could become invalid after a Bufdir schema update, breaking export validation for all organisations.
Mitigation & Contingency
Mitigation: Store the valid Bufdir category list in a Supabase configuration table (bufdir_categories) rather than as a Dart constant, so it can be updated by an admin without a mobile app release. Load the list in the form screen via a lightweight repository call cached locally.
Contingency: If the Bufdir category list cannot be externalised before the admin screen ships, expose a manual override field that allows coordinators to enter a raw Bufdir category code as a fallback, and schedule the configuration table migration as a follow-up task.
Reusing ActivityTypeFormScreen for both creation and editing requires careful Riverpod provider scoping. If the form provider is not properly reset between navigation events, stale values from a previously edited type may pre-populate a new creation form, leading to incorrect data being saved.
Mitigation & Contingency
Mitigation: Scope the form state provider to the route using Riverpod's autoDispose modifier, ensuring the state is torn down when the screen is popped. Write a widget test that navigates to edit type A, pops, navigates to create new, and asserts all fields are empty.
Contingency: If provider scoping proves complex with the current router setup, fall back to separate widget implementations for create and edit that share a common form widget but maintain independent provider instances.
Archiving an activity type must not break historical Bufdir export queries that filter activities by type. If the export pipeline performs an INNER JOIN against only active activity types, archived types will cause historical activities to be silently excluded from exports, producing incorrect reporting data.
Mitigation & Contingency
Mitigation: Audit all downstream query builders (Bufdir export, stats aggregation) before shipping the archive feature to confirm they join against all activity types regardless of is_active status. Add an integration test that archives a type, then asserts historical activity records for that type still appear in export queries.
Contingency: If a downstream query is discovered to filter on is_active post-launch, apply a targeted Supabase view fix that unions active and archived types for export contexts without requiring a mobile app update.