Skip to content

Commit

Permalink
feat: adding test widget
Browse files Browse the repository at this point in the history
  • Loading branch information
amaralkaff committed Nov 8, 2024
1 parent 459b800 commit 266cecf
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -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<AuthCubit>(), isNotNull);
expect(context.read<UserManager>(), isNotNull);
expect(context.read<WeightManager>(), isNotNull);
expect(context.read<PushUpCounter>(), isNotNull);
expect(context.read<SitUpCounter>(), isNotNull);
expect(context.read<ExerciseCompletion>(), isNotNull);
expect(context.read<ExerciseStatsModel>(), isNotNull);

// Verify initial route based on auth state
final authState = context.read<AuthCubit>().state;
if (authState.status == AuthStatus.authenticated) {
expect(find.byType(SplashScreen), findsOneWidget);
} else {
expect(find.byType(LoginScreen), findsOneWidget);
}
});
}

0 comments on commit 266cecf

Please sign in to comment.