MotorSignal-App/test/social_hybrid_ui_test.dart

131 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:motorcycle_dash/core/theme/theme.dart';
import 'package:motorcycle_dash/core/theme/theme_extensions.dart';
import 'package:motorcycle_dash/features/social/feed/social_feed_screen.dart';
import 'package:motorcycle_dash/features/social/social_hub_screen.dart';
import 'package:motorcycle_dash/services/social/social_feed_service.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Social Hybrid UI & Feed Verification Tests', () {
testWidgets('SocialHubScreen AppBar uses surfaceContainer theme color', (tester) async {
final testRouter = GoRouter(
initialLocation: '/social',
routes: [
GoRoute(
path: '/social',
builder: (context, state) => const SocialHubScreen(),
),
],
);
await tester.pumpWidget(
ProviderScope(
child: MaterialApp.router(
theme: AppTheme.darkTheme,
routerConfig: testRouter,
),
),
);
await tester.pumpAndSettle();
final appBarFinder = find.byType(AppBar);
expect(appBarFinder, findsOneWidget);
final appBar = tester.widget<AppBar>(appBarFinder);
expect(appBar.elevation, 0);
expect(appBar.backgroundColor, MotorSignalThemeColors.dark.surfaceContainer);
});
test('SocialFeedService mock sample feeds do not claim false GPS verification', () {
final service = SocialFeedService();
final items = service.currentFeed;
expect(items, isNotEmpty);
for (final item in items) {
expect(
item.isGpsVerified,
isFalse,
reason: 'Item ${item.id} (${item.rideTitle}) must not have unverified GPS claim.',
);
}
});
testWidgets('SocialFeedScreen renders on Pixel 8a portrait without overflows and without false GPS verification badge', (tester) async {
// Pixel 8a physical portrait display is 412x915 dp
await tester.binding.setSurfaceSize(const Size(412, 915));
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
theme: ThemeData.dark().copyWith(
extensions: const [
MotorSignalThemeColors.dark,
],
),
home: const Scaffold(
body: SocialFeedScreen(),
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// Verify header and filter components render cleanly
expect(find.text('Community Feed'), findsOneWidget);
expect(find.text('SQUAD & CANYON FEED'), findsOneWidget);
expect(find.byKey(const ValueKey('feed_search_toggle_button')), findsOneWidget);
expect(find.text('SHARE RECENT SESSION'), findsOneWidget);
// Verify that NO false GPS Verified badge is rendered
expect(find.text('GPS VERIFIED'), findsNothing);
// Verify no RenderFlex overflow exceptions occurred
expect(tester.takeException(), isNull);
});
test('SocialFeedService mock sample feeds are explicitly flagged with isDemo = true', () {
final service = SocialFeedService();
final items = service.currentFeed;
expect(items, isNotEmpty);
for (final item in items) {
expect(
item.isDemo,
isTrue,
reason: 'Mock feed item ${item.id} (${item.rideTitle}) must be flagged as demo.',
);
}
});
testWidgets('SocialFeedScreen renders DEMO SAMPLE badge on mock cards to prevent fake community activity', (tester) async {
await tester.binding.setSurfaceSize(const Size(412, 915));
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
theme: ThemeData.dark().copyWith(
extensions: const [
MotorSignalThemeColors.dark,
],
),
home: const Scaffold(
body: SocialFeedScreen(),
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// Verify that the DEMO SAMPLE badge is rendered on mock feed items
expect(find.text('DEMO SAMPLE'), findsWidgets);
});
});
}