Skip to content

Commit

Permalink
added test case for household overview bloc
Browse files Browse the repository at this point in the history
  • Loading branch information
yashita-egov committed Dec 5, 2024
1 parent c9a7b24 commit 77fbcbe
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class RegistrationDeliveryTestConstants {

static IndividualModel individualModel = IndividualModel(
clientReferenceId: '1ce2-3f4g-5h6i-7j8k-9l0m',
name: NameModel(givenName: 'test'),
address: [mockAddress],
);

Expand All @@ -64,6 +65,9 @@ class RegistrationDeliveryTestConstants {
static HouseholdMemberWrapper householdMemberWrapper = HouseholdMemberWrapper(
household: mockHousehold,
headOfHousehold: mockIndividual,
members: [],
projectBeneficiaries: []);
members: [individualModel],
projectBeneficiaries: [mockProjectBeneficiary],
tasks: [],
sideEffects: [],
referrals: []);
}
76 changes: 76 additions & 0 deletions packages/registration_delivery/test/household_overview_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -52,6 +54,8 @@ void main() {
mockIndividualGlobalSearchRepository;

setUp(() {
mockIndividualGlobalSearchRepository =
MockIndividualGlobalSearchRepository();
mockHouseholdDataRepository = MockHouseholdDataRepository();
mockIndividualDataRepository = MockIndividualDataRepository();
mockHouseholdMemberDataRepository = MockHouseholdMemberDataRepository();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -124,4 +140,64 @@ void main() {
)
],
);

//Test case for when search is performed
blocTest<HouseholdOverviewBloc, HouseholdOverviewState>(
'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),
],
);
}

0 comments on commit 77fbcbe

Please sign in to comment.