test
This commit is contained in:
151
test/unit/pages/modules_page_test.dart
Normal file
151
test/unit/pages/modules_page_test.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/modules/logic.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/modules/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class MockModulesLogic extends GetxController with Mock implements ModulesLogic {
|
||||
@override
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
@override
|
||||
List<ModuleModel> 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),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class MockTokenStorageService extends Mock implements TokenStorageService {}
|
||||
|
||||
class MockSliderLogic extends GetxController with Mock implements SliderLogic {}
|
||||
|
||||
void main() {
|
||||
group('ModulesPage Tests', () {
|
||||
late MockModulesLogic mockController;
|
||||
late MockTokenStorageService mockTokenService;
|
||||
late MockSliderLogic mockUpSlider;
|
||||
late MockSliderLogic mockDownSlider;
|
||||
|
||||
setUp(() {
|
||||
mockController = MockModulesLogic();
|
||||
mockTokenService = MockTokenStorageService();
|
||||
mockUpSlider = MockSliderLogic();
|
||||
mockDownSlider = MockSliderLogic();
|
||||
|
||||
Get.put<ModulesLogic>(mockController);
|
||||
Get.put<TokenStorageService>(mockTokenService);
|
||||
Get.put<SliderLogic>(mockUpSlider, tag: "up");
|
||||
Get.put<SliderLogic>(mockDownSlider, tag: "down");
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
testWidgets('should display app bar with correct title and logo', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
mockController.isLoading.value = false;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ModulesPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
expect(find.text('سامانه جامع رصدیار'), findsOneWidget);
|
||||
|
||||
final appBar = tester.widget<AppBar>(find.byType(AppBar));
|
||||
expect(appBar.backgroundColor, AppColor.blueNormal);
|
||||
expect(appBar.centerTitle, true);
|
||||
});
|
||||
|
||||
testWidgets('should show loading indicator when isLoading is true', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
mockController.isLoading.value = true;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ModulesPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Container), findsWidgets);
|
||||
// The loading container should be present
|
||||
final containers = tester.widgetList<Container>(find.byType(Container));
|
||||
expect(containers.any((container) =>
|
||||
container.color == Colors.grey.withValues(alpha: 0.5)), true);
|
||||
});
|
||||
|
||||
testWidgets('should display main content when not loading', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
mockController.isLoading.value = false;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ModulesPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Column), findsWidgets);
|
||||
expect(find.byType(GridView), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display correct number of modules in grid', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
mockController.isLoading.value = false;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ModulesPage(),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(GridView), findsOneWidget);
|
||||
// Grid should contain the modules from moduleList
|
||||
final gridView = tester.widget<GridView>(find.byType(GridView));
|
||||
expect(gridView, isNotNull);
|
||||
});
|
||||
|
||||
testWidgets('should have correct scaffold structure', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
mockController.isLoading.value = false;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ModulesPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
122
test/unit/pages/splash_page_test.dart
Normal file
122
test/unit/pages/splash_page_test.dart
Normal file
@@ -0,0 +1,122 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/splash/logic.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/splash/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class MockSplashLogic extends GetxController with Mock implements SplashLogic {
|
||||
@override
|
||||
late final AnimationController scaleController;
|
||||
|
||||
@override
|
||||
late final AnimationController rotateController;
|
||||
|
||||
@override
|
||||
Rxn<Animation<double>> scaleAnimation = Rxn();
|
||||
|
||||
@override
|
||||
Rxn<Animation<double>> rotationAnimation = Rxn();
|
||||
}
|
||||
|
||||
class MockGService extends Mock implements GService {}
|
||||
|
||||
class MockTokenStorageService extends Mock implements TokenStorageService {}
|
||||
|
||||
void main() {
|
||||
group('SplashPage Tests', () {
|
||||
late MockSplashLogic mockController;
|
||||
late MockGService mockGService;
|
||||
late MockTokenStorageService mockTokenService;
|
||||
|
||||
setUp(() {
|
||||
mockController = MockSplashLogic();
|
||||
mockGService = MockGService();
|
||||
mockTokenService = MockTokenStorageService();
|
||||
|
||||
Get.put<SplashLogic>(mockController);
|
||||
Get.put<GService>(mockGService);
|
||||
Get.put<TokenStorageService>(mockTokenService);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
testWidgets('should display splash screen with animations', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockScaleAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(1.0),
|
||||
);
|
||||
final mockRotationAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(0.0),
|
||||
);
|
||||
|
||||
mockController.scaleAnimation.value = mockScaleAnimation;
|
||||
mockController.rotationAnimation.value = mockRotationAnimation;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: SplashPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
expect(find.byType(ScaleTransition), findsOneWidget);
|
||||
expect(find.byType(RotationTransition), findsOneWidget);
|
||||
expect(find.byType(Stack), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should have correct background color', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockScaleAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(1.0),
|
||||
);
|
||||
final mockRotationAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(0.0),
|
||||
);
|
||||
|
||||
mockController.scaleAnimation.value = mockScaleAnimation;
|
||||
mockController.rotationAnimation.value = mockRotationAnimation;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: SplashPage(),
|
||||
),
|
||||
);
|
||||
|
||||
// Assert
|
||||
final scaffold = tester.widget<Scaffold>(find.byType(Scaffold));
|
||||
expect(scaffold.backgroundColor, AppColor.blueDarker);
|
||||
});
|
||||
|
||||
testWidgets('should render animations when controllers are available', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockScaleAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(1.2),
|
||||
);
|
||||
final mockRotationAnimation = Animation<double>.fromValueListenable(
|
||||
ValueNotifier(0.5),
|
||||
);
|
||||
|
||||
mockController.scaleAnimation.value = mockScaleAnimation;
|
||||
mockController.rotationAnimation.value = mockRotationAnimation;
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: SplashPage(),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(ScaleTransition), findsOneWidget);
|
||||
expect(find.byType(RotationTransition), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user