From 266cecf7b53645ffbf954e02b47513eec77ccf0e Mon Sep 17 00:00:00 2001 From: amaralkaff Date: Fri, 8 Nov 2024 11:31:25 +0800 Subject: [PATCH] feat: adding test widget --- test/widget_test.dart | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/test/widget_test.dart b/test/widget_test.dart index 0be5db4..3940757 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -1,15 +1,50 @@ // test/widget_test.dart +import 'package:WorkoutAI/models/exercise_completion_model.dart'; +import 'package:WorkoutAI/models/exercise_stats_model.dart'; +import 'package:WorkoutAI/models/push_up_model.dart'; +import 'package:WorkoutAI/models/sit_up_model.dart'; +import 'package:WorkoutAI/models/user_manager.dart'; +import 'package:WorkoutAI/models/weight_manager.dart'; +import 'package:WorkoutAI/views/auth/login_screen.dart'; +import 'package:WorkoutAI/views/splash_screen.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:WorkoutAI/main.dart'; +import 'package:WorkoutAI/models/auth_state.dart'; +import 'package:WorkoutAI/services/auth_service.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + testWidgets('App initialization test', (WidgetTester tester) async { + // Initialize auth service + final authService = AuthService(); + final isAuthenticated = await authService.initializeAuth(); - // You can write your tests here + // Build app with authentication state + await tester.pumpWidget(MyApp(isAuthenticated: isAuthenticated)); + + // Verify basic app structure expect(find.byType(MaterialApp), findsOneWidget); + expect(find.byType(MultiBlocProvider), findsOneWidget); + expect(find.byType(AppWithAuth), findsOneWidget); + + // Verify bloc providers are initialized + final context = tester.element(find.byType(AppWithAuth)); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + expect(context.read(), isNotNull); + + // Verify initial route based on auth state + final authState = context.read().state; + if (authState.status == AuthStatus.authenticated) { + expect(find.byType(SplashScreen), findsOneWidget); + } else { + expect(find.byType(LoginScreen), findsOneWidget); + } }); }