From 77fbcbe51796646101ec0531cd857d95348788fe Mon Sep 17 00:00:00 2001 From: yashita-egov Date: Thu, 5 Dec 2024 16:50:03 +0530 Subject: [PATCH] added test case for household overview bloc --- .../test/constants/test_constants.dart | 8 +- .../test/household_overview_test.dart | 76 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/packages/registration_delivery/test/constants/test_constants.dart b/packages/registration_delivery/test/constants/test_constants.dart index 3783e71f5..bf2592911 100644 --- a/packages/registration_delivery/test/constants/test_constants.dart +++ b/packages/registration_delivery/test/constants/test_constants.dart @@ -48,6 +48,7 @@ class RegistrationDeliveryTestConstants { static IndividualModel individualModel = IndividualModel( clientReferenceId: '1ce2-3f4g-5h6i-7j8k-9l0m', + name: NameModel(givenName: 'test'), address: [mockAddress], ); @@ -64,6 +65,9 @@ class RegistrationDeliveryTestConstants { static HouseholdMemberWrapper householdMemberWrapper = HouseholdMemberWrapper( household: mockHousehold, headOfHousehold: mockIndividual, - members: [], - projectBeneficiaries: []); + members: [individualModel], + projectBeneficiaries: [mockProjectBeneficiary], + tasks: [], + sideEffects: [], + referrals: []); } diff --git a/packages/registration_delivery/test/household_overview_test.dart b/packages/registration_delivery/test/household_overview_test.dart index aa5be5c24..dc9503113 100644 --- a/packages/registration_delivery/test/household_overview_test.dart +++ b/packages/registration_delivery/test/household_overview_test.dart @@ -1,4 +1,5 @@ import 'package:bloc_test/bloc_test.dart'; +import 'package:digit_data_model/models/entities/household_type.dart'; import 'package:digit_data_model/utils/typedefs.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; @@ -11,6 +12,7 @@ import 'package:registration_delivery/models/entities/project_beneficiary.dart'; import 'package:registration_delivery/models/entities/referral.dart'; import 'package:registration_delivery/models/entities/side_effect.dart'; import 'package:registration_delivery/models/entities/task.dart'; +import 'package:registration_delivery/utils/global_search_parameters.dart'; import 'package:registration_delivery/utils/typedefs.dart'; import 'constants/test_constants.dart'; @@ -52,6 +54,8 @@ void main() { mockIndividualGlobalSearchRepository; setUp(() { + mockIndividualGlobalSearchRepository = + MockIndividualGlobalSearchRepository(); mockHouseholdDataRepository = MockHouseholdDataRepository(); mockIndividualDataRepository = MockIndividualDataRepository(); mockHouseholdMemberDataRepository = MockHouseholdMemberDataRepository(); @@ -79,6 +83,18 @@ void main() { }); setUpAll(() { + registerFallbackValue(GlobalSearchParameters( + householdType: HouseholdType.community, + householdClientReferenceId: '1ce2-3f4g-5h6i-7j8k-9l0m', + isProximityEnabled: false, + latitude: null, + longitude: null, + maxRadius: null, + nameSearch: 'test', + offset: null, + limit: null, + filter: [], + )); registerFallbackValue(HouseholdSearchModel()); registerFallbackValue(HouseholdMemberSearchModel()); registerFallbackValue(IndividualSearchModel()); @@ -124,4 +140,64 @@ void main() { ) ], ); + + //Test case for when search is performed + blocTest( + 'emits [loading: true, search results] when search is performed', + build: () { + // Mock search behavior for individual and household members + when(() => + mockIndividualGlobalSearchRepository + .individualGlobalSearch(any())).thenAnswer((_) async => { + 'total_count': 0, + 'data': [RegistrationDeliveryTestConstants.individualModel] + }); + + when(() => mockHouseholdMemberDataRepository.search(any())) + .thenAnswer((_) async => [ + RegistrationDeliveryTestConstants.mockHouseholdMember, + ]); + when(() => mockHouseholdDataRepository.search(any())) + .thenAnswer((_) async => [ + RegistrationDeliveryTestConstants.mockHousehold, + ]); + when(() => mockIndividualDataRepository.search(any())) + .thenAnswer((_) async => [ + RegistrationDeliveryTestConstants.mockIndividual, + ]); + when(() => mockProjectBeneficiaryDataRepository.search(any())) + .thenAnswer((_) async => [ + RegistrationDeliveryTestConstants.mockProjectBeneficiary, + ]); + when(() => mockTaskDataRepository.search(any())) + .thenAnswer((_) async => []); + when(() => mockSideEffectDataRepository.search(any())) + .thenAnswer((_) async => []); + when(() => mockReferralDataRepository.search(any())) + .thenAnswer((_) async => []); + + return householdOverviewBloc; + }, + act: (bloc) { + // Perform a search query + bloc.add(const HouseholdOverviewReloadEvent( + projectId: RegistrationDeliveryTestConstants.testProjectId, + projectBeneficiaryType: BeneficiaryType.individual, + searchByName: 'test', + selectedFilter: [], + )); + }, + expect: () => [ + HouseholdOverviewState( + loading: true, + householdMemberWrapper: + RegistrationDeliveryTestConstants.householdMemberWrapper, + ), + HouseholdOverviewState( + loading: false, + householdMemberWrapper: + RegistrationDeliveryTestConstants.householdMemberWrapper, + offset: 10), + ], + ); }