Skip to content

Commit

Permalink
Add test for fetch more data
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Aug 3, 2023
1 parent 61176fc commit c9ca8ed
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/unit_test/admin/leaves/leave_screen/admin_leaves_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,85 @@ void main() {
]));
});
});

group('Admin leaves fetch more leaves test', () {
setUpAll(() {
leaveRepo = MockLeaveRepo();
employeeRepo = MockEmployeeRepo();
lastDoc = MockDocumentSnapshot();
bloc = AdminLeavesBloc(leaveRepo, employeeRepo);
});

test('Admin leave initial data load test', () {
when(employeeRepo.allEmployees).thenReturn([joi, andrew]);
when(leaveRepo.leaves()).thenAnswer((_) async => PaginatedLeaves(
leaves: [joiCurrentYearLeave, andrewCurrentYearLeave],
lastDoc: lastDoc));
bloc.add(InitialAdminLeavesEvent());
expect(
bloc.stream,
emitsInOrder([
AdminLeavesState(
members: [joi, andrew],
membersFetchStatus: Status.success,
),
AdminLeavesState(
members: [joi, andrew],
membersFetchStatus: Status.success,
leavesFetchStatus: Status.loading,
),
AdminLeavesState(
members: [joi, andrew],
membersFetchStatus: Status.success,
leavesFetchStatus: Status.success,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth()),
]));
});

test('Fetch more leave test', () {
when(leaveRepo.leaves(lastDoc: anyNamed('lastDoc'))).thenAnswer(
(_) async => PaginatedLeaves(
leaves: [joiPreviousYearLeave], lastDoc: lastDoc));
bloc.add(FetchMoreLeavesEvent());
expect(
bloc.stream,
emitsInOrder([
AdminLeavesState(
showPaginationLoading: true,
members: [joi, andrew],
membersFetchStatus: Status.success,
leavesFetchStatus: Status.success,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth()),
AdminLeavesState(
showPaginationLoading: false,
members: [joi, andrew],
membersFetchStatus: Status.success,
leavesFetchStatus: Status.success,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
joiPreviousYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth()),
]));
});
});
});
}

0 comments on commit c9ca8ed

Please sign in to comment.