mirror of
https://github.com/nasa/openmct.git
synced 2025-01-18 02:39:56 +00:00
[Persistence] Finish testing TransactionManager
This commit is contained in:
parent
31264aadda
commit
99227d2e42
@ -26,9 +26,11 @@ define(
|
|||||||
function (TransactionManager) {
|
function (TransactionManager) {
|
||||||
describe("TransactionManager", function () {
|
describe("TransactionManager", function () {
|
||||||
var mockTransactionService,
|
var mockTransactionService,
|
||||||
|
mockDomainObject,
|
||||||
mockOnCommit,
|
mockOnCommit,
|
||||||
mockOnCancel,
|
mockOnCancel,
|
||||||
mockRemoves,
|
mockRemoves,
|
||||||
|
mockPromise,
|
||||||
manager;
|
manager;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -39,6 +41,15 @@ define(
|
|||||||
);
|
);
|
||||||
mockOnCommit = jasmine.createSpy('commit');
|
mockOnCommit = jasmine.createSpy('commit');
|
||||||
mockOnCancel = jasmine.createSpy('cancel');
|
mockOnCancel = jasmine.createSpy('cancel');
|
||||||
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
|
'domainObject',
|
||||||
|
[ 'getId', 'getModel', 'getCapability' ]
|
||||||
|
);
|
||||||
|
mockDomainObject.getId.andReturn('testId');
|
||||||
|
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||||
|
|
||||||
|
mockOnCommit.andReturn(mockPromise);
|
||||||
|
mockOnCancel.andReturn(mockPromise);
|
||||||
|
|
||||||
mockTransactionService.addToTransaction.andCallFake(function () {
|
mockTransactionService.addToTransaction.andCallFake(function () {
|
||||||
var mockRemove =
|
var mockRemove =
|
||||||
@ -56,6 +67,71 @@ define(
|
|||||||
expect(manager.isActive()).toBe(state);
|
expect(manager.isActive()).toBe(state);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when addToTransaction is called", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
manager.addToTransaction(
|
||||||
|
mockDomainObject,
|
||||||
|
mockOnCommit,
|
||||||
|
mockOnCancel
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds callbacks to the active transaction", function () {
|
||||||
|
expect(mockTransactionService.addToTransaction)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invokes passed-in callbacks from its own callbacks", function () {
|
||||||
|
expect(mockOnCommit).not.toHaveBeenCalled();
|
||||||
|
mockTransactionService.addToTransaction
|
||||||
|
.mostRecentCall.args[0]();
|
||||||
|
expect(mockOnCommit).toHaveBeenCalled();
|
||||||
|
|
||||||
|
expect(mockOnCancel).not.toHaveBeenCalled();
|
||||||
|
mockTransactionService.addToTransaction
|
||||||
|
.mostRecentCall.args[1]();
|
||||||
|
expect(mockOnCancel).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ignores subsequent calls for the same object", function () {
|
||||||
|
manager.addToTransaction(
|
||||||
|
mockDomainObject,
|
||||||
|
jasmine.createSpy(),
|
||||||
|
jasmine.createSpy()
|
||||||
|
);
|
||||||
|
expect(mockTransactionService.addToTransaction.calls.length)
|
||||||
|
.toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts subsequent calls for other objects", function () {
|
||||||
|
mockDomainObject.getId.andReturn('otherId');
|
||||||
|
manager.addToTransaction(
|
||||||
|
mockDomainObject,
|
||||||
|
jasmine.createSpy(),
|
||||||
|
jasmine.createSpy()
|
||||||
|
);
|
||||||
|
expect(mockTransactionService.addToTransaction.calls.length)
|
||||||
|
.toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not remove callbacks from the transaction", function () {
|
||||||
|
expect(mockRemoves[0]).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("and clearTransactionsFor is subsequently called", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
manager.clearTransactionsFor(mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes callbacks from the transaction", function () {
|
||||||
|
expect(mockRemoves[0]).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user