Skip to content

Commit

Permalink
Refector admin leaves test
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Aug 3, 2023
1 parent 9a11ffe commit 4a0e69e
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions test/unit_test/admin/leaves/leave_screen/admin_leaves_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void main() {
);

group('Admin Leaves fetch data test', () {
setUp(() {
setUpAll(() {
leaveRepo = MockLeaveRepo();
employeeRepo = MockEmployeeRepo();
lastDoc = MockDocumentSnapshot();
Expand All @@ -110,13 +110,9 @@ void main() {

test('Admin leave initial data load test', () {
when(employeeRepo.allEmployees).thenReturn([joi, andrew]);
when(leaveRepo.leaves())
.thenAnswer((_) async => PaginatedLeaves(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
joiPreviousYearLeave,
andrewCurrentYearLeave
], lastDoc: lastDoc));
when(leaveRepo.leaves()).thenAnswer((_) async => PaginatedLeaves(
leaves: [joiCurrentYearLeave, andrewCurrentYearLeave],
lastDoc: lastDoc));
bloc.add(InitialAdminLeavesEvent());
expect(
bloc.stream,
Expand All @@ -138,14 +134,68 @@ void main() {
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
joiPreviousYearLeave,
andrewCurrentYearLeave
], members: [
joi,
andrew
]).groupByAppliedOnMonth()),
]));
});

test('Search employee test', () {
bloc.add(SearchEmployeeEvent(search: 'joi'));
expectLater(
bloc.stream,
emits(AdminLeavesState(
members: [joi],
membersFetchStatus: Status.success,
leavesFetchStatus: Status.success,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth())));
});

test('select employee test', () {
bloc.add(FetchLeavesInitialEvent(member: joi));
when(leaveRepo.leaves(uid: joi.uid)).thenAnswer((_) async =>
PaginatedLeaves(
leaves: [joiCurrentYearLeave, joiPreviousYearLeave],
lastDoc: lastDoc));
expectLater(
bloc.stream,
emitsInOrder([
AdminLeavesState(
members: [joi],
selectedMember: joi,
membersFetchStatus: Status.success,
leavesFetchStatus: Status.loading,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
andrewCurrentYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth()),
AdminLeavesState(
members: [joi],
selectedMember: joi,
membersFetchStatus: Status.success,
leavesFetchStatus: Status.success,
leaveApplicationMap:
getLeaveApplicationFromLeaveEmployee(leaves: [
joiCurrentYearLeave,
joiPreviousYearLeave,
], members: [
joi,
andrew
]).groupByAppliedOnMonth())
]));
});
});
});
}

0 comments on commit 4a0e69e

Please sign in to comment.