High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
chore: cleanup partner action test (#29296)
shenlong3a7034d25e17
diff --git a/mobile/test/unit/presentation/actions/partner_action_test.dart b/mobile/test/unit/presentation/actions/partner_action_test.dartindex 1eb89fe4cc..0284371c91 100644--- a/mobile/test/unit/presentation/actions/partner_action_test.dart+++ b/mobile/test/unit/presentation/actions/partner_action_test.dart@@ -5,32 +5,25 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';import 'package:immich_mobile/domain/models/user.model.dart';import 'package:immich_mobile/presentation/actions/partner.action.dart';import 'package:immich_mobile/providers/infrastructure/user.provider.dart';-import 'package:immich_mobile/providers/user.provider.dart';import 'package:mocktail/mocktail.dart';import '../../factories/user_factory.dart';-import '../../mocks.dart';import '../../presentation_context.dart';void main() {late PresentationContext context;- late UserDto currentUser;- final mocks = ServiceMocks();setUp(() async {- currentUser = UserFactory.createDto();context = await PresentationContext.create();- when(mocks.user.tryGetMyUser).thenReturn(currentUser);});- tearDown(() async {- mocks.resetAll();- await context.dispose();+ tearDown(() {+ context.dispose();});List<Override> overrides({List<User> candidates = const []}) => [- currentUserProvider.overrideWith((ref) => CurrentUserProvider(mocks.user.service)),- partnerServiceProvider.overrideWithValue(mocks.partner.service),+ ...context.overrides,+ partnerServiceProvider.overrideWithValue(context.mocks.partner.service),candidatesStateProvider.overrideWith((ref) => Stream<Iterable<User>>.value(candidates)),];@@ -43,7 +36,9 @@ void main() {await tester.tap(find.text(candidate.name));await tester.pumpAndSettle();- verify(() => mocks.partner.service.create(sharedById: currentUser.id, sharedWithId: candidate.id)).called(1);+ verify(+ () => context.mocks.partner.service.create(sharedById: context.currentUser.id, sharedWithId: candidate.id),+ ).called(1);});testWidgets('creates nothing when the selection dialog is dismissed', (tester) async {@@ -51,7 +46,7 @@ void main() {await tester.sendKeyEvent(LogicalKeyboardKey.escape); // dismiss without selectingawait tester.pumpAndSettle();- verifyNever(mocks.partner.create);+ verifyNever(context.mocks.partner.create);});});@@ -65,7 +60,9 @@ void main() {await tester.tap(find.byType(TextButton).last); // confirmawait tester.pumpAndSettle();- verify(() => mocks.partner.service.delete(sharedById: currentUser.id, sharedWithId: partner.id)).called(1);+ verify(+ () => context.mocks.partner.service.delete(sharedById: context.currentUser.id, sharedWithId: partner.id),+ ).called(1);});testWidgets('deletes nothing when the confirmation is cancelled', (tester) async {@@ -77,7 +74,7 @@ void main() {await tester.tap(find.byType(TextButton).first); // cancelawait tester.pumpAndSettle();- verifyNever(mocks.partner.delete);+ verifyNever(context.mocks.partner.delete);});});}diff --git a/mobile/test/unit/presentation/partner_page_test.dart b/mobile/test/unit/presentation/partner_page_test.dartindex 4557388dc0..6575b4a15c 100644--- a/mobile/test/unit/presentation/partner_page_test.dart+++ b/mobile/test/unit/presentation/partner_page_test.dart@@ -13,7 +13,7 @@ void main() {late PresentationContext context;setUp(() async => context = await PresentationContext.create());- tearDown(() async => await context.dispose());+ tearDown(() => context.dispose());group('PartnerSharedByList', () {testWidgets('shows the empty-state add button when there are no partners', (tester) async {diff --git a/mobile/test/unit/presentation_context.dart b/mobile/test/unit/presentation_context.dartindex e411b21802..31b5bc0aff 100644--- a/mobile/test/unit/presentation_context.dart+++ b/mobile/test/unit/presentation_context.dart@@ -23,7 +23,7 @@ import 'mocks.dart';class PresentationContext {PresentationContext._({required UserDto user}) : currentUser = user, mocks = ServiceMocks() {- when(mocks.user.tryGetMyUser).thenReturn(currentUser);+ setup();}static const String serverEndpoint = 'http://localhost:3000';@@ -46,10 +46,14 @@ class PresentationContext {return PresentationContext._(user: UserFactory.createDto());}- Future<void> dispose() async {- // TODO: Dispose the store and database after each test.- // This is currently not possible because the store is a singleton and is used across tests.- // Refactor the store to be created per test to allow proper disposal.+ void setup() {+ when(mocks.user.tryGetMyUser).thenReturn(currentUser);+ }++ void dispose() {+ addTearDown(() {+ mocks.resetAll();+ });}}