openmct/platform/features/timeline/test/controllers/swimlane/TimelineProxySpec.js
2015-09-14 16:45:41 -07:00

88 lines
3.3 KiB
JavaScript

/*global define,describe,it,expect,beforeEach,waitsFor,jasmine,window,afterEach*/
define(
['../../../src/controllers/swimlane/TimelineProxy'],
function (TimelineProxy) {
'use strict';
describe("The Timeline's selection proxy", function () {
var mockDomainObject,
mockSelection,
mockActionCapability,
mockActions,
proxy;
beforeEach(function () {
mockDomainObject = jasmine.createSpyObj(
'domainObject',
['getCapability']
);
mockSelection = jasmine.createSpyObj(
'selection',
[ 'get' ]
);
mockActionCapability = jasmine.createSpyObj(
'action',
[ 'getActions' ]
);
mockActions = ['a', 'b', 'c'].map(function (type) {
var mockAction = jasmine.createSpyObj(
'action-' + type,
[ 'perform', 'getMetadata' ]
);
mockAction.getMetadata.andReturn({ type: type });
return mockAction;
});
mockDomainObject.getCapability.andReturn(mockActionCapability);
mockActionCapability.getActions.andReturn(mockActions);
proxy = new TimelineProxy(mockDomainObject, mockSelection);
});
it("triggers a create action on add", function () {
// Should trigger b's create action
proxy.add('b');
expect(mockActions[1].perform).toHaveBeenCalled();
// Also check that other actions weren't invoked
expect(mockActions[0].perform).not.toHaveBeenCalled();
expect(mockActions[2].perform).not.toHaveBeenCalled();
// Verify that interactions were for correct keys
expect(mockDomainObject.getCapability)
.toHaveBeenCalledWith('action');
expect(mockActionCapability.getActions)
.toHaveBeenCalledWith('create');
});
it("invokes the action on the selection, if any", function () {
var mockOtherObject = jasmine.createSpyObj(
'other',
['getCapability']
),
mockOtherAction = jasmine.createSpyObj(
'actionCapability',
['getActions']
),
mockAction = jasmine.createSpyObj(
'action',
['perform', 'getMetadata']
);
// Set up mocks
mockSelection.get.andReturn({ domainObject: mockOtherObject });
mockOtherObject.getCapability.andReturn(mockOtherAction);
mockOtherAction.getActions.andReturn([mockAction]);
mockAction.getMetadata.andReturn({ type: 'z' });
// Invoke add method; should create with selected object
proxy.add('z');
expect(mockAction.perform).toHaveBeenCalled();
});
});
}
);