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,121 @@
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_core/core.dart';
class MockTokenStorageService extends Mock implements TokenStorageService {}
class MockSliderLogic extends GetxController with Mock implements SliderLogic {}
void main() {
group('ModulesLogic Tests', () {
late ModulesLogic modulesLogic;
late MockTokenStorageService mockTokenService;
late MockSliderLogic mockUpSlider;
late MockSliderLogic mockDownSlider;
setUp(() {
mockTokenService = MockTokenStorageService();
mockUpSlider = MockSliderLogic();
mockDownSlider = MockSliderLogic();
Get.put<TokenStorageService>(mockTokenService);
Get.put<SliderLogic>(mockUpSlider, tag: "up");
Get.put<SliderLogic>(mockDownSlider, tag: "down");
modulesLogic = ModulesLogic();
});
tearDown(() {
Get.reset();
});
test('should initialize with correct default values', () {
// Assert
expect(modulesLogic.isLoading.value, false);
expect(modulesLogic.latestNews.value, null);
expect(modulesLogic.moduleList, isNotEmpty);
expect(modulesLogic.moduleList.length, greaterThan(0));
});
test('should have correct module list structure', () {
// Assert
expect(modulesLogic.moduleList, isA<List<ModuleModel>>());
// Check that chicken module exists
final chickenModule = modulesLogic.moduleList.firstWhere(
(module) => module.module == Module.chicken,
);
expect(chickenModule.title, 'رصدطیور');
expect(chickenModule.borderColor, Color(0xFF4665AF));
// Check that inspection module exists
final inspectionModule = modulesLogic.moduleList.firstWhere(
(module) => module.module == Module.inspection,
);
expect(inspectionModule.title, 'رصدبان');
expect(inspectionModule.borderColor, Color(0xFF014856));
});
test('should update isLoading correctly', () {
// Act
modulesLogic.isLoading.value = true;
// Assert
expect(modulesLogic.isLoading.value, true);
// Act
modulesLogic.isLoading.value = false;
// Assert
expect(modulesLogic.isLoading.value, false);
});
test('should update latestNews correctly', () {
// Act
modulesLogic.latestNews.value = 'Test news';
// Assert
expect(modulesLogic.latestNews.value, 'Test news');
// Act
modulesLogic.latestNews.value = null;
// Assert
expect(modulesLogic.latestNews.value, null);
});
test('should have livestock module with correct properties', () {
// Assert
final livestockModule = modulesLogic.moduleList.firstWhere(
(module) => module.module == Module.liveStocks,
);
expect(livestockModule.title, 'رصدام');
expect(livestockModule.borderColor, Color(0xFFD7A972));
expect(livestockModule.backgroundColor, Color(0xFFF4F1EF));
expect(livestockModule.titleColor, Color(0xFF7F7F7F));
});
test('should have all required modules in moduleList', () {
// Assert
final moduleTypes = modulesLogic.moduleList.map((m) => m.module).toList();
expect(moduleTypes.contains(Module.chicken), true);
expect(moduleTypes.contains(Module.liveStocks), true);
expect(moduleTypes.contains(Module.inspection), true);
});
test('should access slider controllers correctly', () {
// Assert
expect(modulesLogic.upSlider, isA<SliderLogic>());
expect(modulesLogic.downSlider, isA<SliderLogic>());
});
test('should access token service correctly', () {
// Assert
expect(modulesLogic.tokenService, isA<TokenStorageService>());
});
});
}

View File

@@ -0,0 +1,93 @@
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_core/core.dart';
class MockGService extends Mock implements GService {}
class MockTokenStorageService extends Mock implements TokenStorageService {}
class MockTickerProvider extends Mock implements TickerProvider {
@override
Ticker createTicker(TickerCallback onTick) {
return Ticker(onTick);
}
}
void main() {
group('SplashLogic Tests', () {
late SplashLogic splashLogic;
late MockGService mockGService;
late MockTokenStorageService mockTokenService;
setUp(() {
mockGService = MockGService();
mockTokenService = MockTokenStorageService();
Get.put<GService>(mockGService);
Get.put<TokenStorageService>(mockTokenService);
splashLogic = SplashLogic();
});
tearDown(() {
Get.reset();
});
test('should initialize animation controllers on init', () {
// Act
splashLogic.onInit();
// Assert
expect(splashLogic.scaleController, isA<AnimationController>());
expect(splashLogic.rotateController, isA<AnimationController>());
expect(splashLogic.scaleAnimation.value, isA<Animation<double>>());
expect(splashLogic.rotationAnimation.value, isA<Animation<double>>());
});
test('should have correct initial values for reactive variables', () {
// Assert
expect(splashLogic.hasUpdated.value, false);
expect(splashLogic.onUpdateDownload.value, false);
expect(splashLogic.percent.value, 0.0);
});
test('should dispose animation controllers on close', () {
// Arrange
splashLogic.onInit();
// Act
splashLogic.onClose();
// Assert - controllers should be disposed
expect(() => splashLogic.scaleController.forward(), throwsA(isA<AssertionError>()));
expect(() => splashLogic.rotateController.forward(), throwsA(isA<AssertionError>()));
});
test('should update percent value correctly', () {
// Act
splashLogic.percent.value = 0.5;
// Assert
expect(splashLogic.percent.value, 0.5);
});
test('should update hasUpdated value correctly', () {
// Act
splashLogic.hasUpdated.value = true;
// Assert
expect(splashLogic.hasUpdated.value, true);
});
test('should update onUpdateDownload value correctly', () {
// Act
splashLogic.onUpdateDownload.value = true;
// Assert
expect(splashLogic.onUpdateDownload.value, true);
});
});
}