From 162809e081ec7861053c5f0cf00cc4f69ecfe690 Mon Sep 17 00:00:00 2001 From: Joshi Date: Wed, 18 Dec 2019 13:13:54 -0800 Subject: [PATCH 1/2] [#2570] adds new condition type and plugin. Also adds tests --- src/MCT.js | 1 + src/plugins/condition/plugin.js | 35 +++++++++++++++++++++ src/plugins/condition/pluginSpec.js | 48 +++++++++++++++++++++++++++++ src/plugins/plugins.js | 7 +++-- 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/plugins/condition/plugin.js create mode 100644 src/plugins/condition/pluginSpec.js diff --git a/src/MCT.js b/src/MCT.js index c07dd39840..c045b6e561 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -264,6 +264,7 @@ define([ this.install(this.plugins.GoToOriginalAction()); this.install(this.plugins.ImportExport()); this.install(this.plugins.WebPage()); + this.install(this.plugins.Condition()); } MCT.prototype = Object.create(EventEmitter.prototype); diff --git a/src/plugins/condition/plugin.js b/src/plugins/condition/plugin.js new file mode 100644 index 0000000000..b55ca2c806 --- /dev/null +++ b/src/plugins/condition/plugin.js @@ -0,0 +1,35 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2019, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT 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 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. + *****************************************************************************/ + +export default function ConditionPlugin() { + return function install(openmct) { + openmct.types.addType('condition', { + name: 'Condition', + key: 'condition', + description: 'A list of criteria which will be evaluated based on a trigger', + creatable: false, + initialize: function (domainObject) { + domainObject.composition = []; + } + }); + } +} diff --git a/src/plugins/condition/pluginSpec.js b/src/plugins/condition/pluginSpec.js new file mode 100644 index 0000000000..2af5533a9b --- /dev/null +++ b/src/plugins/condition/pluginSpec.js @@ -0,0 +1,48 @@ +import { createOpenMct } from "testTools"; +import ConditionPlugin from "./plugin"; + +let openmct; +let conditionDefinition; +let mockDomainObject; + +let mockConditionObject = { + name: 'Condition', + key: 'condition', + creatable: false +}; + +describe('the plugin', function () { + + beforeEach(() => { + openmct = createOpenMct(); + openmct.install(new ConditionPlugin()); + conditionDefinition = openmct.types.get('condition').definition; + }); + + it('defines an object type with the correct key', () => { + expect(conditionDefinition.key).toEqual(mockConditionObject.key); + }); + + it('is not creatable', () => { + expect(conditionDefinition.creatable).toEqual(mockConditionObject.creatable); + }); + + describe('the object', () => { + beforeEach(() => { + mockDomainObject = { + identifier: { + key: 'testConditionKey', + namespace: '' + }, + type: 'condition' + }; + + conditionDefinition.initialize(mockDomainObject); + }); + + it('initializes with an empty composition list', () => { + expect(mockDomainObject.composition instanceof Array).toBeTrue(); + expect(mockDomainObject.composition.length).toEqual(0); + }); + }); +}); diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index 26a0b7a34c..a6fbb3843e 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -49,7 +49,8 @@ define([ './webPage/plugin', './themes/espresso', './themes/maelstrom', - './themes/snow' + './themes/snow', + './condition/plugin' ], function ( _, UTCTimeSystem, @@ -79,7 +80,8 @@ define([ WebPagePlugin, Espresso, Maelstrom, - Snow + Snow, + ConditionPlugin ) { var bundleMap = { LocalStorage: 'platform/persistence/local', @@ -185,6 +187,7 @@ define([ plugins.Espresso = Espresso.default; plugins.Maelstrom = Maelstrom.default; plugins.Snow = Snow.default; + plugins.Condition = ConditionPlugin.default; return plugins; }); From 1f9d4708b381c385cc56d1ffd91c3cc8c76f83de Mon Sep 17 00:00:00 2001 From: Joshi Date: Wed, 18 Dec 2019 13:19:21 -0800 Subject: [PATCH 2/2] Adds copyright --- src/plugins/condition/pluginSpec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/plugins/condition/pluginSpec.js b/src/plugins/condition/pluginSpec.js index 2af5533a9b..68b0d4cc26 100644 --- a/src/plugins/condition/pluginSpec.js +++ b/src/plugins/condition/pluginSpec.js @@ -1,3 +1,25 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2019, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT 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 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. + *****************************************************************************/ + import { createOpenMct } from "testTools"; import ConditionPlugin from "./plugin";