diff --git a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js index ffa6097125..073e5c8fad 100644 --- a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js +++ b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js @@ -67,10 +67,17 @@ define( } function onCancel() { - return self.persistenceCapability.refresh().then(function (result) { + if (self.domainObject.getModel().persisted) { + //Fetch clean model from persistence + return self.persistenceCapability.refresh().then(function (result) { + self.persistPending = false; + return result; + }); + } else { self.persistPending = false; - return result; - }); + //Model is undefined in persistence, so return undefined. + return self.$q.when(undefined); + } } if (this.transactionService.isActive()) { diff --git a/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js index 63a9119826..70ad3d8a20 100644 --- a/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js +++ b/platform/commonUI/edit/test/capabilities/TransactionalPersistenceCapabilitySpec.js @@ -57,6 +57,15 @@ define( ); mockPersistence.persist.andReturn(fastPromise()); mockPersistence.refresh.andReturn(fastPromise()); + + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ + "getModel" + ] + ); + mockDomainObject.getModel.andReturn({persisted: 1}); + capability = new TransactionalPersistenceCapability(mockQ, mockTransactionService, mockPersistence, mockDomainObject); }); @@ -78,6 +87,20 @@ define( expect(mockPersistence.refresh).toHaveBeenCalled(); }); + it("if transaction is active, cancel call is queued that refreshes model when appropriate", function () { + mockTransactionService.isActive.andReturn(true); + capability.persist(); + expect(mockTransactionService.addToTransaction).toHaveBeenCalled(); + + mockDomainObject.getModel.andReturn({}); + mockTransactionService.addToTransaction.mostRecentCall.args[1](); + expect(mockPersistence.refresh).not.toHaveBeenCalled(); + + mockDomainObject.getModel.andReturn({persisted: 1}); + mockTransactionService.addToTransaction.mostRecentCall.args[1](); + expect(mockPersistence.refresh).toHaveBeenCalled(); + }); + it("persist call is only added to transaction once", function () { mockTransactionService.isActive.andReturn(true); capability.persist();