2016-02-04 00:00:11 +00:00
|
|
|
/*****************************************************************************
|
2017-04-05 21:35:12 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2017, United States Government
|
2016-02-04 00:00:11 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2016-02-04 00:00:11 +00:00
|
|
|
* "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.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2016-02-04 00:00:11 +00:00
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
define(
|
2016-02-09 07:05:48 +00:00
|
|
|
['../src/InspectorController'],
|
|
|
|
function (InspectorController) {
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-02-09 07:05:48 +00:00
|
|
|
describe("The inspector controller ", function () {
|
2016-02-04 00:00:11 +00:00
|
|
|
var mockScope,
|
|
|
|
mockDomainObject,
|
2017-12-07 21:04:46 +00:00
|
|
|
mockOpenMCT,
|
|
|
|
mockSelection,
|
|
|
|
mockInspectorViews,
|
|
|
|
mockTypeDef,
|
|
|
|
controller,
|
|
|
|
container,
|
|
|
|
$document = [],
|
|
|
|
selectable = [];
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
beforeEach(function () {
|
2017-12-07 21:04:46 +00:00
|
|
|
mockTypeDef = {
|
|
|
|
typeDef: {
|
|
|
|
inspector: "some-key"
|
|
|
|
}
|
2016-02-04 00:00:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
|
|
|
'getCapability'
|
|
|
|
]);
|
2017-12-07 21:04:46 +00:00
|
|
|
mockDomainObject.getCapability.andReturn(mockTypeDef);
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2016-05-13 03:23:33 +00:00
|
|
|
mockScope = jasmine.createSpyObj('$scope',
|
2017-12-07 21:04:46 +00:00
|
|
|
['$on', 'selection']
|
2016-05-13 03:23:33 +00:00
|
|
|
);
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
selectable[0] = {
|
|
|
|
context: {
|
|
|
|
oldItem: mockDomainObject
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mockSelection = jasmine.createSpyObj("selection", [
|
|
|
|
'on',
|
|
|
|
'off',
|
|
|
|
'get'
|
|
|
|
]);
|
|
|
|
mockSelection.get.andReturn(selectable);
|
|
|
|
|
|
|
|
mockInspectorViews = jasmine.createSpyObj('inspectorViews', ['get']);
|
|
|
|
mockOpenMCT = {
|
|
|
|
selection: mockSelection,
|
|
|
|
inspectorViews: mockInspectorViews
|
|
|
|
};
|
2016-02-04 00:00:11 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
container = jasmine.createSpy('container', ['innerHTML']);
|
|
|
|
$document[0] = jasmine.createSpyObj("$document", ['querySelectorAll']);
|
|
|
|
$document[0].querySelectorAll.andReturn([container]);
|
|
|
|
|
|
|
|
controller = new InspectorController(mockScope, mockOpenMCT, $document);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("listens for selection change event", function () {
|
|
|
|
expect(mockOpenMCT.selection.on).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(controller.selectedItem()).toEqual(mockDomainObject);
|
|
|
|
|
|
|
|
var mockItem = jasmine.createSpyObj('domainObject', [
|
|
|
|
'getCapability'
|
|
|
|
]);
|
|
|
|
mockItem.getCapability.andReturn(mockTypeDef);
|
|
|
|
selectable[0].context.oldItem = mockItem;
|
|
|
|
|
|
|
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
|
|
|
|
|
|
|
expect(controller.selectedItem()).toEqual(mockItem);
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
2016-05-13 03:23:33 +00:00
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("cleans up on scope destroy", function () {
|
|
|
|
expect(mockScope.$on).toHaveBeenCalledWith(
|
|
|
|
'$destroy',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
|
|
|
|
mockScope.$on.calls[0].args[1]();
|
|
|
|
|
|
|
|
expect(mockOpenMCT.selection.off).toHaveBeenCalledWith(
|
|
|
|
'change',
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
2016-05-13 03:23:33 +00:00
|
|
|
});
|
|
|
|
|
2017-12-07 21:04:46 +00:00
|
|
|
it("adds selection object to scope", function () {
|
|
|
|
expect(mockScope.selection).toEqual(selectable);
|
|
|
|
expect(controller.selectedItem()).toEqual(mockDomainObject);
|
2016-05-13 03:23:33 +00:00
|
|
|
});
|
2016-02-04 00:00:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|