This commit is contained in:
2025-09-23 11:19:14 +03:30
parent ce4290dc87
commit d2c495bfb1
14 changed files with 1821 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:rasadyar_inspection/presentation/pages/auth/view.dart';
import 'package:rasadyar_inspection/presentation/pages/auth/logic.dart';
import 'package:rasadyar_core/core.dart';
class MockAuthLogic extends GetxController with Mock implements AuthLogic {}
class MockTokenStorageService extends Mock implements TokenStorageService {}
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Inspection Module Integration Tests', () {
late MockAuthLogic mockAuthLogic;
late MockTokenStorageService mockTokenService;
setUp(() {
mockAuthLogic = MockAuthLogic();
mockTokenService = MockTokenStorageService();
// Setup mock behaviors
mockAuthLogic.textAnimation = AlwaysStoppedAnimation(1.0);
mockAuthLogic.isLoading = false.obs;
mockAuthLogic.usernameController = TextEditingController().obs;
mockAuthLogic.passwordController = TextEditingController().obs;
Get.put<AuthLogic>(mockAuthLogic);
Get.put<TokenStorageService>(mockTokenService);
});
tearDown(() {
Get.reset();
});
testWidgets('should complete authentication flow', (WidgetTester tester) async {
// Act
await tester.pumpWidget(
MaterialApp(
home: AuthPage(),
),
);
// Assert - Verify auth page loads correctly
expect(find.text('به سامانه رصدیار خوش آمدید!'), findsOneWidget);
expect(find.text('سامانه رصد و پایش زنجیره تامین، تولید و توزیع کالا های اساسی'), findsOneWidget);
// Test page navigation and UI interactions
await tester.pumpAndSettle();
expect(find.byType(Scaffold), findsOneWidget);
expect(find.byType(FadeTransition), findsOneWidget);
});
testWidgets('should handle back navigation correctly', (WidgetTester tester) async {
// Act
await tester.pumpWidget(
MaterialApp(
home: AuthPage(),
),
);
// Verify PopScope behavior
final popScope = tester.widget<PopScope>(find.byType(PopScope));
expect(popScope.canPop, false);
// Test that back button handling works
await tester.pump();
expect(find.byType(AuthPage), findsOneWidget);
});
testWidgets('should display welcome animation correctly', (WidgetTester tester) async {
// Act
await tester.pumpWidget(
MaterialApp(
home: AuthPage(),
),
);
// Assert - Check animation components
expect(find.byType(FadeTransition), findsOneWidget);
expect(find.byType(Column), findsOneWidget);
// Verify text styling
final welcomeText = tester.widget<Text>(
find.text('به سامانه رصدیار خوش آمدید!')
);
expect(welcomeText.style?.color, Colors.white);
});
});
}

View File

@@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:get/get.dart';
import 'package:mocktail/mocktail.dart';
import 'package:rasadyar_app/presentation/pages/modules/view.dart';
import 'package:rasadyar_app/presentation/pages/modules/logic.dart';
import 'package:rasadyar_core/core.dart';
class MockModulesLogic extends GetxController with Mock implements ModulesLogic {}
class MockTokenStorageService extends Mock implements TokenStorageService {}
class MockSliderLogic extends GetxController with Mock implements SliderLogic {}
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Modules Page Integration Tests', () {
late MockModulesLogic mockModulesLogic;
late MockTokenStorageService mockTokenService;
late MockSliderLogic mockUpSlider;
late MockSliderLogic mockDownSlider;
setUp(() {
mockModulesLogic = MockModulesLogic();
mockTokenService = MockTokenStorageService();
mockUpSlider = MockSliderLogic();
mockDownSlider = MockSliderLogic();
// Setup mock behaviors
mockModulesLogic.isLoading = false.obs;
mockModulesLogic.moduleList = [
ModuleModel(
title: 'رصدطیور',
icon: 'test_icon.svg',
module: Module.chicken,
borderColor: Color(0xFF4665AF),
backgroundColor: Color(0xFFECEEF2),
titleColor: Color(0xFF4665AF),
),
ModuleModel(
title: 'رصدبان',
icon: 'test_icon2.svg',
module: Module.inspection,
borderColor: Color(0xFF014856),
backgroundColor: Color(0xFFE9EDED),
titleColor: Color(0xFF014856),
),
];
Get.put<ModulesLogic>(mockModulesLogic);
Get.put<TokenStorageService>(mockTokenService);
Get.put<SliderLogic>(mockUpSlider, tag: "up");
Get.put<SliderLogic>(mockDownSlider, tag: "down");
});
tearDown(() {
Get.reset();
});
testWidgets('should display modules grid and handle user interaction', (WidgetTester tester) async {
// Act
await tester.pumpWidget(
MaterialApp(
home: ModulesPage(),
),
);
await tester.pumpAndSettle();
// Assert - Verify modules page loads correctly
expect(find.text('سامانه جامع رصدیار'), findsOneWidget);
expect(find.byType(AppBar), findsOneWidget);
expect(find.byType(GridView), findsOneWidget);
// Verify app bar styling
final appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backgroundColor, AppColor.blueNormal);
expect(appBar.centerTitle, true);
});
testWidgets('should show loading state correctly', (WidgetTester tester) async {
// Arrange
mockModulesLogic.isLoading.value = true;
// Act
await tester.pumpWidget(
MaterialApp(
home: ModulesPage(),
),
);
await tester.pump();
// Assert - Should show loading indicator
expect(find.byType(Container), findsWidgets);
// Change to not loading
mockModulesLogic.isLoading.value = false;
await tester.pump();
// Should show main content
expect(find.byType(Column), findsWidgets);
});
testWidgets('should handle module selection', (WidgetTester tester) async {
// Act
await tester.pumpWidget(
MaterialApp(
home: ModulesPage(),
),
);
await tester.pumpAndSettle();
// Assert - Grid should be present for module selection
expect(find.byType(GridView), findsOneWidget);
// Verify modules are accessible
expect(mockModulesLogic.moduleList.length, greaterThan(0));
});
});
}