MotorSignal-App/test/social_hub_screen_test.dart

150 lines
5.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:motorcycle_dash/core/theme/theme.dart';
import 'package:motorcycle_dash/features/social/social_hub_screen.dart';
import 'package:motorcycle_dash/features/social/widgets/avatar_badge.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Widget buildTestSocialHub({
ThemeData? theme,
Size size = const Size(400, 800),
GoRouter? router,
}) {
final testRouter = router ??
GoRouter(
initialLocation: '/social',
routes: [
GoRoute(
path: '/social',
builder: (context, state) => const SocialHubScreen(),
routes: [
GoRoute(
path: 'profile',
builder: (context, state) => const Scaffold(body: Center(child: Text('Profile Target'))),
),
GoRoute(
path: 'friends',
builder: (context, state) => const Scaffold(body: Center(child: Text('Friends Target'))),
),
GoRoute(
path: 'clubs',
builder: (context, state) => const Scaffold(body: Center(child: Text('Clubs Target'))),
),
],
),
GoRoute(
path: '/group-rides',
builder: (context, state) => const Scaffold(body: Center(child: Text('Group Rides Target'))),
),
GoRoute(
path: '/garage',
builder: (context, state) => const Scaffold(body: Center(child: Text('Garage Target'))),
),
],
);
return ProviderScope(
child: MaterialApp.router(
theme: theme ?? AppTheme.darkTheme,
routerConfig: testRouter,
),
);
}
group('SocialHubScreen Widget Tests', () {
testWidgets('Renders Rider Hero Card with avatar and handle', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
expect(find.text('Social'), findsOneWidget);
expect(find.text('Rider'), findsOneWidget);
expect(find.byType(AvatarBadge), findsOneWidget);
expect(find.text('Edit'), findsOneWidget);
});
testWidgets('Renders sections and social destination cards', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
expect(find.text('Rider Network'), findsOneWidget);
expect(find.text('Motorcycle Activities'), findsOneWidget);
expect(find.text('Friends'), findsOneWidget);
expect(find.text('Clubs'), findsOneWidget);
expect(find.text('Group Rides'), findsOneWidget);
});
testWidgets('Navigates to Rider Profile when Edit button is tapped', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
await tester.tap(find.text('Edit'));
await tester.pumpAndSettle();
expect(find.text('Profile Target'), findsOneWidget);
});
testWidgets('Navigates to Friends when friends card is tapped', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
await tester.tap(find.text('Friends'));
await tester.pumpAndSettle();
expect(find.text('Friends Target'), findsOneWidget);
});
testWidgets('Navigates to Clubs when clubs card is tapped', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
await tester.tap(find.text('Clubs'));
await tester.pumpAndSettle();
expect(find.text('Clubs Target'), findsOneWidget);
});
testWidgets('Navigates to Group Rides when group rides card is tapped', (tester) async {
await tester.pumpWidget(buildTestSocialHub());
await tester.pumpAndSettle();
await tester.tap(find.text('Group Rides'));
await tester.pumpAndSettle();
expect(find.text('Group Rides Target'), findsOneWidget);
});
testWidgets('Renders cleanly under Light Theme without errors', (tester) async {
await tester.pumpWidget(buildTestSocialHub(theme: AppTheme.lightTheme));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.text('Social'), findsOneWidget);
});
testWidgets('Adapts to multiple responsive viewports without overflow', (tester) async {
const viewports = [
Size(320, 640),
Size(412, 915),
Size(800, 360),
Size(1024, 768),
];
for (final vp in viewports) {
tester.view.physicalSize = vp;
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.resetPhysicalSize);
await tester.pumpWidget(buildTestSocialHub(size: vp));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull, reason: 'No overflow on $vp');
expect(find.text('Social'), findsOneWidget);
}
});
});
}