Files
oott/frontend/test/widget/scanner_status_card_test.dart
T
rzuastiandClaude Opus 4.8 98b5fa267f Add automated test suite for the Flutter frontend
Introduce a headless `flutter test` suite (83 tests) covering models,
utilities, every API endpoint, and the five screens, with shared helpers
and fixtures so new tests stay terse.

API endpoint methods are statically-dispatched extensions on the
BackendAPI singleton, so they cannot be mocked via `implements`. Mock at
the Dio HTTP-adapter layer (http_mock_adapter) instead, enabled by two
small @visibleForTesting seams: BackendAPI.dioForTesting swaps the
singleton's Dio, and BackendReachability.forceOnlineForTesting() forces a
deterministic online state so polling widgets load.

Add frontend/run_tests.sh and document it in CLAUDE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 19:41:52 -04:00

58 lines
1.5 KiB
Dart

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:frontend/widgets/scanner_status_card.dart';
import '../helpers/backend_test_harness.dart';
import '../helpers/pump_app.dart';
ScannerStatus _resolve(BuildContext context, int value, double elapsed) =>
(color: Colors.green, label: 'Value $value', sublabels: ['detail line']);
void main() {
setUp(() async {
await setUpBackendForTest();
});
testWidgets('shows a spinner, then the resolved label and sublabels',
(tester) async {
await pumpScreen(
tester,
ScannerStatusCard<int>(
title: 'Probe',
fetch: ({cancelToken}) async => 42,
resolver: _resolve,
),
);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
await pumpUntilFound(tester, find.text('Value 42'));
expect(find.text('Probe'), findsOneWidget);
expect(find.text('detail line'), findsOneWidget);
await tearDownTree(tester);
});
testWidgets('renders an Error state when the fetch fails', (tester) async {
await pumpScreen(
tester,
ScannerStatusCard<int>(
title: 'Probe',
fetch: ({cancelToken}) async => throw DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.connectionError,
),
resolver: _resolve,
),
);
await pumpUntilFound(tester, find.text('Error'));
expect(find.text('Error'), findsOneWidget);
await tearDownTree(tester);
});
}