feat: Initialize project
This commit is contained in:
78
test/helpers/test_helpers.dart
Normal file
78
test/helpers/test_helpers.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:bahla_front/app/app.locator.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
// @stacked-import
|
||||
|
||||
import 'test_helpers.mocks.dart';
|
||||
|
||||
@GenerateMocks([], customMocks: [
|
||||
MockSpec<NavigationService>(onMissingStub: OnMissingStub.returnDefault),
|
||||
MockSpec<BottomSheetService>(onMissingStub: OnMissingStub.returnDefault),
|
||||
MockSpec<DialogService>(onMissingStub: OnMissingStub.returnDefault),
|
||||
// @stacked-mock-spec
|
||||
])
|
||||
void registerServices() {
|
||||
getAndRegisterNavigationService();
|
||||
getAndRegisterBottomSheetService();
|
||||
getAndRegisterDialogService();
|
||||
// @stacked-mock-register
|
||||
}
|
||||
|
||||
MockNavigationService getAndRegisterNavigationService() {
|
||||
_removeRegistrationIfExists<NavigationService>();
|
||||
final service = MockNavigationService();
|
||||
locator.registerSingleton<NavigationService>(service);
|
||||
return service;
|
||||
}
|
||||
|
||||
MockBottomSheetService getAndRegisterBottomSheetService<T>({
|
||||
SheetResponse<T>? showCustomSheetResponse,
|
||||
}) {
|
||||
_removeRegistrationIfExists<BottomSheetService>();
|
||||
final service = MockBottomSheetService();
|
||||
|
||||
when(service.showCustomSheet<T, T>(
|
||||
enableDrag: anyNamed('enableDrag'),
|
||||
enterBottomSheetDuration: anyNamed('enterBottomSheetDuration'),
|
||||
exitBottomSheetDuration: anyNamed('exitBottomSheetDuration'),
|
||||
ignoreSafeArea: anyNamed('ignoreSafeArea'),
|
||||
isScrollControlled: anyNamed('isScrollControlled'),
|
||||
barrierDismissible: anyNamed('barrierDismissible'),
|
||||
additionalButtonTitle: anyNamed('additionalButtonTitle'),
|
||||
variant: anyNamed('variant'),
|
||||
title: anyNamed('title'),
|
||||
hasImage: anyNamed('hasImage'),
|
||||
imageUrl: anyNamed('imageUrl'),
|
||||
showIconInMainButton: anyNamed('showIconInMainButton'),
|
||||
mainButtonTitle: anyNamed('mainButtonTitle'),
|
||||
showIconInSecondaryButton: anyNamed('showIconInSecondaryButton'),
|
||||
secondaryButtonTitle: anyNamed('secondaryButtonTitle'),
|
||||
showIconInAdditionalButton: anyNamed('showIconInAdditionalButton'),
|
||||
takesInput: anyNamed('takesInput'),
|
||||
barrierColor: anyNamed('barrierColor'),
|
||||
barrierLabel: anyNamed('barrierLabel'),
|
||||
customData: anyNamed('customData'),
|
||||
data: anyNamed('data'),
|
||||
description: anyNamed('description'),
|
||||
)).thenAnswer((realInvocation) =>
|
||||
Future.value(showCustomSheetResponse ?? SheetResponse<T>()));
|
||||
|
||||
locator.registerSingleton<BottomSheetService>(service);
|
||||
return service;
|
||||
}
|
||||
|
||||
MockDialogService getAndRegisterDialogService() {
|
||||
_removeRegistrationIfExists<DialogService>();
|
||||
final service = MockDialogService();
|
||||
locator.registerSingleton<DialogService>(service);
|
||||
return service;
|
||||
}
|
||||
|
||||
// @stacked-mock-create
|
||||
|
||||
void _removeRegistrationIfExists<T extends Object>() {
|
||||
if (locator.isRegistered<T>()) {
|
||||
locator.unregister<T>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user