84 lines
2.9 KiB
Dart
84 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:motorcycle_dash/features/garage/garage_screen.dart';
|
|
import 'package:motorcycle_dash/features/garage/garage_providers.dart';
|
|
import 'package:motorcycle_dash/services/sync/sync_providers.dart';
|
|
import 'package:motorcycle_dash/services/auth/auth_providers.dart';
|
|
import 'package:motorcycle_dash/services/auth/auth_state.dart';
|
|
|
|
void main() {
|
|
testWidgets('GarageScreen displays sync spinner when isSyncProcessingProvider is true', (tester) async {
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
garageMotorcyclesStreamProvider.overrideWith((ref) => Stream.value([])),
|
|
isSyncProcessingProvider.overrideWithValue(true),
|
|
pendingSyncCountProvider.overrideWithValue(0),
|
|
],
|
|
child: const MaterialApp(
|
|
home: GarageScreen(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
|
|
// Verify spinner is displayed instead of standard button
|
|
expect(find.byKey(const ValueKey('garage_sync_spinner')), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('garage_sync_button')), findsNothing);
|
|
});
|
|
|
|
testWidgets('GarageScreen displays pending badge count when sync is idle', (tester) async {
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
garageMotorcyclesStreamProvider.overrideWith((ref) => Stream.value([])),
|
|
isSyncProcessingProvider.overrideWithValue(false),
|
|
pendingSyncCountProvider.overrideWithValue(4),
|
|
],
|
|
child: const MaterialApp(
|
|
home: GarageScreen(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const ValueKey('garage_sync_button')), findsOneWidget);
|
|
expect(find.byType(Badge), findsOneWidget);
|
|
expect(find.text('4'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('GarageScreen sync button informs user when signed out', (tester) async {
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
garageMotorcyclesStreamProvider.overrideWith((ref) => Stream.value([])),
|
|
isSyncProcessingProvider.overrideWithValue(false),
|
|
pendingSyncCountProvider.overrideWithValue(1),
|
|
authNotifierProvider.overrideWith((ref) => MockAuthNotifier(const AuthState.unauthenticated())),
|
|
],
|
|
child: const MaterialApp(
|
|
home: GarageScreen(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
|
|
await tester.tap(find.byKey(const ValueKey('garage_sync_button')));
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const ValueKey('garage_sync_auth_required_snackbar')), findsOneWidget);
|
|
expect(find.text('Sign in to sync your garage with MotorCloud.'), findsOneWidget);
|
|
});
|
|
}
|
|
|
|
class MockAuthNotifier extends StateNotifier<AuthState> implements AuthNotifier {
|
|
MockAuthNotifier(super.state);
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|