2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open MCT Web, Copyright (c) 2014-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.
|
|
|
|
*****************************************************************************/
|
2014-11-26 02:30:30 +00:00
|
|
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../../src/creation/CreateWizard"],
|
|
|
|
function (CreateWizard) {
|
|
|
|
"use strict";
|
|
|
|
|
2014-11-26 04:26:37 +00:00
|
|
|
describe("The create wizard", function () {
|
|
|
|
var mockType,
|
|
|
|
mockParent,
|
|
|
|
mockProperties,
|
2015-04-11 01:00:13 +00:00
|
|
|
mockPolicyService,
|
2014-12-04 01:59:37 +00:00
|
|
|
testModel,
|
2016-01-21 04:52:26 +00:00
|
|
|
mockDomainObject,
|
2014-11-26 04:26:37 +00:00
|
|
|
wizard;
|
|
|
|
|
|
|
|
function createMockProperty(name) {
|
|
|
|
var mockProperty = jasmine.createSpyObj(
|
|
|
|
"property" + name,
|
|
|
|
[ "getDefinition", "getValue", "setValue" ]
|
|
|
|
);
|
2015-09-01 18:46:43 +00:00
|
|
|
mockProperty.getDefinition.andReturn({
|
|
|
|
control: "textfield"
|
|
|
|
});
|
2014-12-04 01:59:37 +00:00
|
|
|
mockProperty.getValue.andReturn(name);
|
2014-11-26 04:26:37 +00:00
|
|
|
return mockProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockType = jasmine.createSpyObj(
|
|
|
|
"type",
|
|
|
|
[
|
|
|
|
"getKey",
|
|
|
|
"getGlyph",
|
|
|
|
"getName",
|
|
|
|
"getDescription",
|
|
|
|
"getProperties",
|
|
|
|
"getInitialModel"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockParent = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[
|
|
|
|
"getId",
|
|
|
|
"getModel",
|
|
|
|
"getCapability"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
mockProperties = [ "A", "B", "C" ].map(createMockProperty);
|
2015-04-11 01:00:13 +00:00
|
|
|
mockPolicyService = jasmine.createSpyObj('policyService', ['allow']);
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2014-12-04 01:59:37 +00:00
|
|
|
testModel = { someKey: "some value" };
|
|
|
|
|
2014-11-26 04:26:37 +00:00
|
|
|
mockType.getKey.andReturn("test");
|
|
|
|
mockType.getGlyph.andReturn("T");
|
|
|
|
mockType.getDescription.andReturn("a test type");
|
|
|
|
mockType.getName.andReturn("Test");
|
2014-12-04 01:59:37 +00:00
|
|
|
mockType.getInitialModel.andReturn(testModel);
|
2014-11-26 04:26:37 +00:00
|
|
|
mockType.getProperties.andReturn(mockProperties);
|
|
|
|
|
2016-01-21 04:52:26 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
|
|
|
['getCapability', 'useCapability', 'getModel']
|
|
|
|
);
|
|
|
|
|
|
|
|
//Mocking the getCapability('type') call
|
|
|
|
mockDomainObject.getCapability.andReturn(mockType);
|
|
|
|
mockDomainObject.useCapability.andReturn();
|
|
|
|
mockDomainObject.getModel.andReturn(testModel);
|
|
|
|
|
2014-11-26 04:26:37 +00:00
|
|
|
wizard = new CreateWizard(
|
2016-01-21 04:52:26 +00:00
|
|
|
mockDomainObject,
|
2015-04-11 01:00:13 +00:00
|
|
|
mockParent,
|
|
|
|
mockPolicyService
|
2014-11-26 04:26:37 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("creates a form model with a Properties section", function () {
|
2014-12-04 01:26:02 +00:00
|
|
|
expect(wizard.getFormStructure().sections[0].name)
|
2014-11-26 04:26:37 +00:00
|
|
|
.toEqual("Properties");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("adds one row per defined type property", function () {
|
|
|
|
// Three properties were defined in the mock type
|
2014-12-04 01:26:02 +00:00
|
|
|
expect(wizard.getFormStructure().sections[0].rows.length)
|
2014-11-26 04:26:37 +00:00
|
|
|
.toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("interprets form data using type-defined properties", function () {
|
|
|
|
// Use key names from mock properties
|
2014-12-04 01:26:02 +00:00
|
|
|
wizard.createModel([
|
|
|
|
"field 0",
|
|
|
|
"field 1",
|
|
|
|
"field 2"
|
|
|
|
]);
|
2014-11-26 04:26:37 +00:00
|
|
|
|
|
|
|
// Should have gotten a setValue call
|
|
|
|
mockProperties.forEach(function (mockProperty, i) {
|
|
|
|
expect(mockProperty.setValue).toHaveBeenCalledWith(
|
2014-12-04 01:59:37 +00:00
|
|
|
{ someKey: "some value", type: 'test' },
|
2014-11-26 04:26:37 +00:00
|
|
|
"field " + i
|
|
|
|
);
|
|
|
|
});
|
2014-12-04 01:59:37 +00:00
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2014-12-04 01:59:37 +00:00
|
|
|
it("looks up initial values from properties", function () {
|
|
|
|
var initialValue = wizard.getInitialFormValue();
|
2014-11-26 04:26:37 +00:00
|
|
|
|
2014-12-04 01:59:37 +00:00
|
|
|
expect(initialValue[0]).toEqual("A");
|
|
|
|
expect(initialValue[1]).toEqual("B");
|
|
|
|
expect(initialValue[2]).toEqual("C");
|
|
|
|
|
|
|
|
// Verify that expected argument was passed
|
|
|
|
mockProperties.forEach(function (mockProperty) {
|
|
|
|
expect(mockProperty.getValue)
|
|
|
|
.toHaveBeenCalledWith(testModel);
|
|
|
|
});
|
2014-11-26 04:26:37 +00:00
|
|
|
});
|
|
|
|
|
2016-01-21 04:52:26 +00:00
|
|
|
it("populates the model on the associated object", function () {
|
|
|
|
var formValue = {
|
|
|
|
"A": "ValueA",
|
|
|
|
"B": "ValueB",
|
|
|
|
"C": "ValueC"
|
|
|
|
},
|
|
|
|
compareModel = wizard.createModel(formValue);
|
|
|
|
wizard.populateObjectFromInput(formValue);
|
|
|
|
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function));
|
|
|
|
expect(mockDomainObject.useCapability.mostRecentCall.args[1]()).toEqual(compareModel);
|
|
|
|
});
|
|
|
|
|
2015-04-11 01:00:13 +00:00
|
|
|
it("validates selection types using policy", function () {
|
|
|
|
var mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
|
|
|
['getCapability']
|
|
|
|
),
|
|
|
|
mockOtherType = jasmine.createSpyObj(
|
|
|
|
'otherType',
|
|
|
|
['getKey']
|
|
|
|
),
|
2016-01-21 04:52:26 +00:00
|
|
|
//Create a form structure with location
|
|
|
|
structure = wizard.getFormStructure(true),
|
2015-04-11 01:00:13 +00:00
|
|
|
sections = structure.sections,
|
|
|
|
rows = structure.sections[sections.length - 1].rows,
|
|
|
|
locationRow = rows[rows.length - 1];
|
|
|
|
|
|
|
|
mockDomainObject.getCapability.andReturn(mockOtherType);
|
|
|
|
locationRow.validate(mockDomainObject);
|
|
|
|
|
|
|
|
// Should check policy to see if the user-selected location
|
|
|
|
// can actually contain objects of this type
|
|
|
|
expect(mockPolicyService.allow).toHaveBeenCalledWith(
|
|
|
|
'composition',
|
|
|
|
mockOtherType,
|
|
|
|
mockType
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-21 04:52:26 +00:00
|
|
|
it("creates a form model without a location if not requested", function () {
|
|
|
|
expect(wizard.getFormStructure(false).sections.some(function(section){
|
|
|
|
return section.name === 'Location';
|
|
|
|
})).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2014-11-26 02:30:30 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2015-09-01 18:46:43 +00:00
|
|
|
);
|