test
This commit is contained in:
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