85 lines
2.6 KiB
Dart
85 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:mileograph_flutter/components/pages/dashboard.dart';
|
|
|
|
import '../helpers/fake_services.dart';
|
|
import '../helpers/test_app.dart';
|
|
import '../helpers/test_data.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUpAll(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
});
|
|
|
|
testWidgets('Dashboard renders stats and panels', (tester) async {
|
|
final data = FakeDataService()
|
|
..homepageStatsValue = TestData.homepageStats
|
|
..tripsValue = TestData.tripSummaries
|
|
..onThisDayValue = TestData.onThisDayLegs()
|
|
..classClearanceProgressValue = TestData.classClearance
|
|
..latestLocoChangesValue = TestData.latestLocoChanges
|
|
..tractionValue = TestData.traction
|
|
..currentYearMileageValue = 1200.5;
|
|
final auth = FakeAuthService(api: FakeApiService());
|
|
final router = GoRouter(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => const Dashboard(),
|
|
),
|
|
],
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
buildTestRouterApp(
|
|
router: router,
|
|
dataService: data,
|
|
authService: auth,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Dashboard'), findsOneWidget);
|
|
expect(find.textContaining('Welcome back, Alex Rider'), findsOneWidget);
|
|
expect(find.text('Top traction'), findsOneWidget);
|
|
expect(find.text('67 001'), findsOneWidget);
|
|
expect(find.text('On this day'), findsOneWidget);
|
|
expect(find.text('York → Durham'), findsOneWidget);
|
|
expect(find.text('Latest Loco Changes'), findsOneWidget);
|
|
expect(find.text('Status'), findsWidgets);
|
|
expect(find.text('Active'), findsWidgets);
|
|
});
|
|
|
|
testWidgets('Dashboard shows loading overlay without stats', (tester) async {
|
|
final data = FakeDataService()
|
|
..homepageStatsValue = null
|
|
..isHomepageLoadingValue = true;
|
|
final auth = FakeAuthService(api: FakeApiService());
|
|
final router = GoRouter(
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => const Dashboard(),
|
|
),
|
|
],
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
buildTestRouterApp(
|
|
router: router,
|
|
dataService: data,
|
|
authService: auth,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.text('Loading dashboard data...'), findsOneWidget);
|
|
expect(find.byType(CircularProgressIndicator), findsWidgets);
|
|
});
|
|
}
|