Added tests
This commit is contained in:
@@ -55,6 +55,7 @@ define(
|
||||
"transactionService",
|
||||
[
|
||||
"startTransaction",
|
||||
"size",
|
||||
"commit",
|
||||
"cancel"
|
||||
]
|
||||
@@ -161,11 +162,9 @@ define(
|
||||
});
|
||||
it("returns true if the object has been modified since it" +
|
||||
" was last persisted", function () {
|
||||
model.modified = 0;
|
||||
model.persisted = 0;
|
||||
mockTransactionService.size.andReturn(0);
|
||||
expect(capability.dirty()).toBe(false);
|
||||
|
||||
model.modified = 1;
|
||||
mockTransactionService.size.andReturn(1);
|
||||
expect(capability.dirty()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,7 +56,8 @@ define(
|
||||
"persistenceCapability",
|
||||
["persist", "refresh"]
|
||||
);
|
||||
|
||||
mockPersistence.persist.andReturn(fastPromise());
|
||||
mockPersistence.refresh.andReturn(fastPromise());
|
||||
capability = new TransactionalPersistenceCapability(mockQ, mockTransactionService, mockPersistence, mockDomainObject);
|
||||
});
|
||||
|
||||
@@ -67,26 +68,26 @@ define(
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if transaction is active, persist call is queued", function() {
|
||||
it("if transaction is active, persist and cancel calls are" +
|
||||
" queued", function() {
|
||||
mockTransactionService.isActive.andReturn(true);
|
||||
capability.persist();
|
||||
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
|
||||
|
||||
//Test that it was the persist call that was queued
|
||||
mockTransactionService.addToTransaction.mostRecentCall.args[0]();
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if transaction is active, refresh call is queued as cancel" +
|
||||
" function", function() {
|
||||
mockTransactionService.isActive.andReturn(true);
|
||||
capability.persist();
|
||||
|
||||
//Test that it was the persist call that was queued
|
||||
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();
|
||||
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
|
||||
capability.persist();
|
||||
expect(mockTransactionService.addToTransaction.calls.length).toBe(1);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user