From 755b28d47bd9cae2a913a74727ea595f7c92abb9 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 15 Aug 2024 23:00:57 +0200 Subject: [PATCH] refactor(neon_framework): Always use a real Account for testing Signed-off-by: provokateurin --- .../neon_framework/lib/src/testing/mocks.dart | 17 ++++++--- .../test/main_page_test.dart | 2 -- .../test/notification_test.dart | 2 -- .../talk_app/test/actor_avatar_test.dart | 4 --- .../talk_app/test/main_page_test.dart | 6 +--- .../packages/talk_app/test/message_test.dart | 35 +------------------ .../talk_app/test/reference_preview_test.dart | 4 --- .../talk_app/test/rich_object_test.dart | 13 +------ .../talk_app/test/room_avatar_test.dart | 5 --- .../talk_app/test/room_page_test.dart | 3 -- .../test/account_cache_test.dart | 4 +-- packages/neon_framework/test/dialog_test.dart | 3 -- packages/neon_framework/test/image_test.dart | 22 +++++------- .../neon_framework/test/persistence_test.dart | 2 -- .../test/request_manager_test.dart | 1 - .../test/settings_export_test.dart | 14 ++++---- .../neon_framework/test/user_avatar_test.dart | 5 --- 17 files changed, 32 insertions(+), 110 deletions(-) diff --git a/packages/neon_framework/lib/src/testing/mocks.dart b/packages/neon_framework/lib/src/testing/mocks.dart index 33546946425..779a0b97155 100644 --- a/packages/neon_framework/lib/src/testing/mocks.dart +++ b/packages/neon_framework/lib/src/testing/mocks.dart @@ -2,7 +2,6 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; -import 'package:meta/meta.dart'; // ignore: depend_on_referenced_packages import 'package:mocktail/mocktail.dart'; import 'package:neon_framework/blocs.dart'; @@ -23,10 +22,18 @@ import 'package:shared_preferences_platform_interface/shared_preferences_platfor // ignore: depend_on_referenced_packages import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; -class MockAccount extends Mock implements Account { - @internal - @override - Uri completeUri(Uri uri) => uri; +// ignore: non_constant_identifier_names +Account MockAccount({ + String serverURL = 'https://cloud.example.com:8443/nextcloud', + String username = 'username', + String password = 'password', +}) { + return Account( + (b) => b + ..serverURL = Uri.parse(serverURL) + ..username = username + ..password = password, + ); } class MockAccountCache extends Mock implements AccountCache {} diff --git a/packages/neon_framework/packages/notifications_app/test/main_page_test.dart b/packages/neon_framework/packages/notifications_app/test/main_page_test.dart index 3c5a659ee33..5595b4f77fb 100644 --- a/packages/neon_framework/packages/notifications_app/test/main_page_test.dart +++ b/packages/neon_framework/packages/notifications_app/test/main_page_test.dart @@ -8,7 +8,6 @@ import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/utils.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:notifications_app/l10n/localizations.dart'; import 'package:notifications_app/src/blocs/notifications.dart'; import 'package:notifications_app/src/pages/main.dart'; @@ -36,7 +35,6 @@ void main() { when(() => bloc.notifications).thenAnswer((_) => BehaviorSubject.seeded(Result.success(BuiltList()))); account = MockAccount(); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); }); testWidgets('Errors', (tester) async { diff --git a/packages/neon_framework/packages/notifications_app/test/notification_test.dart b/packages/neon_framework/packages/notifications_app/test/notification_test.dart index a805de2f920..fb7724a37bd 100644 --- a/packages/neon_framework/packages/notifications_app/test/notification_test.dart +++ b/packages/neon_framework/packages/notifications_app/test/notification_test.dart @@ -4,7 +4,6 @@ import 'package:mocktail/mocktail.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/notifications.dart' as notifications; import 'package:notifications_app/l10n/localizations.dart'; import 'package:notifications_app/src/widgets/action.dart'; @@ -47,7 +46,6 @@ void main() { callback = MockCallbackFunction().call; account = MockAccount(); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); }); testWidgets('Notification', (tester) async { diff --git a/packages/neon_framework/packages/talk_app/test/actor_avatar_test.dart b/packages/neon_framework/packages/talk_app/test/actor_avatar_test.dart index b173d943267..41e026ba221 100644 --- a/packages/neon_framework/packages/talk_app/test/actor_avatar_test.dart +++ b/packages/neon_framework/packages/talk_app/test/actor_avatar_test.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:provider/provider.dart'; import 'package:talk_app/src/widgets/actor_avatar.dart'; @@ -20,8 +18,6 @@ void main() { testWidgets('$type', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); await tester.pumpWidgetWithAccessibility( TestApp( diff --git a/packages/neon_framework/packages/talk_app/test/main_page_test.dart b/packages/neon_framework/packages/talk_app/test/main_page_test.dart index 39ac9e8ce51..11df2623b0c 100644 --- a/packages/neon_framework/packages/talk_app/test/main_page_test.dart +++ b/packages/neon_framework/packages/talk_app/test/main_page_test.dart @@ -8,7 +8,6 @@ import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/utils.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:nextcloud/utils.dart'; import 'package:provider/provider.dart'; @@ -54,10 +53,7 @@ void main() { when(() => bloc.errors).thenAnswer((_) => StreamController().stream); when(() => bloc.rooms).thenAnswer((_) => BehaviorSubject.seeded(Result.success(BuiltList([room])))); - account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.username).thenReturn('test'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); + account = MockAccount(username: 'test'); }); testWidgets('Errors', (tester) async { diff --git a/packages/neon_framework/packages/talk_app/test/message_test.dart b/packages/neon_framework/packages/talk_app/test/message_test.dart index a03a0299bd6..48895e11de4 100644 --- a/packages/neon_framework/packages/talk_app/test/message_test.dart +++ b/packages/neon_framework/packages/talk_app/test/message_test.dart @@ -9,7 +9,6 @@ import 'package:neon_framework/testing.dart'; import 'package:neon_framework/theme.dart'; import 'package:neon_framework/utils.dart'; import 'package:nextcloud/core.dart' as core; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; @@ -320,8 +319,6 @@ void main() { testWidgets('Comment', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final chatMessage = MockChatMessage(); when(() => chatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -404,8 +401,6 @@ void main() { testWidgets('TalkParentMessage', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final chatMessage = MockChatMessage(); when(() => chatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -437,10 +432,7 @@ void main() { group('TalkCommentMessage', () { testWidgets('Self', (tester) async { - final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.username).thenReturn('test'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); + final account = MockAccount(username: 'test'); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -494,9 +486,6 @@ void main() { testWidgets('Other', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.username).thenReturn('other'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -550,8 +539,6 @@ void main() { testWidgets('Deleted', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -596,8 +583,6 @@ void main() { testWidgets('As parent', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final chatMessage = MockChatMessage(); when(() => chatMessage.timestamp).thenReturn(0); @@ -636,8 +621,6 @@ void main() { testWidgets('With parent', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -722,8 +705,6 @@ void main() { ); final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final chatMessage = MockChatMessageWithParent(); when(() => chatMessage.id).thenReturn(0); @@ -778,8 +759,6 @@ void main() { group('Separate messages', () { testWidgets('Actor', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -831,8 +810,6 @@ void main() { testWidgets('Time', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -883,8 +860,6 @@ void main() { testWidgets('System message', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.system); @@ -936,8 +911,6 @@ void main() { testWidgets('Edited', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final previousChatMessage = MockChatMessage(); when(() => previousChatMessage.messageType).thenReturn(spreed.MessageType.comment); @@ -999,9 +972,6 @@ void main() { setUp(() { account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.username).thenReturn('test'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); chatMessage = MockChatMessage(); when(() => chatMessage.timestamp).thenReturn(0); @@ -1575,9 +1545,6 @@ void main() { .thenAnswer((_) => BehaviorSubject.seeded(Result.success(userDetails))); final account = MockAccount(); - when(() => account.id).thenReturn('id'); - when(() => account.username).thenReturn('username'); - when(() => account.client).thenReturn(NextcloudClient(Uri())); await tester.pumpWidgetWithAccessibility( TestApp( diff --git a/packages/neon_framework/packages/talk_app/test/reference_preview_test.dart b/packages/neon_framework/packages/talk_app/test/reference_preview_test.dart index 61c32462f98..c0459447b68 100644 --- a/packages/neon_framework/packages/talk_app/test/reference_preview_test.dart +++ b/packages/neon_framework/packages/talk_app/test/reference_preview_test.dart @@ -4,7 +4,6 @@ import 'package:mocktail/mocktail.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:provider/provider.dart'; import 'package:talk_app/src/widgets/reference_preview.dart'; @@ -33,7 +32,6 @@ void main() { testWidgets('Default', (tester) async { final account = MockAccount(); - when(() => account.client).thenReturn(NextcloudClient(Uri())); final openGraphObject = MockOpenGraphObject(); when(() => openGraphObject.name).thenReturn('name'); @@ -60,7 +58,6 @@ void main() { testWidgets('Opens link', (tester) async { final account = MockAccount(); - when(() => account.client).thenReturn(NextcloudClient(Uri())); final openGraphObject = MockOpenGraphObject(); when(() => openGraphObject.name).thenReturn('name'); @@ -87,7 +84,6 @@ void main() { testWidgets('With thumb', (tester) async { final account = MockAccount(); - when(() => account.client).thenReturn(NextcloudClient(Uri())); final openGraphObject = MockOpenGraphObject(); when(() => openGraphObject.thumb).thenReturn(''); diff --git a/packages/neon_framework/packages/talk_app/test/rich_object_test.dart b/packages/neon_framework/packages/talk_app/test/rich_object_test.dart index b371890cc77..0f79ea5c5b1 100644 --- a/packages/neon_framework/packages/talk_app/test/rich_object_test.dart +++ b/packages/neon_framework/packages/talk_app/test/rich_object_test.dart @@ -9,7 +9,6 @@ import 'package:neon_framework/testing.dart'; import 'package:neon_framework/theme.dart'; import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; @@ -30,16 +29,6 @@ void main() { setUp(() { account = MockAccount(); - when(() => account.id).thenReturn('id'); - when(() => account.username).thenReturn('username'); - when(() => account.serverURL).thenReturn(Uri.parse('http://example.com')); - when(() => account.client).thenReturn( - NextcloudClient( - Uri(), - loginName: '', - password: '', - ), - ); }); testWidgets('Deck card', (tester) async { @@ -434,7 +423,7 @@ void main() { find.byWidgetPredicate( (widget) => widget is NeonUriImage && - widget.uri.toString() == 'http://example.com/remote.php/dav/files/username/path', + widget.uri.toString() == 'https://cloud.example.com:8443/nextcloud/remote.php/dav/files/username/path', ), findsOne, ); diff --git a/packages/neon_framework/packages/talk_app/test/room_avatar_test.dart b/packages/neon_framework/packages/talk_app/test/room_avatar_test.dart index ac946df19cd..5b1c19c96d7 100644 --- a/packages/neon_framework/packages/talk_app/test/room_avatar_test.dart +++ b/packages/neon_framework/packages/talk_app/test/room_avatar_test.dart @@ -7,7 +7,6 @@ import 'package:neon_framework/testing.dart'; import 'package:neon_framework/theme.dart'; import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:provider/provider.dart'; import 'package:rxdart/subjects.dart'; @@ -22,8 +21,6 @@ void main() { testWidgets('Custom avatar', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final room = MockRoom(); when(() => room.isCustomAvatar).thenReturn(true); @@ -45,8 +42,6 @@ void main() { testWidgets('One to one', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn(''); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final userStatusBloc = MockUserStatusBloc(); when(() => userStatusBloc.statuses).thenAnswer((_) => BehaviorSubject.seeded(BuiltMap())); diff --git a/packages/neon_framework/packages/talk_app/test/room_page_test.dart b/packages/neon_framework/packages/talk_app/test/room_page_test.dart index bd9122dd7c7..00d50a564bf 100644 --- a/packages/neon_framework/packages/talk_app/test/room_page_test.dart +++ b/packages/neon_framework/packages/talk_app/test/room_page_test.dart @@ -10,7 +10,6 @@ import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/utils.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/spreed.dart' as spreed; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; @@ -164,8 +163,6 @@ void main() { when(() => bloc.reactions).thenAnswer((_) => BehaviorSubject.seeded(BuiltMap())); final account = MockAccount(); - when(() => account.id).thenReturn('id'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); await tester.pumpWidgetWithAccessibility( TestApp( diff --git a/packages/neon_framework/test/account_cache_test.dart b/packages/neon_framework/test/account_cache_test.dart index c82c3ce1a86..5b3ec670afd 100644 --- a/packages/neon_framework/test/account_cache_test.dart +++ b/packages/neon_framework/test/account_cache_test.dart @@ -6,8 +6,8 @@ import 'package:neon_framework/testing.dart'; void main() { final disposable0 = MockDisposable(); final disposable1 = MockDisposable(); - final account0 = MockAccount(); - final account1 = MockAccount(); + final account0 = MockAccount(username: '0'); + final account1 = MockAccount(username: '1'); group('AccountCache', () { test('map functionality', () { diff --git a/packages/neon_framework/test/dialog_test.dart b/packages/neon_framework/test/dialog_test.dart index 2c3cbe45646..eaf704ce723 100644 --- a/packages/neon_framework/test/dialog_test.dart +++ b/packages/neon_framework/test/dialog_test.dart @@ -406,7 +406,6 @@ void main() { testWidgets('Without drop_account', (tester) async { final account = MockAccount(); - when(() => account.humanReadableID).thenReturn(''); final capabilitiesBloc = MockCapabilitiesBloc(); when(() => capabilitiesBloc.capabilities).thenAnswer( @@ -433,7 +432,6 @@ void main() { group('With drop_account', () { testWidgets('Disabled', (tester) async { final account = MockAccount(); - when(() => account.humanReadableID).thenReturn(''); final capabilitiesBloc = MockCapabilitiesBloc(); when(() => capabilitiesBloc.capabilities).thenAnswer( @@ -482,7 +480,6 @@ void main() { testWidgets('Delay', (tester) async { final account = MockAccount(); - when(() => account.humanReadableID).thenReturn(''); final capabilitiesBloc = MockCapabilitiesBloc(); when(() => capabilitiesBloc.capabilities).thenAnswer( diff --git a/packages/neon_framework/test/image_test.dart b/packages/neon_framework/test/image_test.dart index 93d0328f30e..4a5f1f3627c 100644 --- a/packages/neon_framework/test/image_test.dart +++ b/packages/neon_framework/test/image_test.dart @@ -75,15 +75,12 @@ void main() { }); testWidgets('NeonApiImage', (tester) async { - final mockNextcloudClient = MockNextcloudClient(); - - final mockAccount = MockAccount(); - when(() => mockAccount.client).thenReturn(mockNextcloudClient); + final account = MockAccount(); final mockRequestManager = MockRequestManager(); when( () => mockRequestManager.wrap( - account: mockAccount, + account: account, getCacheHeaders: any(named: 'getCacheHeaders'), getRequest: any(named: 'getRequest'), converter: any(named: 'converter'), @@ -101,14 +98,14 @@ void main() { getRequest: (_) => mockRequest, etag: null, expires: null, - account: mockAccount, + account: account, ), ), ); verify( () => mockRequestManager.wrap( - account: mockAccount, + account: account, getCacheHeaders: any(named: 'getCacheHeaders'), getRequest: any(named: 'getRequest'), converter: any(named: 'converter'), @@ -119,16 +116,13 @@ void main() { }); testWidgets('NeonUriImage', (tester) async { - final mockNextcloudClient = MockNextcloudClient(); - - final mockAccount = MockAccount(); - when(() => mockAccount.client).thenReturn(mockNextcloudClient); + final account = MockAccount(); final mockRequestManager = MockRequestManager(); when( () => mockRequestManager.wrap( - account: mockAccount, + account: account, getCacheHeaders: any(named: 'getCacheHeaders'), getRequest: any(named: 'getRequest'), converter: any(named: 'converter'), @@ -143,14 +137,14 @@ void main() { TestApp( child: NeonUriImage( uri: uri, - account: mockAccount, + account: account, ), ), ); verify( () => mockRequestManager.wrap( - account: mockAccount, + account: account, getCacheHeaders: any(named: 'getCacheHeaders'), getRequest: any(named: 'getRequest'), converter: any(named: 'converter'), diff --git a/packages/neon_framework/test/persistence_test.dart b/packages/neon_framework/test/persistence_test.dart index 75e9acc7af1..7f5108ac976 100644 --- a/packages/neon_framework/test/persistence_test.dart +++ b/packages/neon_framework/test/persistence_test.dart @@ -5,7 +5,6 @@ import 'package:cookie_store/cookie_store.dart'; import 'package:cookie_store_conformance_tests/cookie_store_conformance_tests.dart' as cookie_jar_conformance; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; -import 'package:mocktail/mocktail.dart'; import 'package:neon_framework/src/storage/request_cache.dart'; import 'package:neon_framework/src/storage/sqlite_cookie_persistence.dart'; import 'package:neon_framework/src/storage/sqlite_persistence.dart'; @@ -17,7 +16,6 @@ void main() { group('Persistences', () { group('RequestCache', () { final account = MockAccount(); - when(() => account.id).thenReturn('clientID'); final cache = DefaultRequestCache(); diff --git a/packages/neon_framework/test/request_manager_test.dart b/packages/neon_framework/test/request_manager_test.dart index 10a218de014..a775c85cf89 100644 --- a/packages/neon_framework/test/request_manager_test.dart +++ b/packages/neon_framework/test/request_manager_test.dart @@ -19,7 +19,6 @@ String base64String(String value) => base64.encode(utf8.encode(value)); void main() { final account = MockAccount(); - when(() => account.id).thenReturn('clientID'); late MockNeonStorage storage; setUpAll(() { diff --git a/packages/neon_framework/test/settings_export_test.dart b/packages/neon_framework/test/settings_export_test.dart index 6876eff086a..69cc54e76b4 100644 --- a/packages/neon_framework/test/settings_export_test.dart +++ b/packages/neon_framework/test/settings_export_test.dart @@ -40,21 +40,21 @@ void main() { final bloc = MockAccountsBloc(); final exporter = AccountsBlocExporter(bloc); - const accountValue = MapEntry('accountID', 'value'); - const accountExport = { - 'accounts': {'accountID': 'value'}, + final account = MockAccount(); + + final accountValue = MapEntry(account.id, 'value'); + final accountExport = { + 'accounts': {account.id: 'value'}, }; when(() => bloc.accounts).thenAnswer((_) => BehaviorSubject.seeded(BuiltList())); var export = exporter.export(); expect(Map.fromEntries([export]), {'accounts': {}}); - final fakeAccount = MockAccount(); final fakeOptions = MockAccountOptions(); - when(() => bloc.accounts).thenAnswer((_) => BehaviorSubject.seeded(BuiltList([fakeAccount]))); - when(() => bloc.getOptionsFor(fakeAccount)).thenReturn(fakeOptions); + when(() => bloc.accounts).thenAnswer((_) => BehaviorSubject.seeded(BuiltList([account]))); + when(() => bloc.getOptionsFor(account)).thenReturn(fakeOptions); when(fakeOptions.export).thenReturn(accountValue); - when(() => fakeAccount.id).thenReturn('accountID'); export = exporter.export(); expect(Map.fromEntries([export]), accountExport); diff --git a/packages/neon_framework/test/user_avatar_test.dart b/packages/neon_framework/test/user_avatar_test.dart index c5730a56a78..c56b0271cee 100644 --- a/packages/neon_framework/test/user_avatar_test.dart +++ b/packages/neon_framework/test/user_avatar_test.dart @@ -6,7 +6,6 @@ import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/src/widgets/user_avatar.dart'; import 'package:neon_framework/testing.dart'; import 'package:neon_framework/widgets.dart'; -import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/user_status.dart' as user_status; import 'package:rxdart/rxdart.dart'; @@ -18,9 +17,6 @@ void main() { for (final (withStatus, matcher) in [(false, findsNothing), (true, findsOne)]) { testWidgets('${withStatus ? 'With' : 'Without'} status', (tester) async { final account = MockAccount(); - when(() => account.id).thenReturn('test'); - when(() => account.username).thenReturn('test'); - when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); final userStatusBloc = MockUserStatusBloc(); when(() => userStatusBloc.statuses).thenAnswer( @@ -48,7 +44,6 @@ void main() { ), ), ); - await tester.pumpAndSettle(); expect(find.byType(NeonUserStatusIndicator), matcher); });