From d7265ef549437ba70fe2e5f3a8ebffb25413a68c Mon Sep 17 00:00:00 2001 From: Terence ZAFINDRATAFA Date: Tue, 28 May 2024 17:13:57 +0200 Subject: [PATCH 01/11] TW-1702: regression fix + tests added for download on mobile --- .../download_manager/download_manager.dart | 24 +- .../manager/storage_directory_manager.dart | 2 + .../mixins/download_file_on_mobile_mixin.dart | 25 +- .../download_file_on_mobile_mixin_test.dart | 257 ++++ ...nload_file_on_mobile_mixin_test.mocks.dart | 1054 +++++++++++++++++ 5 files changed, 1343 insertions(+), 19 deletions(-) create mode 100644 test/mixin/download/download_file_on_mobile_mixin_test.dart create mode 100644 test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart diff --git a/lib/utils/manager/download_manager/download_manager.dart b/lib/utils/manager/download_manager/download_manager.dart index a283163d0a..4f828da0b0 100644 --- a/lib/utils/manager/download_manager/download_manager.dart +++ b/lib/utils/manager/download_manager/download_manager.dart @@ -26,14 +26,14 @@ class DownloadManager { final workingQueue = getIt.get(); - final Map _eventIdMapDownloadFileInfo = {}; + final Map eventIdMapDownloadFileInfo = {}; void cancelDownload(String eventId) { - final cancelToken = _eventIdMapDownloadFileInfo[eventId]?.cancelToken; + final cancelToken = eventIdMapDownloadFileInfo[eventId]?.cancelToken; if (cancelToken != null) { try { cancelToken.cancel(); - _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState( exception: CancelDownloadingException(), @@ -44,7 +44,7 @@ class DownloadManager { Logs().e( 'DownloadManager::cancelDownload(): $e', ); - _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), @@ -60,7 +60,7 @@ class DownloadManager { ) { final streamController = StreamController>(); - _eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( + eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( eventId: event.eventId, cancelToken: CancelToken(), downloadStateStreamController: streamController, @@ -69,25 +69,25 @@ class DownloadManager { } Stream>? getDownloadStateStream(String eventId) { - return _eventIdMapDownloadFileInfo[eventId]?.downloadStream; + return eventIdMapDownloadFileInfo[eventId]?.downloadStream; } Future clear(String eventId) async { try { - await _eventIdMapDownloadFileInfo[eventId] + await eventIdMapDownloadFileInfo[eventId] ?.downloadStateStreamController .close(); } catch (e) { Logs().e( 'DownloadManager::_clear(): $e', ); - _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), ); } finally { - _eventIdMapDownloadFileInfo.remove(eventId); + eventIdMapDownloadFileInfo.remove(eventId); Logs().i( 'DownloadManager::clear with $eventId successfully', ); @@ -100,14 +100,14 @@ class DownloadManager { bool isFirstPriority = false, }) async { _initDownloadFileInfo(event); - final streamController = _eventIdMapDownloadFileInfo[event.eventId] + final streamController = eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController; - final cancelToken = _eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; + final cancelToken = eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; if (streamController == null || cancelToken == null) { Logs().e( 'DownloadManager::download(): streamController or cancelToken is null', ); - _eventIdMapDownloadFileInfo[event.eventId] + eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController .add( Left( diff --git a/lib/utils/manager/storage_directory_manager.dart b/lib/utils/manager/storage_directory_manager.dart index d6d30fe836..2eefedb940 100644 --- a/lib/utils/manager/storage_directory_manager.dart +++ b/lib/utils/manager/storage_directory_manager.dart @@ -13,6 +13,8 @@ class StorageDirectoryManager { static StorageDirectoryManager get instance => _instance; + factory StorageDirectoryManager() => _instance; + Future getFileStoreDirectory() async { try { try { diff --git a/lib/widgets/mixins/download_file_on_mobile_mixin.dart b/lib/widgets/mixins/download_file_on_mobile_mixin.dart index 4a2a438835..11a1db8228 100644 --- a/lib/widgets/mixins/download_file_on_mobile_mixin.dart +++ b/lib/widgets/mixins/download_file_on_mobile_mixin.dart @@ -6,6 +6,7 @@ import 'package:fluffychat/app_state/failure.dart'; import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; +import 'package:fluffychat/utils/exception/downloading_exception.dart'; import 'package:fluffychat/utils/manager/download_manager/download_file_state.dart'; import 'package:fluffychat/utils/manager/storage_directory_manager.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/download_file_extension.dart'; @@ -17,6 +18,8 @@ import 'package:matrix/matrix.dart'; mixin DownloadFileOnMobileMixin on State { final downloadManager = getIt.get(); + final storageDirectoryManager = StorageDirectoryManager(); + final downloadFileStateNotifier = ValueNotifier( const NotDownloadPresentationState(), ); @@ -66,15 +69,17 @@ mixin DownloadFileOnMobileMixin on State { } Future checkFileInDownloadsInApp() async { - final filePath = - await StorageDirectoryManager.instance.getFilePathInAppDownloads( + final filePath = await storageDirectoryManager.getFilePathInAppDownloads( eventId: event.eventId, fileName: event.filename, ); - final file = File(filePath); + updateStateIfFileExists(File(filePath)); + } + + Future updateStateIfFileExists(File file) async { if (await file.exists() && await file.length() == event.getFileSize()) { downloadFileStateNotifier.value = DownloadedPresentationState( - filePath: filePath, + filePath: file.path, ); return; } @@ -89,9 +94,15 @@ mixin DownloadFileOnMobileMixin on State { void setupDownloadingProcess(Either resultEvent) { resultEvent.fold( (failure) { - Logs() - .e('$T::setupDownloadingProcess::onDownloadingProcess(): $failure'); - downloadFileStateNotifier.value = const NotDownloadPresentationState(); + Logs().e('MessageDownloadContent::onDownloadingProcess(): $failure'); + if (failure is DownloadFileFailureState && + failure.exception is CancelDownloadingException) { + downloadFileStateNotifier.value = + const NotDownloadPresentationState(); + } else { + downloadFileStateNotifier.value = + DownloadErrorPresentationState(error: failure); + } streamSubscription?.cancel(); }, (success) { diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.dart b/test/mixin/download/download_file_on_mobile_mixin_test.dart new file mode 100644 index 0000000000..11afc9ba40 --- /dev/null +++ b/test/mixin/download/download_file_on_mobile_mixin_test.dart @@ -0,0 +1,257 @@ +import 'dart:io'; + +import 'package:dartz/dartz.dart' hide State, OpenFile; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; +import 'package:fluffychat/utils/exception/downloading_exception.dart'; +import 'package:fluffychat/utils/manager/download_manager/download_file_state.dart'; +import 'package:fluffychat/utils/manager/download_manager/download_manager.dart'; +import 'package:fluffychat/widgets/mixins/download_file_on_mobile_mixin.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:matrix/matrix.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'download_file_on_mobile_mixin_test.mocks.dart'; + +const fakeEventId = "fakeEventId"; +const fakeFilename = "fakeFilename"; + +class MockRoom extends Mock implements Room { + @override + // ignore: hash_and_equals + bool operator ==(dynamic other) { + if (identical(this, other)) return true; + // ignore: unrelated_type_equality_checks + return other is Room && other.id == id; + } + + @override + Map get sendingFilePlaceholders => super.noSuchMethod( + Invocation.getter(#sendingFilePlaceholders), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class MockEvent extends Mock implements Event { + MockEvent(this.fakeRoom); + final Room fakeRoom; + @override + String get eventId => fakeEventId; + + @override + Room get room => fakeRoom; + + @override + Map get infoMap => super.noSuchMethod( + Invocation.getter(#infoMap), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class DummyWidget extends StatefulWidget { + const DummyWidget({required this.event, super.key}); + + final Event event; + + @override + // ignore: no_logic_in_create_state + DummyWidgetState createState() => DummyWidgetState(event); +} + +class DummyWidgetState extends State + with DownloadFileOnMobileMixin { + DummyWidgetState(this.fakeEvent); + + final Event fakeEvent; + + @override + Widget build(BuildContext context) { + return Container(); + } + + @override + Event get event => fakeEvent; +} + +@GenerateNiceMocks([ + MockSpec(), + MockSpec(), +]) +void main() { + group('DownloadFileOnMobileMixin: setupDownloadingProcess', () { + late DummyWidgetState dummyState; + late Event fakeEvent; + late Room fakeRoom; + + setUpAll(() { + getIt.registerSingleton(MockDownloadManager()); + fakeRoom = MockRoom(); + fakeEvent = MockEvent(fakeRoom); + dummyState = DummyWidgetState(fakeEvent); + }); + + tearDownAll(() { + getIt.reset(); + }); + + test('should handle failure', () { + final failure = DownloadFileFailureState(exception: Exception()); + dummyState.setupDownloadingProcess(Left(failure)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle cancel', () { + final failure = + DownloadFileFailureState(exception: CancelDownloadingException()); + dummyState.setupDownloadingProcess(Left(failure)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle success with DownloadingFileState', () { + const success = DownloadingFileState(receive: 10, total: 100); + dummyState.setupDownloadingProcess(const Right(success)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle success with DownloadNativeFileSuccessState', () { + const success = DownloadNativeFileSuccessState(filePath: 'path/to/file'); + dummyState.setupDownloadingProcess(const Right(success)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + }); + + group("DownloadFileOnMobileMixin: checkFileExistInMemory", () { + setUpAll(() { + getIt.registerSingleton(MockDownloadManager()); + }); + + tearDownAll(() { + getIt.reset(); + }); + + test('should update downloadFileStateNotifier if file exists in memory', + () { + final fakeRoom = MockRoom(); + final fakeEvent = MockEvent(fakeRoom); + final dummyState = DummyWidgetState(fakeEvent); + + when(fakeRoom.sendingFilePlaceholders).thenReturn({ + fakeEventId: MatrixFile( + name: fakeFilename, + filePath: "path/to/file", + ), + }); + + expect(dummyState.checkFileExistInMemory(), isTrue); + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test( + 'should not update downloadFileStateNotifier if file does not exist in memory', + () { + final fakeRoom = MockRoom(); + final fakeEvent = MockEvent(fakeRoom); + final dummyState = DummyWidgetState(fakeEvent); + + expect(dummyState.checkFileExistInMemory(), isFalse); + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + }); + + group("updateStateIfFileExists", () { + setUpAll(() { + getIt.registerSingleton(MockDownloadManager()); + }); + + tearDownAll(() { + getIt.reset(); + }); + + test( + 'should update downloadFileStateNotifier if file exists in app downloads', + () async { + final fakeRoom = MockRoom(); + final fakeEvent = MockEvent(fakeRoom); + final dummyState = DummyWidgetState(fakeEvent); + + final file = MockFile(); + when(file.exists()).thenAnswer((_) async => true); + when(file.length()).thenAnswer((_) async => 123); + when(fakeEvent.infoMap).thenReturn({'size': 123}); + when(file.path).thenReturn('path/to/file'); + + await dummyState.updateStateIfFileExists(file); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should not update downloadFileStateNotifier if file does not exists', + () async { + final fakeRoom = MockRoom(); + final fakeEvent = MockEvent(fakeRoom); + final dummyState = DummyWidgetState(fakeEvent); + + final file = MockFile(); + when(file.exists()).thenAnswer((_) async => false); + when(file.length()).thenAnswer((_) async => 123); + when(fakeEvent.infoMap).thenReturn({'size': 123}); + when(file.path).thenReturn('path/to/file'); + + await dummyState.updateStateIfFileExists(file); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test( + 'should not update downloadFileStateNotifier if file does have the same size as the event', + () async { + final fakeRoom = MockRoom(); + final fakeEvent = MockEvent(fakeRoom); + final dummyState = DummyWidgetState(fakeEvent); + + final file = MockFile(); + when(file.exists()).thenAnswer((_) async => true); + when(file.length()).thenAnswer((_) async => 1234); + when(fakeEvent.infoMap).thenReturn({'size': 123}); + when(file.path).thenReturn('path/to/file'); + + await dummyState.updateStateIfFileExists(file); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + }); +} diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart new file mode 100644 index 0000000000..8db9968b6c --- /dev/null +++ b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart @@ -0,0 +1,1054 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in fluffychat/test/mixin/download/download_file_on_mobile_mixin_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i5; +import 'dart:convert' as _i6; +import 'dart:io' as _i2; +import 'dart:typed_data' as _i7; + +import 'package:dartz/dartz.dart' as _i10; +import 'package:fluffychat/app_state/failure.dart' as _i11; +import 'package:fluffychat/app_state/success.dart' as _i12; +import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' + as _i9; +import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' + as _i8; +import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' + as _i3; +import 'package:matrix/matrix.dart' as _i13; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i4; + +// 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 + +class _FakeFile_0 extends _i1.SmartFake implements _i2.File { + _FakeFile_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUri_1 extends _i1.SmartFake implements Uri { + _FakeUri_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDirectory_2 extends _i1.SmartFake implements _i2.Directory { + _FakeDirectory_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFileSystemEntity_3 extends _i1.SmartFake + implements _i2.FileSystemEntity { + _FakeFileSystemEntity_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDateTime_4 extends _i1.SmartFake implements DateTime { + _FakeDateTime_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRandomAccessFile_5 extends _i1.SmartFake + implements _i2.RandomAccessFile { + _FakeRandomAccessFile_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeIOSink_6 extends _i1.SmartFake implements _i2.IOSink { + _FakeIOSink_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFileStat_7 extends _i1.SmartFake implements _i2.FileStat { + _FakeFileStat_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDownloadWorkerQueue_8 extends _i1.SmartFake + implements _i3.DownloadWorkerQueue { + _FakeDownloadWorkerQueue_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [File]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockFile extends _i1.Mock implements _i2.File { + @override + _i2.File get absolute => (super.noSuchMethod( + Invocation.getter(#absolute), + returnValue: _FakeFile_0( + this, + Invocation.getter(#absolute), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.getter(#absolute), + ), + ) as _i2.File); + + @override + String get path => (super.noSuchMethod( + Invocation.getter(#path), + returnValue: _i4.dummyValue( + this, + Invocation.getter(#path), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.getter(#path), + ), + ) as String); + + @override + Uri get uri => (super.noSuchMethod( + Invocation.getter(#uri), + returnValue: _FakeUri_1( + this, + Invocation.getter(#uri), + ), + returnValueForMissingStub: _FakeUri_1( + this, + Invocation.getter(#uri), + ), + ) as Uri); + + @override + bool get isAbsolute => (super.noSuchMethod( + Invocation.getter(#isAbsolute), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i2.Directory get parent => (super.noSuchMethod( + Invocation.getter(#parent), + returnValue: _FakeDirectory_2( + this, + Invocation.getter(#parent), + ), + returnValueForMissingStub: _FakeDirectory_2( + this, + Invocation.getter(#parent), + ), + ) as _i2.Directory); + + @override + _i5.Future<_i2.File> create({ + bool? recursive = false, + bool? exclusive = false, + }) => + (super.noSuchMethod( + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void createSync({ + bool? recursive = false, + bool? exclusive = false, + }) => + super.noSuchMethod( + Invocation.method( + #createSync, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> rename(String? newPath) => (super.noSuchMethod( + Invocation.method( + #rename, + [newPath], + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #rename, + [newPath], + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #rename, + [newPath], + ), + )), + ) as _i5.Future<_i2.File>); + + @override + _i2.File renameSync(String? newPath) => (super.noSuchMethod( + Invocation.method( + #renameSync, + [newPath], + ), + returnValue: _FakeFile_0( + this, + Invocation.method( + #renameSync, + [newPath], + ), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.method( + #renameSync, + [newPath], + ), + ), + ) as _i2.File); + + @override + _i5.Future<_i2.FileSystemEntity> delete({bool? recursive = false}) => + (super.noSuchMethod( + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + returnValue: + _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( + this, + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( + this, + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + )), + ) as _i5.Future<_i2.FileSystemEntity>); + + @override + void deleteSync({bool? recursive = false}) => super.noSuchMethod( + Invocation.method( + #deleteSync, + [], + {#recursive: recursive}, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> copy(String? newPath) => (super.noSuchMethod( + Invocation.method( + #copy, + [newPath], + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #copy, + [newPath], + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #copy, + [newPath], + ), + )), + ) as _i5.Future<_i2.File>); + + @override + _i2.File copySync(String? newPath) => (super.noSuchMethod( + Invocation.method( + #copySync, + [newPath], + ), + returnValue: _FakeFile_0( + this, + Invocation.method( + #copySync, + [newPath], + ), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.method( + #copySync, + [newPath], + ), + ), + ) as _i2.File); + + @override + _i5.Future length() => (super.noSuchMethod( + Invocation.method( + #length, + [], + ), + returnValue: _i5.Future.value(0), + returnValueForMissingStub: _i5.Future.value(0), + ) as _i5.Future); + + @override + int lengthSync() => (super.noSuchMethod( + Invocation.method( + #lengthSync, + [], + ), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + + @override + _i5.Future lastAccessed() => (super.noSuchMethod( + Invocation.method( + #lastAccessed, + [], + ), + returnValue: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastAccessed, + [], + ), + )), + returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastAccessed, + [], + ), + )), + ) as _i5.Future); + + @override + DateTime lastAccessedSync() => (super.noSuchMethod( + Invocation.method( + #lastAccessedSync, + [], + ), + returnValue: _FakeDateTime_4( + this, + Invocation.method( + #lastAccessedSync, + [], + ), + ), + returnValueForMissingStub: _FakeDateTime_4( + this, + Invocation.method( + #lastAccessedSync, + [], + ), + ), + ) as DateTime); + + @override + _i5.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( + Invocation.method( + #setLastAccessed, + [time], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + void setLastAccessedSync(DateTime? time) => super.noSuchMethod( + Invocation.method( + #setLastAccessedSync, + [time], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future lastModified() => (super.noSuchMethod( + Invocation.method( + #lastModified, + [], + ), + returnValue: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastModified, + [], + ), + )), + returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastModified, + [], + ), + )), + ) as _i5.Future); + + @override + DateTime lastModifiedSync() => (super.noSuchMethod( + Invocation.method( + #lastModifiedSync, + [], + ), + returnValue: _FakeDateTime_4( + this, + Invocation.method( + #lastModifiedSync, + [], + ), + ), + returnValueForMissingStub: _FakeDateTime_4( + this, + Invocation.method( + #lastModifiedSync, + [], + ), + ), + ) as DateTime); + + @override + _i5.Future setLastModified(DateTime? time) => (super.noSuchMethod( + Invocation.method( + #setLastModified, + [time], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + void setLastModifiedSync(DateTime? time) => super.noSuchMethod( + Invocation.method( + #setLastModifiedSync, + [time], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.RandomAccessFile> open( + {_i2.FileMode? mode = _i2.FileMode.read}) => + (super.noSuchMethod( + Invocation.method( + #open, + [], + {#mode: mode}, + ), + returnValue: + _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( + this, + Invocation.method( + #open, + [], + {#mode: mode}, + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( + this, + Invocation.method( + #open, + [], + {#mode: mode}, + ), + )), + ) as _i5.Future<_i2.RandomAccessFile>); + + @override + _i2.RandomAccessFile openSync({_i2.FileMode? mode = _i2.FileMode.read}) => + (super.noSuchMethod( + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + returnValue: _FakeRandomAccessFile_5( + this, + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + ), + returnValueForMissingStub: _FakeRandomAccessFile_5( + this, + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + ), + ) as _i2.RandomAccessFile); + + @override + _i5.Stream> openRead([ + int? start, + int? end, + ]) => + (super.noSuchMethod( + Invocation.method( + #openRead, + [ + start, + end, + ], + ), + returnValue: _i5.Stream>.empty(), + returnValueForMissingStub: _i5.Stream>.empty(), + ) as _i5.Stream>); + + @override + _i2.IOSink openWrite({ + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + }) => + (super.noSuchMethod( + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + returnValue: _FakeIOSink_6( + this, + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + ), + returnValueForMissingStub: _FakeIOSink_6( + this, + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + ), + ) as _i2.IOSink); + + @override + _i5.Future<_i7.Uint8List> readAsBytes() => (super.noSuchMethod( + Invocation.method( + #readAsBytes, + [], + ), + returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), + returnValueForMissingStub: + _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), + ) as _i5.Future<_i7.Uint8List>); + + @override + _i7.Uint8List readAsBytesSync() => (super.noSuchMethod( + Invocation.method( + #readAsBytesSync, + [], + ), + returnValue: _i7.Uint8List(0), + returnValueForMissingStub: _i7.Uint8List(0), + ) as _i7.Uint8List); + + @override + _i5.Future readAsString( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + returnValue: _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + )), + returnValueForMissingStub: + _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + )), + ) as _i5.Future); + + @override + String readAsStringSync({_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + returnValue: _i4.dummyValue( + this, + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + ), + ) as String); + + @override + _i5.Future> readAsLines( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsLines, + [], + {#encoding: encoding}, + ), + returnValue: _i5.Future>.value([]), + returnValueForMissingStub: _i5.Future>.value([]), + ) as _i5.Future>); + + @override + List readAsLinesSync( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsLinesSync, + [], + {#encoding: encoding}, + ), + returnValue: [], + returnValueForMissingStub: [], + ) as List); + + @override + _i5.Future<_i2.File> writeAsBytes( + List? bytes, { + _i2.FileMode? mode = _i2.FileMode.write, + bool? flush = false, + }) => + (super.noSuchMethod( + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void writeAsBytesSync( + List? bytes, { + _i2.FileMode? mode = _i2.FileMode.write, + bool? flush = false, + }) => + super.noSuchMethod( + Invocation.method( + #writeAsBytesSync, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> writeAsString( + String? contents, { + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + bool? flush = false, + }) => + (super.noSuchMethod( + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void writeAsStringSync( + String? contents, { + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + bool? flush = false, + }) => + super.noSuchMethod( + Invocation.method( + #writeAsStringSync, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future exists() => (super.noSuchMethod( + Invocation.method( + #exists, + [], + ), + returnValue: _i5.Future.value(false), + returnValueForMissingStub: _i5.Future.value(false), + ) as _i5.Future); + + @override + bool existsSync() => (super.noSuchMethod( + Invocation.method( + #existsSync, + [], + ), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i5.Future resolveSymbolicLinks() => (super.noSuchMethod( + Invocation.method( + #resolveSymbolicLinks, + [], + ), + returnValue: _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinks, + [], + ), + )), + returnValueForMissingStub: + _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinks, + [], + ), + )), + ) as _i5.Future); + + @override + String resolveSymbolicLinksSync() => (super.noSuchMethod( + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + returnValue: _i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + ), + ) as String); + + @override + _i5.Future<_i2.FileStat> stat() => (super.noSuchMethod( + Invocation.method( + #stat, + [], + ), + returnValue: _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( + this, + Invocation.method( + #stat, + [], + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( + this, + Invocation.method( + #stat, + [], + ), + )), + ) as _i5.Future<_i2.FileStat>); + + @override + _i2.FileStat statSync() => (super.noSuchMethod( + Invocation.method( + #statSync, + [], + ), + returnValue: _FakeFileStat_7( + this, + Invocation.method( + #statSync, + [], + ), + ), + returnValueForMissingStub: _FakeFileStat_7( + this, + Invocation.method( + #statSync, + [], + ), + ), + ) as _i2.FileStat); + + @override + _i5.Stream<_i2.FileSystemEvent> watch({ + int? events = 15, + bool? recursive = false, + }) => + (super.noSuchMethod( + Invocation.method( + #watch, + [], + { + #events: events, + #recursive: recursive, + }, + ), + returnValue: _i5.Stream<_i2.FileSystemEvent>.empty(), + returnValueForMissingStub: _i5.Stream<_i2.FileSystemEvent>.empty(), + ) as _i5.Stream<_i2.FileSystemEvent>); +} + +/// A class which mocks [DownloadManager]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { + @override + _i3.DownloadWorkerQueue get workingQueue => (super.noSuchMethod( + Invocation.getter(#workingQueue), + returnValue: _FakeDownloadWorkerQueue_8( + this, + Invocation.getter(#workingQueue), + ), + returnValueForMissingStub: _FakeDownloadWorkerQueue_8( + this, + Invocation.getter(#workingQueue), + ), + ) as _i3.DownloadWorkerQueue); + + @override + Map get eventIdMapDownloadFileInfo => + (super.noSuchMethod( + Invocation.getter(#eventIdMapDownloadFileInfo), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + + @override + void cancelDownload(String? eventId) => super.noSuchMethod( + Invocation.method( + #cancelDownload, + [eventId], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + String? eventId) => + (super.noSuchMethod( + Invocation.method( + #getDownloadStateStream, + [eventId], + ), + returnValueForMissingStub: null, + ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + + @override + _i5.Future clear(String? eventId) => (super.noSuchMethod( + Invocation.method( + #clear, + [eventId], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future download({ + required _i13.Event? event, + bool? getThumbnail = false, + bool? isFirstPriority = false, + }) => + (super.noSuchMethod( + Invocation.method( + #download, + [], + { + #event: event, + #getThumbnail: getThumbnail, + #isFirstPriority: isFirstPriority, + }, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); +} From 4faf07dd4375b3803cb55075d8a5400c30859c4a Mon Sep 17 00:00:00 2001 From: Terence ZAFINDRATAFA Date: Tue, 28 May 2024 18:04:40 +0200 Subject: [PATCH 02/11] TW-1702: error handling on download file on web fixed + tests added --- .../mixins/download_file_on_web_mixin.dart | 12 +- .../download_file_on_web_mixin_test.dart | 150 +++ ...download_file_on_web_mixin_test.mocks.dart | 1054 +++++++++++++++++ 3 files changed, 1214 insertions(+), 2 deletions(-) create mode 100644 test/mixin/download/download_file_on_web_mixin_test.dart create mode 100644 test/mixin/download/download_file_on_web_mixin_test.mocks.dart diff --git a/lib/widgets/mixins/download_file_on_web_mixin.dart b/lib/widgets/mixins/download_file_on_web_mixin.dart index 9532d762da..a0ea3b6a9d 100644 --- a/lib/widgets/mixins/download_file_on_web_mixin.dart +++ b/lib/widgets/mixins/download_file_on_web_mixin.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/app_state/failure.dart'; import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; +import 'package:fluffychat/utils/exception/downloading_exception.dart'; import 'package:fluffychat/utils/manager/download_manager/download_file_state.dart'; import 'package:fluffychat/utils/manager/download_manager/download_manager.dart'; import 'package:fluffychat/widgets/twake_app.dart'; @@ -44,8 +45,15 @@ mixin DownloadFileOnWebMixin on State { void setupDownloadingProcess(Either resultEvent) { resultEvent.fold( (failure) { - Logs().e('$T::onDownloadingProcess(): $failure'); - downloadFileStateNotifier.value = const NotDownloadPresentationState(); + Logs().e('MessageDownloadContentWeb::onDownloadingProcess(): $failure'); + if (failure is DownloadFileFailureState && + failure.exception is CancelDownloadingException) { + downloadFileStateNotifier.value = + const NotDownloadPresentationState(); + } else { + downloadFileStateNotifier.value = + DownloadErrorPresentationState(error: failure); + } }, (success) { if (success is DownloadingFileState) { diff --git a/test/mixin/download/download_file_on_web_mixin_test.dart b/test/mixin/download/download_file_on_web_mixin_test.dart new file mode 100644 index 0000000000..ecc21f8e16 --- /dev/null +++ b/test/mixin/download/download_file_on_web_mixin_test.dart @@ -0,0 +1,150 @@ +import 'dart:io'; + +import 'package:dartz/dartz.dart' hide State, OpenFile; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; +import 'package:fluffychat/utils/exception/downloading_exception.dart'; +import 'package:fluffychat/utils/manager/download_manager/download_file_state.dart'; +import 'package:fluffychat/utils/manager/download_manager/download_manager.dart'; +import 'package:fluffychat/widgets/mixins/download_file_on_web_mixin.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:matrix/matrix.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'download_file_on_web_mixin_test.mocks.dart'; + +const fakeEventId = "fakeEventId"; +const fakeFilename = "fakeFilename"; + +class MockRoom extends Mock implements Room { + @override + // ignore: hash_and_equals + bool operator ==(dynamic other) { + if (identical(this, other)) return true; + // ignore: unrelated_type_equality_checks + return other is Room && other.id == id; + } + + @override + Map get sendingFilePlaceholders => super.noSuchMethod( + Invocation.getter(#sendingFilePlaceholders), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class MockEvent extends Mock implements Event { + MockEvent(this.fakeRoom); + final Room fakeRoom; + @override + String get eventId => fakeEventId; + + @override + Room get room => fakeRoom; + + @override + Map get infoMap => super.noSuchMethod( + Invocation.getter(#infoMap), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class DummyWidget extends StatefulWidget { + const DummyWidget({required this.event, super.key}); + + final Event event; + + @override + // ignore: no_logic_in_create_state + DummyWidgetState createState() => DummyWidgetState(event); +} + +class DummyWidgetState extends State with DownloadFileOnWebMixin { + DummyWidgetState(this.fakeEvent); + + final Event fakeEvent; + + @override + Widget build(BuildContext context) { + return Container(); + } + + @override + Event get event => fakeEvent; + + @override + void handleDownloadMatrixFileSuccessDone({ + required DownloadMatrixFileSuccessState success, + }) {} +} + +@GenerateNiceMocks([ + MockSpec(), + MockSpec(), +]) +void main() { + group('DownloadFileOnWebMixin: setupDownloadingProcess', () { + late DummyWidgetState dummyState; + late Event fakeEvent; + late Room fakeRoom; + + setUp(() { + getIt.registerSingleton(MockDownloadManager()); + fakeRoom = MockRoom(); + fakeEvent = MockEvent(fakeRoom); + dummyState = DummyWidgetState(fakeEvent); + }); + + tearDown(() { + getIt.reset(); + }); + + test('should handle failure', () { + final failure = DownloadFileFailureState(exception: Exception()); + dummyState.setupDownloadingProcess(Left(failure)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle cancel', () { + final failure = DownloadFileFailureState( + exception: CancelDownloadingException(), + ); + dummyState.setupDownloadingProcess(Left(failure)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle success with DownloadingFileState', () { + const success = DownloadingFileState(receive: 10, total: 100); + dummyState.setupDownloadingProcess(const Right(success)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + + test('should handle success with DownloadMatrixFileSuccessState', () { + TestWidgetsFlutterBinding.ensureInitialized(); + + final success = DownloadMatrixFileSuccessState( + matrixFile: MatrixFile(name: "name"), + ); + dummyState.setupDownloadingProcess(Right(success)); + + expect( + dummyState.downloadFileStateNotifier.value, + isInstanceOf(), + ); + }); + }); +} diff --git a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart new file mode 100644 index 0000000000..dfaf094139 --- /dev/null +++ b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart @@ -0,0 +1,1054 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in fluffychat/test/mixin/download/download_file_on_web_mixin_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i5; +import 'dart:convert' as _i6; +import 'dart:io' as _i2; +import 'dart:typed_data' as _i7; + +import 'package:dartz/dartz.dart' as _i10; +import 'package:fluffychat/app_state/failure.dart' as _i11; +import 'package:fluffychat/app_state/success.dart' as _i12; +import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' + as _i9; +import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' + as _i8; +import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' + as _i3; +import 'package:matrix/matrix.dart' as _i13; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i4; + +// 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 + +class _FakeFile_0 extends _i1.SmartFake implements _i2.File { + _FakeFile_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUri_1 extends _i1.SmartFake implements Uri { + _FakeUri_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDirectory_2 extends _i1.SmartFake implements _i2.Directory { + _FakeDirectory_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFileSystemEntity_3 extends _i1.SmartFake + implements _i2.FileSystemEntity { + _FakeFileSystemEntity_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDateTime_4 extends _i1.SmartFake implements DateTime { + _FakeDateTime_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRandomAccessFile_5 extends _i1.SmartFake + implements _i2.RandomAccessFile { + _FakeRandomAccessFile_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeIOSink_6 extends _i1.SmartFake implements _i2.IOSink { + _FakeIOSink_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFileStat_7 extends _i1.SmartFake implements _i2.FileStat { + _FakeFileStat_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDownloadWorkerQueue_8 extends _i1.SmartFake + implements _i3.DownloadWorkerQueue { + _FakeDownloadWorkerQueue_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [File]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockFile extends _i1.Mock implements _i2.File { + @override + _i2.File get absolute => (super.noSuchMethod( + Invocation.getter(#absolute), + returnValue: _FakeFile_0( + this, + Invocation.getter(#absolute), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.getter(#absolute), + ), + ) as _i2.File); + + @override + String get path => (super.noSuchMethod( + Invocation.getter(#path), + returnValue: _i4.dummyValue( + this, + Invocation.getter(#path), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.getter(#path), + ), + ) as String); + + @override + Uri get uri => (super.noSuchMethod( + Invocation.getter(#uri), + returnValue: _FakeUri_1( + this, + Invocation.getter(#uri), + ), + returnValueForMissingStub: _FakeUri_1( + this, + Invocation.getter(#uri), + ), + ) as Uri); + + @override + bool get isAbsolute => (super.noSuchMethod( + Invocation.getter(#isAbsolute), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i2.Directory get parent => (super.noSuchMethod( + Invocation.getter(#parent), + returnValue: _FakeDirectory_2( + this, + Invocation.getter(#parent), + ), + returnValueForMissingStub: _FakeDirectory_2( + this, + Invocation.getter(#parent), + ), + ) as _i2.Directory); + + @override + _i5.Future<_i2.File> create({ + bool? recursive = false, + bool? exclusive = false, + }) => + (super.noSuchMethod( + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #create, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void createSync({ + bool? recursive = false, + bool? exclusive = false, + }) => + super.noSuchMethod( + Invocation.method( + #createSync, + [], + { + #recursive: recursive, + #exclusive: exclusive, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> rename(String? newPath) => (super.noSuchMethod( + Invocation.method( + #rename, + [newPath], + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #rename, + [newPath], + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #rename, + [newPath], + ), + )), + ) as _i5.Future<_i2.File>); + + @override + _i2.File renameSync(String? newPath) => (super.noSuchMethod( + Invocation.method( + #renameSync, + [newPath], + ), + returnValue: _FakeFile_0( + this, + Invocation.method( + #renameSync, + [newPath], + ), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.method( + #renameSync, + [newPath], + ), + ), + ) as _i2.File); + + @override + _i5.Future<_i2.FileSystemEntity> delete({bool? recursive = false}) => + (super.noSuchMethod( + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + returnValue: + _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( + this, + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( + this, + Invocation.method( + #delete, + [], + {#recursive: recursive}, + ), + )), + ) as _i5.Future<_i2.FileSystemEntity>); + + @override + void deleteSync({bool? recursive = false}) => super.noSuchMethod( + Invocation.method( + #deleteSync, + [], + {#recursive: recursive}, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> copy(String? newPath) => (super.noSuchMethod( + Invocation.method( + #copy, + [newPath], + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #copy, + [newPath], + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #copy, + [newPath], + ), + )), + ) as _i5.Future<_i2.File>); + + @override + _i2.File copySync(String? newPath) => (super.noSuchMethod( + Invocation.method( + #copySync, + [newPath], + ), + returnValue: _FakeFile_0( + this, + Invocation.method( + #copySync, + [newPath], + ), + ), + returnValueForMissingStub: _FakeFile_0( + this, + Invocation.method( + #copySync, + [newPath], + ), + ), + ) as _i2.File); + + @override + _i5.Future length() => (super.noSuchMethod( + Invocation.method( + #length, + [], + ), + returnValue: _i5.Future.value(0), + returnValueForMissingStub: _i5.Future.value(0), + ) as _i5.Future); + + @override + int lengthSync() => (super.noSuchMethod( + Invocation.method( + #lengthSync, + [], + ), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + + @override + _i5.Future lastAccessed() => (super.noSuchMethod( + Invocation.method( + #lastAccessed, + [], + ), + returnValue: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastAccessed, + [], + ), + )), + returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastAccessed, + [], + ), + )), + ) as _i5.Future); + + @override + DateTime lastAccessedSync() => (super.noSuchMethod( + Invocation.method( + #lastAccessedSync, + [], + ), + returnValue: _FakeDateTime_4( + this, + Invocation.method( + #lastAccessedSync, + [], + ), + ), + returnValueForMissingStub: _FakeDateTime_4( + this, + Invocation.method( + #lastAccessedSync, + [], + ), + ), + ) as DateTime); + + @override + _i5.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( + Invocation.method( + #setLastAccessed, + [time], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + void setLastAccessedSync(DateTime? time) => super.noSuchMethod( + Invocation.method( + #setLastAccessedSync, + [time], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future lastModified() => (super.noSuchMethod( + Invocation.method( + #lastModified, + [], + ), + returnValue: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastModified, + [], + ), + )), + returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( + this, + Invocation.method( + #lastModified, + [], + ), + )), + ) as _i5.Future); + + @override + DateTime lastModifiedSync() => (super.noSuchMethod( + Invocation.method( + #lastModifiedSync, + [], + ), + returnValue: _FakeDateTime_4( + this, + Invocation.method( + #lastModifiedSync, + [], + ), + ), + returnValueForMissingStub: _FakeDateTime_4( + this, + Invocation.method( + #lastModifiedSync, + [], + ), + ), + ) as DateTime); + + @override + _i5.Future setLastModified(DateTime? time) => (super.noSuchMethod( + Invocation.method( + #setLastModified, + [time], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + void setLastModifiedSync(DateTime? time) => super.noSuchMethod( + Invocation.method( + #setLastModifiedSync, + [time], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.RandomAccessFile> open( + {_i2.FileMode? mode = _i2.FileMode.read}) => + (super.noSuchMethod( + Invocation.method( + #open, + [], + {#mode: mode}, + ), + returnValue: + _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( + this, + Invocation.method( + #open, + [], + {#mode: mode}, + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( + this, + Invocation.method( + #open, + [], + {#mode: mode}, + ), + )), + ) as _i5.Future<_i2.RandomAccessFile>); + + @override + _i2.RandomAccessFile openSync({_i2.FileMode? mode = _i2.FileMode.read}) => + (super.noSuchMethod( + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + returnValue: _FakeRandomAccessFile_5( + this, + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + ), + returnValueForMissingStub: _FakeRandomAccessFile_5( + this, + Invocation.method( + #openSync, + [], + {#mode: mode}, + ), + ), + ) as _i2.RandomAccessFile); + + @override + _i5.Stream> openRead([ + int? start, + int? end, + ]) => + (super.noSuchMethod( + Invocation.method( + #openRead, + [ + start, + end, + ], + ), + returnValue: _i5.Stream>.empty(), + returnValueForMissingStub: _i5.Stream>.empty(), + ) as _i5.Stream>); + + @override + _i2.IOSink openWrite({ + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + }) => + (super.noSuchMethod( + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + returnValue: _FakeIOSink_6( + this, + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + ), + returnValueForMissingStub: _FakeIOSink_6( + this, + Invocation.method( + #openWrite, + [], + { + #mode: mode, + #encoding: encoding, + }, + ), + ), + ) as _i2.IOSink); + + @override + _i5.Future<_i7.Uint8List> readAsBytes() => (super.noSuchMethod( + Invocation.method( + #readAsBytes, + [], + ), + returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), + returnValueForMissingStub: + _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), + ) as _i5.Future<_i7.Uint8List>); + + @override + _i7.Uint8List readAsBytesSync() => (super.noSuchMethod( + Invocation.method( + #readAsBytesSync, + [], + ), + returnValue: _i7.Uint8List(0), + returnValueForMissingStub: _i7.Uint8List(0), + ) as _i7.Uint8List); + + @override + _i5.Future readAsString( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + returnValue: _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + )), + returnValueForMissingStub: + _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #readAsString, + [], + {#encoding: encoding}, + ), + )), + ) as _i5.Future); + + @override + String readAsStringSync({_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + returnValue: _i4.dummyValue( + this, + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.method( + #readAsStringSync, + [], + {#encoding: encoding}, + ), + ), + ) as String); + + @override + _i5.Future> readAsLines( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsLines, + [], + {#encoding: encoding}, + ), + returnValue: _i5.Future>.value([]), + returnValueForMissingStub: _i5.Future>.value([]), + ) as _i5.Future>); + + @override + List readAsLinesSync( + {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method( + #readAsLinesSync, + [], + {#encoding: encoding}, + ), + returnValue: [], + returnValueForMissingStub: [], + ) as List); + + @override + _i5.Future<_i2.File> writeAsBytes( + List? bytes, { + _i2.FileMode? mode = _i2.FileMode.write, + bool? flush = false, + }) => + (super.noSuchMethod( + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsBytes, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void writeAsBytesSync( + List? bytes, { + _i2.FileMode? mode = _i2.FileMode.write, + bool? flush = false, + }) => + super.noSuchMethod( + Invocation.method( + #writeAsBytesSync, + [bytes], + { + #mode: mode, + #flush: flush, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future<_i2.File> writeAsString( + String? contents, { + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + bool? flush = false, + }) => + (super.noSuchMethod( + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( + this, + Invocation.method( + #writeAsString, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + )), + ) as _i5.Future<_i2.File>); + + @override + void writeAsStringSync( + String? contents, { + _i2.FileMode? mode = _i2.FileMode.write, + _i6.Encoding? encoding = const _i6.Utf8Codec(), + bool? flush = false, + }) => + super.noSuchMethod( + Invocation.method( + #writeAsStringSync, + [contents], + { + #mode: mode, + #encoding: encoding, + #flush: flush, + }, + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Future exists() => (super.noSuchMethod( + Invocation.method( + #exists, + [], + ), + returnValue: _i5.Future.value(false), + returnValueForMissingStub: _i5.Future.value(false), + ) as _i5.Future); + + @override + bool existsSync() => (super.noSuchMethod( + Invocation.method( + #existsSync, + [], + ), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i5.Future resolveSymbolicLinks() => (super.noSuchMethod( + Invocation.method( + #resolveSymbolicLinks, + [], + ), + returnValue: _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinks, + [], + ), + )), + returnValueForMissingStub: + _i5.Future.value(_i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinks, + [], + ), + )), + ) as _i5.Future); + + @override + String resolveSymbolicLinksSync() => (super.noSuchMethod( + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + returnValue: _i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.method( + #resolveSymbolicLinksSync, + [], + ), + ), + ) as String); + + @override + _i5.Future<_i2.FileStat> stat() => (super.noSuchMethod( + Invocation.method( + #stat, + [], + ), + returnValue: _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( + this, + Invocation.method( + #stat, + [], + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( + this, + Invocation.method( + #stat, + [], + ), + )), + ) as _i5.Future<_i2.FileStat>); + + @override + _i2.FileStat statSync() => (super.noSuchMethod( + Invocation.method( + #statSync, + [], + ), + returnValue: _FakeFileStat_7( + this, + Invocation.method( + #statSync, + [], + ), + ), + returnValueForMissingStub: _FakeFileStat_7( + this, + Invocation.method( + #statSync, + [], + ), + ), + ) as _i2.FileStat); + + @override + _i5.Stream<_i2.FileSystemEvent> watch({ + int? events = 15, + bool? recursive = false, + }) => + (super.noSuchMethod( + Invocation.method( + #watch, + [], + { + #events: events, + #recursive: recursive, + }, + ), + returnValue: _i5.Stream<_i2.FileSystemEvent>.empty(), + returnValueForMissingStub: _i5.Stream<_i2.FileSystemEvent>.empty(), + ) as _i5.Stream<_i2.FileSystemEvent>); +} + +/// A class which mocks [DownloadManager]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { + @override + _i3.DownloadWorkerQueue get workingQueue => (super.noSuchMethod( + Invocation.getter(#workingQueue), + returnValue: _FakeDownloadWorkerQueue_8( + this, + Invocation.getter(#workingQueue), + ), + returnValueForMissingStub: _FakeDownloadWorkerQueue_8( + this, + Invocation.getter(#workingQueue), + ), + ) as _i3.DownloadWorkerQueue); + + @override + Map get eventIdMapDownloadFileInfo => + (super.noSuchMethod( + Invocation.getter(#eventIdMapDownloadFileInfo), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + + @override + void cancelDownload(String? eventId) => super.noSuchMethod( + Invocation.method( + #cancelDownload, + [eventId], + ), + returnValueForMissingStub: null, + ); + + @override + _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + String? eventId) => + (super.noSuchMethod( + Invocation.method( + #getDownloadStateStream, + [eventId], + ), + returnValueForMissingStub: null, + ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + + @override + _i5.Future clear(String? eventId) => (super.noSuchMethod( + Invocation.method( + #clear, + [eventId], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future download({ + required _i13.Event? event, + bool? getThumbnail = false, + bool? isFirstPriority = false, + }) => + (super.noSuchMethod( + Invocation.method( + #download, + [], + { + #event: event, + #getThumbnail: getThumbnail, + #isFirstPriority: isFirstPriority, + }, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); +} From 5c2b933a8ebd9cf09aba4583507ea5eb0760943f Mon Sep 17 00:00:00 2001 From: Terence ZAFINDRATAFA Date: Tue, 28 May 2024 20:14:50 +0200 Subject: [PATCH 03/11] TW-1702: update room operator override to fit nullsafety requirements --- .../download_file_on_mobile_mixin_test.dart | 53 +++++++++++++------ .../download_file_on_web_mixin_test.dart | 30 +++++++---- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.dart b/test/mixin/download/download_file_on_mobile_mixin_test.dart index 11afc9ba40..cf46956317 100644 --- a/test/mixin/download/download_file_on_mobile_mixin_test.dart +++ b/test/mixin/download/download_file_on_mobile_mixin_test.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartz/dartz.dart' hide State, OpenFile; +import 'package:dartz/dartz.dart' hide State, OpenFile, id; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; import 'package:fluffychat/utils/exception/downloading_exception.dart'; @@ -19,12 +19,10 @@ const fakeFilename = "fakeFilename"; class MockRoom extends Mock implements Room { @override - // ignore: hash_and_equals - bool operator ==(dynamic other) { - if (identical(this, other)) return true; - // ignore: unrelated_type_equality_checks - return other is Room && other.id == id; - } + bool operator ==(dynamic other) => (other is Room && other.id == id); + + @override + int get hashCode => Object.hashAll([id]); @override Map get sendingFilePlaceholders => super.noSuchMethod( @@ -81,7 +79,7 @@ class DummyWidgetState extends State MockSpec(), ]) void main() { - group('DownloadFileOnMobileMixin: setupDownloadingProcess', () { + group('DownloadFileOnMobileMixin: setupDownloadingProcess - ENV: WEB', () { late DummyWidgetState dummyState; late Event fakeEvent; late Room fakeRoom; @@ -97,7 +95,10 @@ void main() { getIt.reset(); }); - test('should handle failure', () { + test( + 'WHEN the download fails because of an Exception \n' + 'THEN downloadFileStateNotifier value should be DownloadErrorPresentationState \n', + () { final failure = DownloadFileFailureState(exception: Exception()); dummyState.setupDownloadingProcess(Left(failure)); @@ -107,7 +108,10 @@ void main() { ); }); - test('should handle cancel', () { + test( + 'WHEN the user cancel the download \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', + () { final failure = DownloadFileFailureState(exception: CancelDownloadingException()); dummyState.setupDownloadingProcess(Left(failure)); @@ -118,7 +122,10 @@ void main() { ); }); - test('should handle success with DownloadingFileState', () { + test( + 'WHEN download is in progress \n' + 'THEN downloadFileStateNotifier value should be DownloadingPresentationState \n', + () { const success = DownloadingFileState(receive: 10, total: 100); dummyState.setupDownloadingProcess(const Right(success)); @@ -128,7 +135,10 @@ void main() { ); }); - test('should handle success with DownloadNativeFileSuccessState', () { + test( + 'WHEN download is successful \n' + 'THEN downloadFileStateNotifier value should be DownloadedPresentationState \n', + () { const success = DownloadNativeFileSuccessState(filePath: 'path/to/file'); dummyState.setupDownloadingProcess(const Right(success)); @@ -148,7 +158,9 @@ void main() { getIt.reset(); }); - test('should update downloadFileStateNotifier if file exists in memory', + test( + 'WHEN file already exists \n' + 'THEN downloadFileStateNotifier value should be DownloadedPresentationState \n', () { final fakeRoom = MockRoom(); final fakeEvent = MockEvent(fakeRoom); @@ -169,7 +181,8 @@ void main() { }); test( - 'should not update downloadFileStateNotifier if file does not exist in memory', + 'WHEN file do not exists \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', () { final fakeRoom = MockRoom(); final fakeEvent = MockEvent(fakeRoom); @@ -193,7 +206,9 @@ void main() { }); test( - 'should update downloadFileStateNotifier if file exists in app downloads', + 'WHEN file already exists \n' + 'AND file size is the same as the event size \n' + 'THEN downloadFileStateNotifier value should be DownloadedPresentationState \n', () async { final fakeRoom = MockRoom(); final fakeEvent = MockEvent(fakeRoom); @@ -213,7 +228,9 @@ void main() { ); }); - test('should not update downloadFileStateNotifier if file does not exists', + test( + 'WHEN file does not exists \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', () async { final fakeRoom = MockRoom(); final fakeEvent = MockEvent(fakeRoom); @@ -234,7 +251,9 @@ void main() { }); test( - 'should not update downloadFileStateNotifier if file does have the same size as the event', + 'WHEN file already exists \n' + 'BUT file size is the not same as the event size \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', () async { final fakeRoom = MockRoom(); final fakeEvent = MockEvent(fakeRoom); diff --git a/test/mixin/download/download_file_on_web_mixin_test.dart b/test/mixin/download/download_file_on_web_mixin_test.dart index ecc21f8e16..9908edcf34 100644 --- a/test/mixin/download/download_file_on_web_mixin_test.dart +++ b/test/mixin/download/download_file_on_web_mixin_test.dart @@ -19,12 +19,10 @@ const fakeFilename = "fakeFilename"; class MockRoom extends Mock implements Room { @override - // ignore: hash_and_equals - bool operator ==(dynamic other) { - if (identical(this, other)) return true; - // ignore: unrelated_type_equality_checks - return other is Room && other.id == id; - } + bool operator ==(dynamic other) => (other is Room && other.id == id); + + @override + int get hashCode => Object.hashAll([id]); @override Map get sendingFilePlaceholders => super.noSuchMethod( @@ -101,7 +99,10 @@ void main() { getIt.reset(); }); - test('should handle failure', () { + test( + 'WHEN the download fails because of an Exception \n' + 'THEN downloadFileStateNotifier value should be DownloadErrorPresentationState \n', + () { final failure = DownloadFileFailureState(exception: Exception()); dummyState.setupDownloadingProcess(Left(failure)); @@ -111,7 +112,10 @@ void main() { ); }); - test('should handle cancel', () { + test( + 'WHEN the user cancel the download \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', + () { final failure = DownloadFileFailureState( exception: CancelDownloadingException(), ); @@ -123,7 +127,10 @@ void main() { ); }); - test('should handle success with DownloadingFileState', () { + test( + 'WHEN download is in progress \n' + 'THEN downloadFileStateNotifier value should be DownloadingPresentationState \n', + () { const success = DownloadingFileState(receive: 10, total: 100); dummyState.setupDownloadingProcess(const Right(success)); @@ -133,7 +140,10 @@ void main() { ); }); - test('should handle success with DownloadMatrixFileSuccessState', () { + test( + 'WHEN download is successful \n' + 'THEN downloadFileStateNotifier value should be NotDownloadPresentationState \n', + () { TestWidgetsFlutterBinding.ensureInitialized(); final success = DownloadMatrixFileSuccessState( From bd5d3d51e347de7c70034cb50a35a4558d920940 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Tue, 28 May 2024 20:25:17 +0200 Subject: [PATCH 04/11] fixup! TW-1702: update room operator override to fit nullsafety requirements --- pubspec.yaml | 2 +- test/mixin/download/download_file_on_mobile_mixin_test.dart | 2 +- test/mixin/download/download_file_on_web_mixin_test.dart | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0af0e24111..f4757ac28f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: matrix: git: url: git@github.com:linagora/matrix-dart-sdk.git - ref: twake-supported-0.22.6 + ref: TW-1702/hotfix_download_error_handling receive_sharing_intent: git: diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.dart b/test/mixin/download/download_file_on_mobile_mixin_test.dart index cf46956317..6ce55c9237 100644 --- a/test/mixin/download/download_file_on_mobile_mixin_test.dart +++ b/test/mixin/download/download_file_on_mobile_mixin_test.dart @@ -19,7 +19,7 @@ const fakeFilename = "fakeFilename"; class MockRoom extends Mock implements Room { @override - bool operator ==(dynamic other) => (other is Room && other.id == id); + bool operator ==(Object other) => (other is Room && other.id == id); @override int get hashCode => Object.hashAll([id]); diff --git a/test/mixin/download/download_file_on_web_mixin_test.dart b/test/mixin/download/download_file_on_web_mixin_test.dart index 9908edcf34..235c419f83 100644 --- a/test/mixin/download/download_file_on_web_mixin_test.dart +++ b/test/mixin/download/download_file_on_web_mixin_test.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:dartz/dartz.dart' hide State, OpenFile; +import 'package:dartz/dartz.dart' hide State, OpenFile, id; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/presentation/model/chat/downloading_state_presentation_model.dart'; import 'package:fluffychat/utils/exception/downloading_exception.dart'; @@ -19,7 +19,7 @@ const fakeFilename = "fakeFilename"; class MockRoom extends Mock implements Room { @override - bool operator ==(dynamic other) => (other is Room && other.id == id); + bool operator ==(Object other) => (other is Room && other.id == id); @override int get hashCode => Object.hashAll([id]); From 35a7d1b2f21acf6a7454d74bbc19becfdf68ea35 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 08:28:04 +0200 Subject: [PATCH 05/11] fixup! fixup! TW-1702: update room operator override to fit nullsafety requirements --- .../download_manager/download_manager.dart | 24 +++++++++---------- .../manager/storage_directory_manager.dart | 2 -- .../mixins/download_file_on_mobile_mixin.dart | 4 +--- ...nload_file_on_mobile_mixin_test.mocks.dart | 24 ++++++------------- ...download_file_on_web_mixin_test.mocks.dart | 24 ++++++------------- 5 files changed, 27 insertions(+), 51 deletions(-) diff --git a/lib/utils/manager/download_manager/download_manager.dart b/lib/utils/manager/download_manager/download_manager.dart index 4f828da0b0..a283163d0a 100644 --- a/lib/utils/manager/download_manager/download_manager.dart +++ b/lib/utils/manager/download_manager/download_manager.dart @@ -26,14 +26,14 @@ class DownloadManager { final workingQueue = getIt.get(); - final Map eventIdMapDownloadFileInfo = {}; + final Map _eventIdMapDownloadFileInfo = {}; void cancelDownload(String eventId) { - final cancelToken = eventIdMapDownloadFileInfo[eventId]?.cancelToken; + final cancelToken = _eventIdMapDownloadFileInfo[eventId]?.cancelToken; if (cancelToken != null) { try { cancelToken.cancel(); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState( exception: CancelDownloadingException(), @@ -44,7 +44,7 @@ class DownloadManager { Logs().e( 'DownloadManager::cancelDownload(): $e', ); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), @@ -60,7 +60,7 @@ class DownloadManager { ) { final streamController = StreamController>(); - eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( + _eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( eventId: event.eventId, cancelToken: CancelToken(), downloadStateStreamController: streamController, @@ -69,25 +69,25 @@ class DownloadManager { } Stream>? getDownloadStateStream(String eventId) { - return eventIdMapDownloadFileInfo[eventId]?.downloadStream; + return _eventIdMapDownloadFileInfo[eventId]?.downloadStream; } Future clear(String eventId) async { try { - await eventIdMapDownloadFileInfo[eventId] + await _eventIdMapDownloadFileInfo[eventId] ?.downloadStateStreamController .close(); } catch (e) { Logs().e( 'DownloadManager::_clear(): $e', ); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), ); } finally { - eventIdMapDownloadFileInfo.remove(eventId); + _eventIdMapDownloadFileInfo.remove(eventId); Logs().i( 'DownloadManager::clear with $eventId successfully', ); @@ -100,14 +100,14 @@ class DownloadManager { bool isFirstPriority = false, }) async { _initDownloadFileInfo(event); - final streamController = eventIdMapDownloadFileInfo[event.eventId] + final streamController = _eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController; - final cancelToken = eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; + final cancelToken = _eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; if (streamController == null || cancelToken == null) { Logs().e( 'DownloadManager::download(): streamController or cancelToken is null', ); - eventIdMapDownloadFileInfo[event.eventId] + _eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController .add( Left( diff --git a/lib/utils/manager/storage_directory_manager.dart b/lib/utils/manager/storage_directory_manager.dart index 2eefedb940..d6d30fe836 100644 --- a/lib/utils/manager/storage_directory_manager.dart +++ b/lib/utils/manager/storage_directory_manager.dart @@ -13,8 +13,6 @@ class StorageDirectoryManager { static StorageDirectoryManager get instance => _instance; - factory StorageDirectoryManager() => _instance; - Future getFileStoreDirectory() async { try { try { diff --git a/lib/widgets/mixins/download_file_on_mobile_mixin.dart b/lib/widgets/mixins/download_file_on_mobile_mixin.dart index 11a1db8228..2f6db249b7 100644 --- a/lib/widgets/mixins/download_file_on_mobile_mixin.dart +++ b/lib/widgets/mixins/download_file_on_mobile_mixin.dart @@ -18,8 +18,6 @@ import 'package:matrix/matrix.dart'; mixin DownloadFileOnMobileMixin on State { final downloadManager = getIt.get(); - final storageDirectoryManager = StorageDirectoryManager(); - final downloadFileStateNotifier = ValueNotifier( const NotDownloadPresentationState(), ); @@ -69,7 +67,7 @@ mixin DownloadFileOnMobileMixin on State { } Future checkFileInDownloadsInApp() async { - final filePath = await storageDirectoryManager.getFilePathInAppDownloads( + final filePath = await StorageDirectoryManager.instance.getFilePathInAppDownloads( eventId: event.eventId, fileName: event.filename, ); diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart index 8db9968b6c..921c812633 100644 --- a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart +++ b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart @@ -8,16 +8,14 @@ import 'dart:convert' as _i6; import 'dart:io' as _i2; import 'dart:typed_data' as _i7; -import 'package:dartz/dartz.dart' as _i10; -import 'package:fluffychat/app_state/failure.dart' as _i11; -import 'package:fluffychat/app_state/success.dart' as _i12; -import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' - as _i9; +import 'package:dartz/dartz.dart' as _i9; +import 'package:fluffychat/app_state/failure.dart' as _i10; +import 'package:fluffychat/app_state/success.dart' as _i11; import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' as _i8; import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' as _i3; -import 'package:matrix/matrix.dart' as _i13; +import 'package:matrix/matrix.dart' as _i12; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i4; @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ), ) as _i3.DownloadWorkerQueue); - @override - Map get eventIdMapDownloadFileInfo => - (super.noSuchMethod( - Invocation.getter(#eventIdMapDownloadFileInfo), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - @override void cancelDownload(String? eventId) => super.noSuchMethod( Invocation.method( @@ -1012,7 +1002,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ); @override - _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( String? eventId) => (super.noSuchMethod( Invocation.method( @@ -1020,7 +1010,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { [eventId], ), returnValueForMissingStub: null, - ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); @override _i5.Future clear(String? eventId) => (super.noSuchMethod( @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { @override _i5.Future download({ - required _i13.Event? event, + required _i12.Event? event, bool? getThumbnail = false, bool? isFirstPriority = false, }) => diff --git a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart index dfaf094139..3f00dd45f7 100644 --- a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart +++ b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart @@ -8,16 +8,14 @@ import 'dart:convert' as _i6; import 'dart:io' as _i2; import 'dart:typed_data' as _i7; -import 'package:dartz/dartz.dart' as _i10; -import 'package:fluffychat/app_state/failure.dart' as _i11; -import 'package:fluffychat/app_state/success.dart' as _i12; -import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' - as _i9; +import 'package:dartz/dartz.dart' as _i9; +import 'package:fluffychat/app_state/failure.dart' as _i10; +import 'package:fluffychat/app_state/success.dart' as _i11; import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' as _i8; import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' as _i3; -import 'package:matrix/matrix.dart' as _i13; +import 'package:matrix/matrix.dart' as _i12; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i4; @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ), ) as _i3.DownloadWorkerQueue); - @override - Map get eventIdMapDownloadFileInfo => - (super.noSuchMethod( - Invocation.getter(#eventIdMapDownloadFileInfo), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - @override void cancelDownload(String? eventId) => super.noSuchMethod( Invocation.method( @@ -1012,7 +1002,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ); @override - _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( String? eventId) => (super.noSuchMethod( Invocation.method( @@ -1020,7 +1010,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { [eventId], ), returnValueForMissingStub: null, - ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); @override _i5.Future clear(String? eventId) => (super.noSuchMethod( @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { @override _i5.Future download({ - required _i13.Event? event, + required _i12.Event? event, bool? getThumbnail = false, bool? isFirstPriority = false, }) => From cf4d7c7c3a3039600dfca129f4a1e3e3431503d7 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 09:09:05 +0200 Subject: [PATCH 06/11] fixup! fixup! fixup! TW-1702: update room operator override to fit nullsafety requirements --- lib/widgets/mixins/download_file_on_mobile_mixin.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/widgets/mixins/download_file_on_mobile_mixin.dart b/lib/widgets/mixins/download_file_on_mobile_mixin.dart index 2f6db249b7..31e2d12579 100644 --- a/lib/widgets/mixins/download_file_on_mobile_mixin.dart +++ b/lib/widgets/mixins/download_file_on_mobile_mixin.dart @@ -67,7 +67,8 @@ mixin DownloadFileOnMobileMixin on State { } Future checkFileInDownloadsInApp() async { - final filePath = await StorageDirectoryManager.instance.getFilePathInAppDownloads( + final filePath = + await StorageDirectoryManager.instance.getFilePathInAppDownloads( eventId: event.eventId, fileName: event.filename, ); From 978dfc08a5935d3c4ee66bb766da8a9846b7bdc9 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 21:41:49 +0200 Subject: [PATCH 07/11] TW-1702/shared_mocks.dart added --- .../download_file_on_mobile_mixin_test.dart | 39 +------ .../download_file_on_web_mixin_test.dart | 37 +----- .../message_content_builder_mixin_test.dart | 82 ++----------- test/utils/shared_mocks.dart | 108 ++++++++++++++++++ 4 files changed, 122 insertions(+), 144 deletions(-) create mode 100644 test/utils/shared_mocks.dart diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.dart b/test/mixin/download/download_file_on_mobile_mixin_test.dart index 6ce55c9237..7cdd95386f 100644 --- a/test/mixin/download/download_file_on_mobile_mixin_test.dart +++ b/test/mixin/download/download_file_on_mobile_mixin_test.dart @@ -12,42 +12,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:matrix/matrix.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'download_file_on_mobile_mixin_test.mocks.dart'; - -const fakeEventId = "fakeEventId"; -const fakeFilename = "fakeFilename"; - -class MockRoom extends Mock implements Room { - @override - bool operator ==(Object other) => (other is Room && other.id == id); - - @override - int get hashCode => Object.hashAll([id]); - - @override - Map get sendingFilePlaceholders => super.noSuchMethod( - Invocation.getter(#sendingFilePlaceholders), - returnValue: {}, - returnValueForMissingStub: {}, - ); -} - -class MockEvent extends Mock implements Event { - MockEvent(this.fakeRoom); - final Room fakeRoom; - @override - String get eventId => fakeEventId; - - @override - Room get room => fakeRoom; - @override - Map get infoMap => super.noSuchMethod( - Invocation.getter(#infoMap), - returnValue: {}, - returnValueForMissingStub: {}, - ); -} +import 'download_file_on_mobile_mixin_test.mocks.dart'; +import '../../utils/shared_mocks.dart'; class DummyWidget extends StatefulWidget { const DummyWidget({required this.event, super.key}); @@ -167,7 +134,7 @@ void main() { final dummyState = DummyWidgetState(fakeEvent); when(fakeRoom.sendingFilePlaceholders).thenReturn({ - fakeEventId: MatrixFile( + MockEvent.fakeEventId: MatrixFile( name: fakeFilename, filePath: "path/to/file", ), diff --git a/test/mixin/download/download_file_on_web_mixin_test.dart b/test/mixin/download/download_file_on_web_mixin_test.dart index 235c419f83..7c79ee880b 100644 --- a/test/mixin/download/download_file_on_web_mixin_test.dart +++ b/test/mixin/download/download_file_on_web_mixin_test.dart @@ -11,44 +11,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:matrix/matrix.dart'; import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; +import '../../utils/shared_mocks.dart'; import 'download_file_on_web_mixin_test.mocks.dart'; -const fakeEventId = "fakeEventId"; -const fakeFilename = "fakeFilename"; - -class MockRoom extends Mock implements Room { - @override - bool operator ==(Object other) => (other is Room && other.id == id); - - @override - int get hashCode => Object.hashAll([id]); - - @override - Map get sendingFilePlaceholders => super.noSuchMethod( - Invocation.getter(#sendingFilePlaceholders), - returnValue: {}, - returnValueForMissingStub: {}, - ); -} - -class MockEvent extends Mock implements Event { - MockEvent(this.fakeRoom); - final Room fakeRoom; - @override - String get eventId => fakeEventId; - - @override - Room get room => fakeRoom; - - @override - Map get infoMap => super.noSuchMethod( - Invocation.getter(#infoMap), - returnValue: {}, - returnValueForMissingStub: {}, - ); -} - class DummyWidget extends StatefulWidget { const DummyWidget({required this.event, super.key}); diff --git a/test/pages/chat/events/message/message_content_builder_mixin_test.dart b/test/pages/chat/events/message/message_content_builder_mixin_test.dart index adc2fdcf03..6fc3106fd1 100644 --- a/test/pages/chat/events/message/message_content_builder_mixin_test.dart +++ b/test/pages/chat/events/message/message_content_builder_mixin_test.dart @@ -16,6 +16,8 @@ import 'package:matrix/matrix.dart'; import 'package:matrix_api_lite/fake_matrix_api.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import '../../../../utils/shared_mocks.dart'; + class MockUpMessageContentBuilder with MessageContentBuilderMixin {} void main() { @@ -29,70 +31,6 @@ void main() { final client = Client('client', httpClient: FakeMatrixApi()); final room = Room(id: '!room:example.abc', client: client); - final fileEvent = Event( - content: { - 'body': 'something-important.doc', - 'filename': 'something-important.doc', - 'info': {'mimetype': 'application/msword', 'size': 46144}, - 'msgtype': 'm.file', - 'url': 'mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe', - }, - type: 'm.room.message', - eventId: '\$143273582443PhrSn:example.org', - senderId: '@example:example.org', - originServerTs: DateTime.fromMillisecondsSinceEpoch(1894270481925), - room: room, - ); - final imageEvent = Event( - content: { - 'body': 'filename.jpg', - 'info': {'h': 398, 'mimetype': 'image/jpeg', 'size': 31037, 'w': 394}, - 'msgtype': 'm.image', - 'url': 'mxc://example.org/JWEIFJgwEIhweiWJE', - }, - type: 'm.room.message', - eventId: '\$143273582443PhrSn:example.org', - senderId: '@example:example.org', - originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), - room: room, - ); - final videoEvent = Event( - content: { - 'body': 'Gangnam Style', - 'info': { - 'duration': 2140786, - 'h': 320, - 'mimetype': 'video/mp4', - 'size': 1563685, - 'thumbnail_info': { - 'h': 300, - 'mimetype': 'image/jpeg', - 'size': 46144, - 'w': 300, - }, - 'thumbnail_url': 'mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe', - 'w': 480, - }, - 'msgtype': 'm.video', - 'url': 'mxc://example.org/a526eYUSFFxlgbQYZmo442', - }, - type: 'm.room.message', - eventId: '\$143273582443PhrSn:example.org', - senderId: '@example:example.org', - originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), - room: room, - ); - final emptyTextEvent = Event( - content: { - 'body': '', - 'msgtype': 'm.text', - }, - type: 'm.room.message', - eventId: '\$143273582443PhrSn:example.org', - senderId: '@example:example.org', - originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), - room: room, - ); group( '[MessageContentBuilderMixin] TEST\n', @@ -184,7 +122,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: fileEvent, + event: EventGenerator.fileEvent(room), maxWidth: messageMaxWidthWeb, ); }, @@ -195,7 +133,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: imageEvent, + event: EventGenerator.imageEvent(room), maxWidth: messageMaxWidthWeb, ); }, @@ -206,7 +144,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: videoEvent, + event: EventGenerator.videoEvent(room), maxWidth: messageMaxWidthWeb, ); }, @@ -219,7 +157,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: emptyTextEvent, + event: EventGenerator.emptyTextEvent(room), maxWidth: messageMaxWidthWeb, ); }, @@ -439,7 +377,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: fileEvent, + event: EventGenerator.fileEvent(room), maxWidth: messageMaxWidthMobile, ); }, @@ -450,7 +388,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: imageEvent, + event: EventGenerator.imageEvent(room), maxWidth: messageMaxWidthMobile, ); }, @@ -461,7 +399,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: videoEvent, + event: EventGenerator.videoEvent(room), maxWidth: messageMaxWidthMobile, ); }, @@ -474,7 +412,7 @@ void main() { (WidgetTester tester) async { await runTest( tester, - event: emptyTextEvent, + event: EventGenerator.emptyTextEvent(room), maxWidth: messageMaxWidthMobile, ); }, diff --git a/test/utils/shared_mocks.dart b/test/utils/shared_mocks.dart new file mode 100644 index 0000000000..5c3a09b6a1 --- /dev/null +++ b/test/utils/shared_mocks.dart @@ -0,0 +1,108 @@ +import 'package:matrix/matrix.dart'; +import 'package:mockito/mockito.dart'; + +const fakeFilename = "fakeFilename"; + +class MockRoom extends Mock implements Room { + @override + bool operator ==(Object other) => (other is Room && other.id == id); + + @override + int get hashCode => Object.hashAll([id]); + + @override + Map get sendingFilePlaceholders => super.noSuchMethod( + Invocation.getter(#sendingFilePlaceholders), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class MockEvent extends Mock implements Event { + MockEvent(this.fakeRoom); + final Room fakeRoom; + static const fakeEventId = "fakeEventId"; + + @override + String get eventId => fakeEventId; + + @override + Room get room => fakeRoom; + + @override + Map get infoMap => super.noSuchMethod( + Invocation.getter(#infoMap), + returnValue: {}, + returnValueForMissingStub: {}, + ); +} + +class EventGenerator { + static Event fileEvent(Room room) => Event( + content: { + 'body': 'something-important.doc', + 'filename': 'something-important.doc', + 'info': {'mimetype': 'application/msword', 'size': 46144}, + 'msgtype': 'm.file', + 'url': 'mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe', + }, + type: 'm.room.message', + eventId: '\$143273582443PhrSn:example.org', + senderId: '@example:example.org', + originServerTs: DateTime.fromMillisecondsSinceEpoch(1894270481925), + room: room, + ); + + static Event imageEvent(Room room) => Event( + content: { + 'body': 'filename.jpg', + 'info': {'h': 398, 'mimetype': 'image/jpeg', 'size': 31037, 'w': 394}, + 'msgtype': 'm.image', + 'url': 'mxc://example.org/JWEIFJgwEIhweiWJE', + }, + type: 'm.room.message', + eventId: '\$143273582443PhrSn:example.org', + senderId: '@example:example.org', + originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), + room: room, + ); + + static Event videoEvent(Room room) => Event( + content: { + 'body': 'Gangnam Style', + 'info': { + 'duration': 2140786, + 'h': 320, + 'mimetype': 'video/mp4', + 'size': 1563685, + 'thumbnail_info': { + 'h': 300, + 'mimetype': 'image/jpeg', + 'size': 46144, + 'w': 300, + }, + 'thumbnail_url': 'mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe', + 'w': 480, + }, + 'msgtype': 'm.video', + 'url': 'mxc://example.org/a526eYUSFFxlgbQYZmo442', + }, + type: 'm.room.message', + eventId: '\$143273582443PhrSn:example.org', + senderId: '@example:example.org', + originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), + room: room, + ); + + static Event emptyTextEvent(Room room) => Event( + content: { + 'body': '', + 'msgtype': 'm.text', + }, + type: 'm.room.message', + eventId: '\$143273582443PhrSn:example.org', + senderId: '@example:example.org', + originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), + room: room, + ); +} From 1ba54b6c47264ad15c6dbc044eb6275a342592a0 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 21:43:02 +0200 Subject: [PATCH 08/11] fixup! TW-1702/shared_mocks.dart added --- .gitignore | 1 + ...nload_file_on_mobile_mixin_test.mocks.dart | 1044 ----------------- ...download_file_on_web_mixin_test.mocks.dart | 1044 ----------------- 3 files changed, 1 insertion(+), 2088 deletions(-) delete mode 100644 test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart delete mode 100644 test/mixin/download/download_file_on_web_mixin_test.mocks.dart diff --git a/.gitignore b/.gitignore index b21c33414b..2deeb54f7b 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ prime .pub-cache/ .pub/ /build/ +**/*.mocks.dart # Web related docs/build/ diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart deleted file mode 100644 index 921c812633..0000000000 --- a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart +++ /dev/null @@ -1,1044 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in fluffychat/test/mixin/download/download_file_on_mobile_mixin_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; -import 'dart:convert' as _i6; -import 'dart:io' as _i2; -import 'dart:typed_data' as _i7; - -import 'package:dartz/dartz.dart' as _i9; -import 'package:fluffychat/app_state/failure.dart' as _i10; -import 'package:fluffychat/app_state/success.dart' as _i11; -import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' - as _i8; -import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' - as _i3; -import 'package:matrix/matrix.dart' as _i12; -import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i4; - -// 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 - -class _FakeFile_0 extends _i1.SmartFake implements _i2.File { - _FakeFile_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeUri_1 extends _i1.SmartFake implements Uri { - _FakeUri_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDirectory_2 extends _i1.SmartFake implements _i2.Directory { - _FakeDirectory_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeFileSystemEntity_3 extends _i1.SmartFake - implements _i2.FileSystemEntity { - _FakeFileSystemEntity_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDateTime_4 extends _i1.SmartFake implements DateTime { - _FakeDateTime_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeRandomAccessFile_5 extends _i1.SmartFake - implements _i2.RandomAccessFile { - _FakeRandomAccessFile_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeIOSink_6 extends _i1.SmartFake implements _i2.IOSink { - _FakeIOSink_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeFileStat_7 extends _i1.SmartFake implements _i2.FileStat { - _FakeFileStat_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDownloadWorkerQueue_8 extends _i1.SmartFake - implements _i3.DownloadWorkerQueue { - _FakeDownloadWorkerQueue_8( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [File]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockFile extends _i1.Mock implements _i2.File { - @override - _i2.File get absolute => (super.noSuchMethod( - Invocation.getter(#absolute), - returnValue: _FakeFile_0( - this, - Invocation.getter(#absolute), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.getter(#absolute), - ), - ) as _i2.File); - - @override - String get path => (super.noSuchMethod( - Invocation.getter(#path), - returnValue: _i4.dummyValue( - this, - Invocation.getter(#path), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.getter(#path), - ), - ) as String); - - @override - Uri get uri => (super.noSuchMethod( - Invocation.getter(#uri), - returnValue: _FakeUri_1( - this, - Invocation.getter(#uri), - ), - returnValueForMissingStub: _FakeUri_1( - this, - Invocation.getter(#uri), - ), - ) as Uri); - - @override - bool get isAbsolute => (super.noSuchMethod( - Invocation.getter(#isAbsolute), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i2.Directory get parent => (super.noSuchMethod( - Invocation.getter(#parent), - returnValue: _FakeDirectory_2( - this, - Invocation.getter(#parent), - ), - returnValueForMissingStub: _FakeDirectory_2( - this, - Invocation.getter(#parent), - ), - ) as _i2.Directory); - - @override - _i5.Future<_i2.File> create({ - bool? recursive = false, - bool? exclusive = false, - }) => - (super.noSuchMethod( - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void createSync({ - bool? recursive = false, - bool? exclusive = false, - }) => - super.noSuchMethod( - Invocation.method( - #createSync, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> rename(String? newPath) => (super.noSuchMethod( - Invocation.method( - #rename, - [newPath], - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - ) as _i5.Future<_i2.File>); - - @override - _i2.File renameSync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #renameSync, - [newPath], - ), - returnValue: _FakeFile_0( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - ) as _i2.File); - - @override - _i5.Future<_i2.FileSystemEntity> delete({bool? recursive = false}) => - (super.noSuchMethod( - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - returnValue: - _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - ) as _i5.Future<_i2.FileSystemEntity>); - - @override - void deleteSync({bool? recursive = false}) => super.noSuchMethod( - Invocation.method( - #deleteSync, - [], - {#recursive: recursive}, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> copy(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copy, - [newPath], - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - ) as _i5.Future<_i2.File>); - - @override - _i2.File copySync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copySync, - [newPath], - ), - returnValue: _FakeFile_0( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - ) as _i2.File); - - @override - _i5.Future length() => (super.noSuchMethod( - Invocation.method( - #length, - [], - ), - returnValue: _i5.Future.value(0), - returnValueForMissingStub: _i5.Future.value(0), - ) as _i5.Future); - - @override - int lengthSync() => (super.noSuchMethod( - Invocation.method( - #lengthSync, - [], - ), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - - @override - _i5.Future lastAccessed() => (super.noSuchMethod( - Invocation.method( - #lastAccessed, - [], - ), - returnValue: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - ) as _i5.Future); - - @override - DateTime lastAccessedSync() => (super.noSuchMethod( - Invocation.method( - #lastAccessedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - ) as DateTime); - - @override - _i5.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastAccessed, - [time], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - void setLastAccessedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastAccessedSync, - [time], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future lastModified() => (super.noSuchMethod( - Invocation.method( - #lastModified, - [], - ), - returnValue: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - ) as _i5.Future); - - @override - DateTime lastModifiedSync() => (super.noSuchMethod( - Invocation.method( - #lastModifiedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - ) as DateTime); - - @override - _i5.Future setLastModified(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastModified, - [time], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - void setLastModifiedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastModifiedSync, - [time], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.RandomAccessFile> open( - {_i2.FileMode? mode = _i2.FileMode.read}) => - (super.noSuchMethod( - Invocation.method( - #open, - [], - {#mode: mode}, - ), - returnValue: - _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - ) as _i5.Future<_i2.RandomAccessFile>); - - @override - _i2.RandomAccessFile openSync({_i2.FileMode? mode = _i2.FileMode.read}) => - (super.noSuchMethod( - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - returnValue: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - returnValueForMissingStub: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - ) as _i2.RandomAccessFile); - - @override - _i5.Stream> openRead([ - int? start, - int? end, - ]) => - (super.noSuchMethod( - Invocation.method( - #openRead, - [ - start, - end, - ], - ), - returnValue: _i5.Stream>.empty(), - returnValueForMissingStub: _i5.Stream>.empty(), - ) as _i5.Stream>); - - @override - _i2.IOSink openWrite({ - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - }) => - (super.noSuchMethod( - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - returnValue: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - ), - returnValueForMissingStub: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - ), - ) as _i2.IOSink); - - @override - _i5.Future<_i7.Uint8List> readAsBytes() => (super.noSuchMethod( - Invocation.method( - #readAsBytes, - [], - ), - returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - returnValueForMissingStub: - _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - ) as _i5.Future<_i7.Uint8List>); - - @override - _i7.Uint8List readAsBytesSync() => (super.noSuchMethod( - Invocation.method( - #readAsBytesSync, - [], - ), - returnValue: _i7.Uint8List(0), - returnValueForMissingStub: _i7.Uint8List(0), - ) as _i7.Uint8List); - - @override - _i5.Future readAsString( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - returnValue: _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - )), - returnValueForMissingStub: - _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - )), - ) as _i5.Future); - - @override - String readAsStringSync({_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - returnValue: _i4.dummyValue( - this, - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - ), - ) as String); - - @override - _i5.Future> readAsLines( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLines, - [], - {#encoding: encoding}, - ), - returnValue: _i5.Future>.value([]), - returnValueForMissingStub: _i5.Future>.value([]), - ) as _i5.Future>); - - @override - List readAsLinesSync( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLinesSync, - [], - {#encoding: encoding}, - ), - returnValue: [], - returnValueForMissingStub: [], - ) as List); - - @override - _i5.Future<_i2.File> writeAsBytes( - List? bytes, { - _i2.FileMode? mode = _i2.FileMode.write, - bool? flush = false, - }) => - (super.noSuchMethod( - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void writeAsBytesSync( - List? bytes, { - _i2.FileMode? mode = _i2.FileMode.write, - bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsBytesSync, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> writeAsString( - String? contents, { - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - bool? flush = false, - }) => - (super.noSuchMethod( - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void writeAsStringSync( - String? contents, { - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsStringSync, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future exists() => (super.noSuchMethod( - Invocation.method( - #exists, - [], - ), - returnValue: _i5.Future.value(false), - returnValueForMissingStub: _i5.Future.value(false), - ) as _i5.Future); - - @override - bool existsSync() => (super.noSuchMethod( - Invocation.method( - #existsSync, - [], - ), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i5.Future resolveSymbolicLinks() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinks, - [], - ), - returnValue: _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinks, - [], - ), - )), - returnValueForMissingStub: - _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinks, - [], - ), - )), - ) as _i5.Future); - - @override - String resolveSymbolicLinksSync() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - returnValue: _i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - ), - ) as String); - - @override - _i5.Future<_i2.FileStat> stat() => (super.noSuchMethod( - Invocation.method( - #stat, - [], - ), - returnValue: _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - ) as _i5.Future<_i2.FileStat>); - - @override - _i2.FileStat statSync() => (super.noSuchMethod( - Invocation.method( - #statSync, - [], - ), - returnValue: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - returnValueForMissingStub: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - ) as _i2.FileStat); - - @override - _i5.Stream<_i2.FileSystemEvent> watch({ - int? events = 15, - bool? recursive = false, - }) => - (super.noSuchMethod( - Invocation.method( - #watch, - [], - { - #events: events, - #recursive: recursive, - }, - ), - returnValue: _i5.Stream<_i2.FileSystemEvent>.empty(), - returnValueForMissingStub: _i5.Stream<_i2.FileSystemEvent>.empty(), - ) as _i5.Stream<_i2.FileSystemEvent>); -} - -/// A class which mocks [DownloadManager]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { - @override - _i3.DownloadWorkerQueue get workingQueue => (super.noSuchMethod( - Invocation.getter(#workingQueue), - returnValue: _FakeDownloadWorkerQueue_8( - this, - Invocation.getter(#workingQueue), - ), - returnValueForMissingStub: _FakeDownloadWorkerQueue_8( - this, - Invocation.getter(#workingQueue), - ), - ) as _i3.DownloadWorkerQueue); - - @override - void cancelDownload(String? eventId) => super.noSuchMethod( - Invocation.method( - #cancelDownload, - [eventId], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( - String? eventId) => - (super.noSuchMethod( - Invocation.method( - #getDownloadStateStream, - [eventId], - ), - returnValueForMissingStub: null, - ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); - - @override - _i5.Future clear(String? eventId) => (super.noSuchMethod( - Invocation.method( - #clear, - [eventId], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future download({ - required _i12.Event? event, - bool? getThumbnail = false, - bool? isFirstPriority = false, - }) => - (super.noSuchMethod( - Invocation.method( - #download, - [], - { - #event: event, - #getThumbnail: getThumbnail, - #isFirstPriority: isFirstPriority, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); -} diff --git a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart deleted file mode 100644 index 3f00dd45f7..0000000000 --- a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart +++ /dev/null @@ -1,1044 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in fluffychat/test/mixin/download/download_file_on_web_mixin_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; -import 'dart:convert' as _i6; -import 'dart:io' as _i2; -import 'dart:typed_data' as _i7; - -import 'package:dartz/dartz.dart' as _i9; -import 'package:fluffychat/app_state/failure.dart' as _i10; -import 'package:fluffychat/app_state/success.dart' as _i11; -import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' - as _i8; -import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' - as _i3; -import 'package:matrix/matrix.dart' as _i12; -import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i4; - -// 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 - -class _FakeFile_0 extends _i1.SmartFake implements _i2.File { - _FakeFile_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeUri_1 extends _i1.SmartFake implements Uri { - _FakeUri_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDirectory_2 extends _i1.SmartFake implements _i2.Directory { - _FakeDirectory_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeFileSystemEntity_3 extends _i1.SmartFake - implements _i2.FileSystemEntity { - _FakeFileSystemEntity_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDateTime_4 extends _i1.SmartFake implements DateTime { - _FakeDateTime_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeRandomAccessFile_5 extends _i1.SmartFake - implements _i2.RandomAccessFile { - _FakeRandomAccessFile_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeIOSink_6 extends _i1.SmartFake implements _i2.IOSink { - _FakeIOSink_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeFileStat_7 extends _i1.SmartFake implements _i2.FileStat { - _FakeFileStat_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDownloadWorkerQueue_8 extends _i1.SmartFake - implements _i3.DownloadWorkerQueue { - _FakeDownloadWorkerQueue_8( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [File]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockFile extends _i1.Mock implements _i2.File { - @override - _i2.File get absolute => (super.noSuchMethod( - Invocation.getter(#absolute), - returnValue: _FakeFile_0( - this, - Invocation.getter(#absolute), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.getter(#absolute), - ), - ) as _i2.File); - - @override - String get path => (super.noSuchMethod( - Invocation.getter(#path), - returnValue: _i4.dummyValue( - this, - Invocation.getter(#path), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.getter(#path), - ), - ) as String); - - @override - Uri get uri => (super.noSuchMethod( - Invocation.getter(#uri), - returnValue: _FakeUri_1( - this, - Invocation.getter(#uri), - ), - returnValueForMissingStub: _FakeUri_1( - this, - Invocation.getter(#uri), - ), - ) as Uri); - - @override - bool get isAbsolute => (super.noSuchMethod( - Invocation.getter(#isAbsolute), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i2.Directory get parent => (super.noSuchMethod( - Invocation.getter(#parent), - returnValue: _FakeDirectory_2( - this, - Invocation.getter(#parent), - ), - returnValueForMissingStub: _FakeDirectory_2( - this, - Invocation.getter(#parent), - ), - ) as _i2.Directory); - - @override - _i5.Future<_i2.File> create({ - bool? recursive = false, - bool? exclusive = false, - }) => - (super.noSuchMethod( - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void createSync({ - bool? recursive = false, - bool? exclusive = false, - }) => - super.noSuchMethod( - Invocation.method( - #createSync, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> rename(String? newPath) => (super.noSuchMethod( - Invocation.method( - #rename, - [newPath], - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - ) as _i5.Future<_i2.File>); - - @override - _i2.File renameSync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #renameSync, - [newPath], - ), - returnValue: _FakeFile_0( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - ) as _i2.File); - - @override - _i5.Future<_i2.FileSystemEntity> delete({bool? recursive = false}) => - (super.noSuchMethod( - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - returnValue: - _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.FileSystemEntity>.value(_FakeFileSystemEntity_3( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - ) as _i5.Future<_i2.FileSystemEntity>); - - @override - void deleteSync({bool? recursive = false}) => super.noSuchMethod( - Invocation.method( - #deleteSync, - [], - {#recursive: recursive}, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> copy(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copy, - [newPath], - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - ) as _i5.Future<_i2.File>); - - @override - _i2.File copySync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copySync, - [newPath], - ), - returnValue: _FakeFile_0( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_0( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - ) as _i2.File); - - @override - _i5.Future length() => (super.noSuchMethod( - Invocation.method( - #length, - [], - ), - returnValue: _i5.Future.value(0), - returnValueForMissingStub: _i5.Future.value(0), - ) as _i5.Future); - - @override - int lengthSync() => (super.noSuchMethod( - Invocation.method( - #lengthSync, - [], - ), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - - @override - _i5.Future lastAccessed() => (super.noSuchMethod( - Invocation.method( - #lastAccessed, - [], - ), - returnValue: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - ) as _i5.Future); - - @override - DateTime lastAccessedSync() => (super.noSuchMethod( - Invocation.method( - #lastAccessedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - ) as DateTime); - - @override - _i5.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastAccessed, - [time], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - void setLastAccessedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastAccessedSync, - [time], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future lastModified() => (super.noSuchMethod( - Invocation.method( - #lastModified, - [], - ), - returnValue: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - returnValueForMissingStub: _i5.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - ) as _i5.Future); - - @override - DateTime lastModifiedSync() => (super.noSuchMethod( - Invocation.method( - #lastModifiedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - ) as DateTime); - - @override - _i5.Future setLastModified(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastModified, - [time], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - void setLastModifiedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastModifiedSync, - [time], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.RandomAccessFile> open( - {_i2.FileMode? mode = _i2.FileMode.read}) => - (super.noSuchMethod( - Invocation.method( - #open, - [], - {#mode: mode}, - ), - returnValue: - _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - ) as _i5.Future<_i2.RandomAccessFile>); - - @override - _i2.RandomAccessFile openSync({_i2.FileMode? mode = _i2.FileMode.read}) => - (super.noSuchMethod( - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - returnValue: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - returnValueForMissingStub: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - ) as _i2.RandomAccessFile); - - @override - _i5.Stream> openRead([ - int? start, - int? end, - ]) => - (super.noSuchMethod( - Invocation.method( - #openRead, - [ - start, - end, - ], - ), - returnValue: _i5.Stream>.empty(), - returnValueForMissingStub: _i5.Stream>.empty(), - ) as _i5.Stream>); - - @override - _i2.IOSink openWrite({ - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - }) => - (super.noSuchMethod( - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - returnValue: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - ), - returnValueForMissingStub: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - ), - ) as _i2.IOSink); - - @override - _i5.Future<_i7.Uint8List> readAsBytes() => (super.noSuchMethod( - Invocation.method( - #readAsBytes, - [], - ), - returnValue: _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - returnValueForMissingStub: - _i5.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - ) as _i5.Future<_i7.Uint8List>); - - @override - _i7.Uint8List readAsBytesSync() => (super.noSuchMethod( - Invocation.method( - #readAsBytesSync, - [], - ), - returnValue: _i7.Uint8List(0), - returnValueForMissingStub: _i7.Uint8List(0), - ) as _i7.Uint8List); - - @override - _i5.Future readAsString( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - returnValue: _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - )), - returnValueForMissingStub: - _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - )), - ) as _i5.Future); - - @override - String readAsStringSync({_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - returnValue: _i4.dummyValue( - this, - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - ), - ) as String); - - @override - _i5.Future> readAsLines( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLines, - [], - {#encoding: encoding}, - ), - returnValue: _i5.Future>.value([]), - returnValueForMissingStub: _i5.Future>.value([]), - ) as _i5.Future>); - - @override - List readAsLinesSync( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLinesSync, - [], - {#encoding: encoding}, - ), - returnValue: [], - returnValueForMissingStub: [], - ) as List); - - @override - _i5.Future<_i2.File> writeAsBytes( - List? bytes, { - _i2.FileMode? mode = _i2.FileMode.write, - bool? flush = false, - }) => - (super.noSuchMethod( - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void writeAsBytesSync( - List? bytes, { - _i2.FileMode? mode = _i2.FileMode.write, - bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsBytesSync, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future<_i2.File> writeAsString( - String? contents, { - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - bool? flush = false, - }) => - (super.noSuchMethod( - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValue: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i5.Future<_i2.File>.value(_FakeFile_0( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - ) as _i5.Future<_i2.File>); - - @override - void writeAsStringSync( - String? contents, { - _i2.FileMode? mode = _i2.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), - bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsStringSync, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future exists() => (super.noSuchMethod( - Invocation.method( - #exists, - [], - ), - returnValue: _i5.Future.value(false), - returnValueForMissingStub: _i5.Future.value(false), - ) as _i5.Future); - - @override - bool existsSync() => (super.noSuchMethod( - Invocation.method( - #existsSync, - [], - ), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i5.Future resolveSymbolicLinks() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinks, - [], - ), - returnValue: _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinks, - [], - ), - )), - returnValueForMissingStub: - _i5.Future.value(_i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinks, - [], - ), - )), - ) as _i5.Future); - - @override - String resolveSymbolicLinksSync() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - returnValue: _i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - ), - ) as String); - - @override - _i5.Future<_i2.FileStat> stat() => (super.noSuchMethod( - Invocation.method( - #stat, - [], - ), - returnValue: _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - returnValueForMissingStub: - _i5.Future<_i2.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - ) as _i5.Future<_i2.FileStat>); - - @override - _i2.FileStat statSync() => (super.noSuchMethod( - Invocation.method( - #statSync, - [], - ), - returnValue: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - returnValueForMissingStub: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - ) as _i2.FileStat); - - @override - _i5.Stream<_i2.FileSystemEvent> watch({ - int? events = 15, - bool? recursive = false, - }) => - (super.noSuchMethod( - Invocation.method( - #watch, - [], - { - #events: events, - #recursive: recursive, - }, - ), - returnValue: _i5.Stream<_i2.FileSystemEvent>.empty(), - returnValueForMissingStub: _i5.Stream<_i2.FileSystemEvent>.empty(), - ) as _i5.Stream<_i2.FileSystemEvent>); -} - -/// A class which mocks [DownloadManager]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { - @override - _i3.DownloadWorkerQueue get workingQueue => (super.noSuchMethod( - Invocation.getter(#workingQueue), - returnValue: _FakeDownloadWorkerQueue_8( - this, - Invocation.getter(#workingQueue), - ), - returnValueForMissingStub: _FakeDownloadWorkerQueue_8( - this, - Invocation.getter(#workingQueue), - ), - ) as _i3.DownloadWorkerQueue); - - @override - void cancelDownload(String? eventId) => super.noSuchMethod( - Invocation.method( - #cancelDownload, - [eventId], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( - String? eventId) => - (super.noSuchMethod( - Invocation.method( - #getDownloadStateStream, - [eventId], - ), - returnValueForMissingStub: null, - ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); - - @override - _i5.Future clear(String? eventId) => (super.noSuchMethod( - Invocation.method( - #clear, - [eventId], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future download({ - required _i12.Event? event, - bool? getThumbnail = false, - bool? isFirstPriority = false, - }) => - (super.noSuchMethod( - Invocation.method( - #download, - [], - { - #event: event, - #getThumbnail: getThumbnail, - #isFirstPriority: isFirstPriority, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); -} From ccc60f1c89a860e36e1d94e5edbf124ae5c455cf Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 22:01:08 +0200 Subject: [PATCH 09/11] fixup! fixup! TW-1702/shared_mocks.dart added --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index f4757ac28f..0af0e24111 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: matrix: git: url: git@github.com:linagora/matrix-dart-sdk.git - ref: TW-1702/hotfix_download_error_handling + ref: twake-supported-0.22.6 receive_sharing_intent: git: From b9d3c6028515d81f897e30c187532589aafff853 Mon Sep 17 00:00:00 2001 From: Terence ZAFINDRATAFA Date: Tue, 9 Jul 2024 18:01:21 +0200 Subject: [PATCH 10/11] TW-1702: handle download error on file tab --- .../chat_details_files_item_view.dart | 4 +++- .../chat_details_files_item_view_web.dart | 4 +++- .../chat_details_file_downloading_tile.dart | 3 +++ ...chat_details_file_row_downloading_web.dart | 3 +++ .../chat_details_row_downloading_wrapper.dart | 20 +++++++++++++++---- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item/chat_details_files_item_view.dart b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item/chat_details_files_item_view.dart index d9a0a9f446..c2b682dad4 100644 --- a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item/chat_details_files_item_view.dart +++ b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item/chat_details_files_item_view.dart @@ -24,7 +24,8 @@ class ChatDetailsFilesView extends StatelessWidget { return ValueListenableBuilder( valueListenable: controller.downloadFileStateNotifier, builder: (context, DownloadPresentationState state, child) { - if (state is DownloadingPresentationState) { + if (state is DownloadingPresentationState || + state is DownloadErrorPresentationState) { return ChatDetailsDownloadingFileTile( mimeType: controller.event.mimeType, fileType: filetype, @@ -37,6 +38,7 @@ class ChatDetailsFilesView extends StatelessWidget { controller.downloadManager .cancelDownload(controller.event.eventId); }, + hasError: state is DownloadErrorPresentationState, ); } else if (state is DownloadedPresentationState) { return ChatDetailsDownloadedFileTile( diff --git a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item_web/chat_details_files_item_view_web.dart b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item_web/chat_details_files_item_view_web.dart index f7f66b4d52..406a1b0838 100644 --- a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item_web/chat_details_files_item_view_web.dart +++ b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_item_web/chat_details_files_item_view_web.dart @@ -22,7 +22,8 @@ class ChatDetailsFilesViewWeb extends StatelessWidget { return ValueListenableBuilder( valueListenable: controller.downloadFileStateNotifier, builder: (context, DownloadPresentationState state, child) { - if (state is DownloadingPresentationState) { + if (state is DownloadingPresentationState || + state is DownloadErrorPresentationState) { return ChatDetailsFileTileRowDownloadingWeb( mimeType: controller.event.mimeType, fileType: filetype, @@ -36,6 +37,7 @@ class ChatDetailsFilesViewWeb extends StatelessWidget { controller.downloadManager .cancelDownload(controller.event.eventId); }, + hasError: state is DownloadErrorPresentationState, ); } diff --git a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_downloading_tile.dart b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_downloading_tile.dart index e37f764eb9..fdc212d05e 100644 --- a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_downloading_tile.dart +++ b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_downloading_tile.dart @@ -14,6 +14,7 @@ class ChatDetailsDownloadingFileTile extends StatelessWidget { required this.fileType, required this.sizeString, required this.downloadFileStateNotifier, + this.hasError = false, }); final GestureTapCallback onTap; @@ -22,6 +23,7 @@ class ChatDetailsDownloadingFileTile extends StatelessWidget { final String? fileType; final String? sizeString; final ValueNotifier downloadFileStateNotifier; + final bool hasError; @override Widget build(BuildContext context) { @@ -29,6 +31,7 @@ class ChatDetailsDownloadingFileTile extends StatelessWidget { hoverColor: LinagoraSysColors.material().surfaceVariant, onTap: onTap, child: ChatDetailsFileRowDownloadingWrapper( + hasError: hasError, mimeType: mimeType, fileType: fileType, downloadFileStateNotifier: downloadFileStateNotifier, diff --git a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_row_downloading_web.dart b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_row_downloading_web.dart index d7e45da4d1..615af0c414 100644 --- a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_row_downloading_web.dart +++ b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_file_row_downloading_web.dart @@ -17,6 +17,7 @@ class ChatDetailsFileTileRowDownloadingWeb extends StatelessWidget { required this.sizeString, required this.onTap, required this.downloadFileStateNotifier, + this.hasError = false, }); final GestureTapCallback onTap; @@ -26,6 +27,7 @@ class ChatDetailsFileTileRowDownloadingWeb extends StatelessWidget { final String? fileType; final DateTime sentDate; final ValueNotifier downloadFileStateNotifier; + final bool hasError; @override Widget build(BuildContext context) { @@ -33,6 +35,7 @@ class ChatDetailsFileTileRowDownloadingWeb extends StatelessWidget { hoverColor: LinagoraSysColors.material().surfaceVariant, onTap: onTap, child: ChatDetailsFileRowDownloadingWrapper( + hasError: hasError, mimeType: mimeType, fileType: fileType, downloadFileStateNotifier: downloadFileStateNotifier, diff --git a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_row_downloading_wrapper.dart b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_row_downloading_wrapper.dart index 955d963ec5..577a6a09fa 100644 --- a/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_row_downloading_wrapper.dart +++ b/lib/pages/chat_details/chat_details_page_view/files/chat_details_files_row/chat_details_row_downloading_wrapper.dart @@ -9,6 +9,7 @@ class ChatDetailsFileRowDownloadingWrapper extends StatelessWidget { final String? mimeType; final String? fileType; final ValueNotifier downloadFileStateNotifier; + final bool hasError; const ChatDetailsFileRowDownloadingWrapper({ super.key, @@ -16,6 +17,7 @@ class ChatDetailsFileRowDownloadingWrapper extends StatelessWidget { required this.mimeType, required this.fileType, required this.downloadFileStateNotifier, + this.hasError = false, }); final style = const MessageFileTileStyle(); @@ -50,11 +52,14 @@ class ChatDetailsFileRowDownloadingWrapper extends StatelessWidget { width: style.iconSize, height: style.iconSize, decoration: BoxDecoration( - color: Theme.of(context).colorScheme.primary, + color: style.iconBackgroundColor( + hasError: hasError, + context: context, + ), shape: BoxShape.circle, ), ), - if (downloadProgress != 0) + if (downloadProgress != 0 && !hasError) SizedBox( width: style.circularProgressLoadingSize, height: style.circularProgressLoadingSize, @@ -66,11 +71,18 @@ class ChatDetailsFileRowDownloadingWrapper extends StatelessWidget { Container( width: style.downloadIconSize, decoration: BoxDecoration( - color: Theme.of(context).colorScheme.primary, + color: style.iconBackgroundColor( + hasError: hasError, + context: context, + ), shape: BoxShape.circle, ), child: Icon( - downloadProgress == 0 ? Icons.arrow_downward : Icons.close, + hasError + ? Icons.error_outline + : downloadProgress == 0 + ? Icons.arrow_downward + : Icons.close, key: ValueKey(downloadProgress), color: Theme.of(context).colorScheme.surface, size: style.downloadIconSize, From 3934039aba4c1ac7fd75b528c1bc5d9228b32f04 Mon Sep 17 00:00:00 2001 From: "khaled.njim" Date: Fri, 26 Jul 2024 15:43:23 +0100 Subject: [PATCH 11/11] TW-1702 handle connectivity status change when downloading --- .../download_manager/download_manager.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/utils/manager/download_manager/download_manager.dart b/lib/utils/manager/download_manager/download_manager.dart index a283163d0a..a03a1dd793 100644 --- a/lib/utils/manager/download_manager/download_manager.dart +++ b/lib/utils/manager/download_manager/download_manager.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:dartz/dartz.dart' hide Task; import 'package:dio/dio.dart'; import 'package:fluffychat/app_state/failure.dart'; @@ -11,6 +12,7 @@ import 'package:fluffychat/utils/manager/download_manager/download_file_state.da import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/download_file_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/download_file_web_extension.dart'; +import 'package:fluffychat/utils/network_connection_service.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/task_queue/task.dart'; import 'package:matrix/matrix.dart'; @@ -28,6 +30,9 @@ class DownloadManager { final Map _eventIdMapDownloadFileInfo = {}; + final NetworkConnectionService _connectivityService = + getIt.get(); + void cancelDownload(String eventId) { final cancelToken = _eventIdMapDownloadFileInfo[eventId]?.cancelToken; if (cancelToken != null) { @@ -132,6 +137,26 @@ class DownloadManager { cancelToken: cancelToken, isFirstPriority: isFirstPriority, ); + + _connectivityService.connectivity.onConnectivityChanged + .listen((connectivity) async { + if (connectivity == ConnectivityResult.none) { + Logs().e( + 'DownloadManager::download(): No internet connectivity', + ); + streamController.add( + Left( + DownloadFileFailureState( + exception: Exception( + 'No internet connectivity', + ), + ), + ), + ); + cancelDownload(event.eventId); + return; + } + }); } void _addTaskToWorkerQueue({