test: add unit tests for poultry repository and searchable dropdown functionalities

- Introduced tests for `PoultryScienceRepositoryImp` to validate delegated remote calls.
- Added comprehensive tests for `SearchableDropdownLogic` covering selection, overlay, and search logic.
- Enhanced `SearchableDropdown` widget tests for multi-select, label building, and overlay management.
This commit is contained in:
2025-11-16 15:40:21 +03:30
parent 716a7ed259
commit a66c8b69ca
16 changed files with 812 additions and 304 deletions

View File

@@ -4,7 +4,6 @@ import 'package:rasadyar_chicken/data/data_source/remote/auth/auth_remote.dart';
import 'package:rasadyar_chicken/data/models/response/user_info/user_info_model.dart';
import 'package:rasadyar_chicken/data/models/response/user_profile_model/user_profile_model.dart';
import 'package:rasadyar_chicken/data/repositories/auth/auth_repository_imp.dart';
import 'package:rasadyar_core/core.dart';
class MockAuthRemoteDataSource extends Mock implements AuthRemoteDataSource {}
@@ -22,7 +21,6 @@ void main() {
test('should complete full login flow successfully', () async {
// Arrange
const phoneNumber = '09123456789';
const deviceName = 'Test Device';
final authRequest = {
'username': 'test@example.com',
'password': 'password',
@@ -48,28 +46,18 @@ void main() {
// Mock the flow
when(
() => mockAuthRemote.getUserInfo(phoneNumber),
() => mockAuthRemote.getUserInfo(phoneNumber),
).thenAnswer((_) async => expectedUserInfo);
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
when(
() => mockAuthRemote.login(authRequest: authRequest),
() => mockAuthRemote.login(authRequest: authRequest),
).thenAnswer((_) async => expectedUserProfile);
// Act - Step 1: Get user info
final userInfo = await authRepository.getUserInfo(phoneNumber);
expect(userInfo, equals(expectedUserInfo));
// Act - Step 2: Submit user info
await authRepository.submitUserInfo(
phone: phoneNumber,
deviceName: deviceName,
);
// Act - Step 3: Login
// Act - Step 2: Login
final userProfile = await authRepository.login(
authRequest: authRequest,
);
@@ -77,7 +65,6 @@ void main() {
// Assert
expect(userProfile, equals(expectedUserProfile));
verify(() => mockAuthRemote.getUserInfo(phoneNumber)).called(1);
//verify(() => mockAuthRemote.submitUserInfo(any())).called(1);
verify(() => mockAuthRemote.login(authRequest: authRequest)).called(1);
});
@@ -100,11 +87,11 @@ void main() {
// Mock the flow
when(
() => mockAuthRemote.hasAuthenticated(),
() => mockAuthRemote.hasAuthenticated(),
).thenAnswer((_) async => false);
when(
() => mockAuthRemote.login(authRequest: authRequest),
() => mockAuthRemote.login(authRequest: authRequest),
).thenAnswer((_) async => expectedUserProfile);
// Act - Step 1: Check authentication status
@@ -129,7 +116,7 @@ void main() {
const phoneNumber = '09123456789';
when(
() => mockAuthRemote.getUserInfo(phoneNumber),
() => mockAuthRemote.getUserInfo(phoneNumber),
).thenAnswer((_) async => null);
// Act
@@ -143,7 +130,6 @@ void main() {
test('should handle login failure after successful user info', () async {
// Arrange
const phoneNumber = '09123456789';
const deviceName = 'Test Device';
final authRequest = {
'username': 'test@example.com',
'password': 'wrong',
@@ -158,28 +144,18 @@ void main() {
// Mock the flow
when(
() => mockAuthRemote.getUserInfo(phoneNumber),
() => mockAuthRemote.getUserInfo(phoneNumber),
).thenAnswer((_) async => expectedUserInfo);
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
when(
() => mockAuthRemote.login(authRequest: authRequest),
() => mockAuthRemote.login(authRequest: authRequest),
).thenAnswer((_) async => null);
// Act - Step 1: Get user info (success)
final userInfo = await authRepository.getUserInfo(phoneNumber);
expect(userInfo, equals(expectedUserInfo));
// Act - Step 2: Submit user info (success)
await authRepository.submitUserInfo(
phone: phoneNumber,
deviceName: deviceName,
);
// Act - Step 3: Login (failure)
// Act - Step 2: Login (failure)
final userProfile = await authRepository.login(
authRequest: authRequest,
);
@@ -187,7 +163,6 @@ void main() {
// Assert
expect(userProfile, isNull);
verify(() => mockAuthRemote.getUserInfo(phoneNumber)).called(1);
verify(() => mockAuthRemote.submitUserInfo(any())).called(1);
verify(() => mockAuthRemote.login(authRequest: authRequest)).called(1);
});
});
@@ -209,7 +184,7 @@ void main() {
test('should track authentication state correctly', () async {
// Arrange
when(
() => mockAuthRemote.hasAuthenticated(),
() => mockAuthRemote.hasAuthenticated(),
).thenAnswer((_) async => true);
// Act
@@ -223,7 +198,7 @@ void main() {
test('should handle authentication state changes', () async {
// Arrange
when(
() => mockAuthRemote.hasAuthenticated(),
() => mockAuthRemote.hasAuthenticated(),
).thenAnswer((_) async => false);
// Act
@@ -236,40 +211,23 @@ void main() {
});
group('User Info Management', () {
test('should handle user info submission without device name', () async {
test('should get user info by phone', () async {
// Arrange
const phone = '09123456789';
final expectedData = {'mobile': phone, 'device_name': null};
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
// Act
await authRepository.submitUserInfo(phone: phone);
// Assert
verify(() => mockAuthRemote.submitUserInfo(expectedData)).called(1);
});
test('should handle user info submission with device name', () async {
// Arrange
const phone = '09123456789';
const deviceName = 'Test Device';
final expectedData = {'mobile': phone, 'device_name': deviceName};
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
// Act
await authRepository.submitUserInfo(
phone: phone,
deviceName: deviceName,
final expectedUserInfo = UserInfoModel(
isUser: true,
address: 'Test Address',
backend: 'test-backend',
apiKey: 'test-api-key',
);
when(
() => mockAuthRemote.getUserInfo(phone),
).thenAnswer((_) async => expectedUserInfo);
// Act
final res = await authRepository.getUserInfo(phone);
// Assert
verify(() => mockAuthRemote.submitUserInfo(expectedData)).called(1);
expect(res, expectedUserInfo);
verify(() => mockAuthRemote.getUserInfo(phone)).called(1);
});
});
});