From c0e33d7b9a74fec2068434a58588fddadfeb970d Mon Sep 17 00:00:00 2001 From: Sneha Canopas <92501869+cp-sneha-s@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:49:00 +0530 Subject: [PATCH] Fix show events on home screen (#78) --- lib/data/di/service_locator.config.dart | 4 +- lib/data/repo/employee_repo.dart | 9 ++- .../celebration_event_bloc_test.mocks.dart | 79 +++++++++++++++++++ 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 test/unit_test/shared/events/celebration_event_bloc_test.mocks.dart diff --git a/lib/data/di/service_locator.config.dart b/lib/data/di/service_locator.config.dart index a6bbbb6f..96912f39 100644 --- a/lib/data/di/service_locator.config.dart +++ b/lib/data/di/service_locator.config.dart @@ -272,8 +272,8 @@ extension GetItInjectableX on _i1.GetIt { gh<_i25.UserStateNotifier>(), gh<_i23.StorageService>(), )); - gh.lazySingleton<_i51.EmployeeRepo>( - () => _i51.EmployeeRepo( + gh.singleton<_i51.EmployeeRepo>( + _i51.EmployeeRepo( gh<_i30.EmployeeService>(), gh<_i25.UserStateNotifier>(), gh<_i10.FirebaseCrashlytics>(), diff --git a/lib/data/repo/employee_repo.dart b/lib/data/repo/employee_repo.dart index 9b7f2d56..42c6f1c2 100644 --- a/lib/data/repo/employee_repo.dart +++ b/lib/data/repo/employee_repo.dart @@ -7,7 +7,7 @@ import 'package:rxdart/rxdart.dart'; import '../model/employee/employee.dart'; import '../services/employee_service.dart'; -@LazySingleton() +@Singleton() class EmployeeRepo { final EmployeeService _employeeService; final UserStateNotifier _userStateNotifier; @@ -34,7 +34,12 @@ class EmployeeRepo { Stream> get employees => _employeeController.stream.asBroadcastStream(); - List get allEmployees => _employeeController.value; + List get allEmployees { + if (_employeeController.hasValue) { + return _employeeController.stream.value; + } + return []; + } Stream> get activeEmployees => _employeeController.stream.asyncMap((employees) => employees diff --git a/test/unit_test/shared/events/celebration_event_bloc_test.mocks.dart b/test/unit_test/shared/events/celebration_event_bloc_test.mocks.dart new file mode 100644 index 00000000..efeb9aab --- /dev/null +++ b/test/unit_test/shared/events/celebration_event_bloc_test.mocks.dart @@ -0,0 +1,79 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in projectunity/test/unit_test/shared/events/celebration_event_bloc_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:projectunity/data/model/employee/employee.dart' as _i4; +import 'package:projectunity/data/repo/employee_repo.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +/// A class which mocks [EmployeeRepo]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockEmployeeRepo extends _i1.Mock implements _i2.EmployeeRepo { + MockEmployeeRepo() { + _i1.throwOnMissingStub(this); + } + + @override + _i3.Stream> get employees => (super.noSuchMethod( + Invocation.getter(#employees), + returnValue: _i3.Stream>.empty(), + ) as _i3.Stream>); + + @override + List<_i4.Employee> get allEmployees => (super.noSuchMethod( + Invocation.getter(#allEmployees), + returnValue: <_i4.Employee>[], + ) as List<_i4.Employee>); + + @override + _i3.Stream> get activeEmployees => (super.noSuchMethod( + Invocation.getter(#activeEmployees), + returnValue: _i3.Stream>.empty(), + ) as _i3.Stream>); + + @override + _i3.Stream<_i4.Employee?> memberDetails(String? uid) => (super.noSuchMethod( + Invocation.method( + #memberDetails, + [uid], + ), + returnValue: _i3.Stream<_i4.Employee?>.empty(), + ) as _i3.Stream<_i4.Employee?>); + + @override + _i3.Future reset() => (super.noSuchMethod( + Invocation.method( + #reset, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future dispose() => (super.noSuchMethod( + Invocation.method( + #dispose, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +}