diff --git a/lib/features/public_asset/presentation/public_asset_controller.dart b/lib/features/public_asset/presentation/public_asset_controller.dart index 9b598d21b..fdde332e8 100644 --- a/lib/features/public_asset/presentation/public_asset_controller.dart +++ b/lib/features/public_asset/presentation/public_asset_controller.dart @@ -187,7 +187,7 @@ class PublicAssetController extends BaseController { } void discardChanges() { - if (session == null || accountId == null) return; + if (session == null || accountId == null || newlyPickedPublicAssetIds.isEmpty) return; consumeState(_deletePublicAssetsInteractor.execute( session!, accountId!, diff --git a/test/features/identity_creator/presentation/identity_creator_controller_test.dart b/test/features/identity_creator/presentation/identity_creator_controller_test.dart index 629d507ea..f591a78a0 100644 --- a/test/features/identity_creator/presentation/identity_creator_controller_test.dart +++ b/test/features/identity_creator/presentation/identity_creator_controller_test.dart @@ -161,7 +161,47 @@ void main() { group("IdentityCreatorController test:", () { test( 'should call deletePublicAssetsInteractor.execute() ' - 'when closeView() is called', + 'when closeView() is called ' + 'and user has picked at lease one image', + () { + // arrange + final accountId = AccountId(Id('value')); + final account = Account( + AccountName('value'), + true, + true, + {CapabilityIdentifier.jmapPublicAsset: DefaultCapability({})}); + final session = Session( + {}, + {accountId: account}, + {}, UserName('value'), Uri(), Uri(), Uri(), Uri(), State('value')); + identityCreatorController.arguments = IdentityCreatorArguments(accountId, session); + + // act + identityCreatorController.onReady(); + expect(identityCreatorController.publicAssetController, isNotNull); + identityCreatorController.publicAssetController?.newlyPickedPublicAssetIds.add(Id('value')); + + final context = MockBuildContext(); + final buildOwner = MockBuildOwner(); + final focusManager = MockFocusManager(); + when(context.owner).thenReturn(buildOwner); + when(buildOwner.focusManager).thenReturn(focusManager); + when(focusManager.rootScope).thenReturn(FocusScopeNode()); + identityCreatorController.closeView(context); + + // assert + verify(deletePublicAssetsInteractor.execute( + session, + accountId, + publicAssetIds: anyNamed('publicAssetIds'), + )).called(1); + }); + + test( + 'should not call deletePublicAssetsInteractor.execute() ' + 'when closeView() is called ' + 'and user has not picked any image', () { // arrange final accountId = AccountId(Id('value')); @@ -189,11 +229,11 @@ void main() { identityCreatorController.closeView(context); // assert - verify(deletePublicAssetsInteractor.execute( + verifyNever(deletePublicAssetsInteractor.execute( session, accountId, publicAssetIds: anyNamed('publicAssetIds'), - )).called(1); + )); }); }); } \ No newline at end of file