2015-11-05 20:45:51 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open MCT Web, Copyright (c) 2009-2015, United States Government
|
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
|
|
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* Open MCT Web includes source code licensed under additional open source
|
|
|
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
|
|
* this source code distribution or the Licensing information page available
|
|
|
|
* at runtime from the About dialog for additional information.
|
|
|
|
*****************************************************************************/
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
['../../../src/controllers/swimlane/TimelineProxy'],
|
|
|
|
function (TimelineProxy) {
|
|
|
|
|
|
|
|
describe("The Timeline's selection proxy", function () {
|
|
|
|
var mockDomainObject,
|
|
|
|
mockSelection,
|
|
|
|
mockActionCapability,
|
|
|
|
mockActions,
|
|
|
|
proxy;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
|
|
|
['getCapability']
|
|
|
|
);
|
|
|
|
mockSelection = jasmine.createSpyObj(
|
|
|
|
'selection',
|
2016-05-19 18:29:13 +00:00
|
|
|
['get']
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
mockActionCapability = jasmine.createSpyObj(
|
|
|
|
'action',
|
2016-05-19 18:29:13 +00:00
|
|
|
['getActions']
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
mockActions = ['a', 'b', 'c'].map(function (type) {
|
|
|
|
var mockAction = jasmine.createSpyObj(
|
|
|
|
'action-' + type,
|
2016-05-19 18:29:13 +00:00
|
|
|
['perform', 'getMetadata']
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
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)
|
2016-01-21 04:52:26 +00:00
|
|
|
.toHaveBeenCalledWith('add');
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|