aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/images/user-guide/create-loop.pngbin46065 -> 54351 bytes
-rw-r--r--docs/images/user-guide/loop-menu.pngbin43472 -> 38587 bytes
-rwxr-xr-xdocs/images/user-guide/open-menu-prop.pngbin37343 -> 59422 bytes
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java69
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java30
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java106
-rw-r--r--src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java55
-rw-r--r--ui-react/src/api/LoopCache.test.js98
-rw-r--r--ui-react/src/api/LoopCache_mokeLoopJsonCache.json6
-rw-r--r--ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js137
-rw-r--r--ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap141
11 files changed, 634 insertions, 8 deletions
diff --git a/docs/images/user-guide/create-loop.png b/docs/images/user-guide/create-loop.png
index 20b9f05d..40cdb4c3 100644
--- a/docs/images/user-guide/create-loop.png
+++ b/docs/images/user-guide/create-loop.png
Binary files differ
diff --git a/docs/images/user-guide/loop-menu.png b/docs/images/user-guide/loop-menu.png
index 658359e0..b6056349 100644
--- a/docs/images/user-guide/loop-menu.png
+++ b/docs/images/user-guide/loop-menu.png
Binary files differ
diff --git a/docs/images/user-guide/open-menu-prop.png b/docs/images/user-guide/open-menu-prop.png
index c07b2256..046e2a3d 100755
--- a/docs/images/user-guide/open-menu-prop.png
+++ b/docs/images/user-guide/open-menu-prop.png
Binary files differ
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java
new file mode 100644
index 00000000..29f5a1da
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.tosca.update;
+
+import junit.framework.TestCase;
+import org.onap.clamp.clds.tosca.update.templates.JsonTemplateField;
+
+public class JsonTemplateFieldTest extends TestCase {
+
+ JsonTemplateField field1 = new JsonTemplateField("type", "testType", true, true);
+ JsonTemplateField field2 = new JsonTemplateField("type");
+ JsonTemplateField field3 = new JsonTemplateField("type", "testType1", true, true);
+ JsonTemplateField field4 = new JsonTemplateField("type", "testType", false, true);
+ JsonTemplateField field5 = new JsonTemplateField("type", "testType", true, false);
+ JsonTemplateField field6 = new JsonTemplateField("type", "testType", true, true);
+
+ /**
+ * Test fieldsEqual method.
+ */
+ public void testFieldsEqualsMethod() {
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field3));
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field4));
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field5));
+ assertTrue(JsonTemplateField.fieldsEquals(field1,field6));
+ }
+
+ /**
+ * Test equals method.
+ */
+ public void testEqualsMethod() {
+ assertTrue(field1.equals(field2));
+ assertTrue(field1.equals(field3));
+ assertTrue(field1.equals(field4));
+ assertTrue(field1.equals(field5));
+ assertTrue(field1.equals(field6));
+ }
+
+ /**
+ * Test compareWithField method.
+ */
+ public void testCompareWithFieldMethod() {
+ assertFalse(field1.compareWithField(field2));
+ assertFalse(field1.compareWithField(field3));
+ assertFalse(field1.compareWithField(field4));
+ assertFalse(field1.compareWithField(field5));
+ assertTrue(field1.equals(field6));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
index fab3030c..dc736a48 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
@@ -32,20 +32,38 @@ import org.onap.clamp.clds.tosca.update.templates.JsonTemplateField;
public class JsonTemplateTest extends TestCase {
+ JsonTemplate toTest = new JsonTemplate("toTest");
+ List<JsonTemplateField>
+ jsonTemplateFields = new ArrayList<>(
+ Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
+ new JsonTemplateField(
+ "enum")));
+
/**
* Test check failed.
*/
public void testCheckFields() {
- JsonTemplate toTest = new JsonTemplate("toTest");
- List<JsonTemplateField>
- jsonTemplateFields = new ArrayList<>(
- Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
- new JsonTemplateField(
- "enum")));
toTest.setJsonTemplateFields(jsonTemplateFields);
JsonTemplate reference = new JsonTemplate("toTest");
reference.setJsonTemplateFields(jsonTemplateFields);
assertTrue(toTest.checkFields(reference));
}
+ /**
+ * Test other methods.
+ */
+ public void testOtherFields() {
+ toTest.setJsonTemplateFields(jsonTemplateFields);
+ toTest.addField(new JsonTemplateField("moreField"));
+ toTest.setVisibility("moreField", true);
+ toTest.setStatic("moreField", true);
+ toTest.updateValueField("moreField", "testValue");
+
+ assertTrue(toTest.isVisible("moreField"));
+ assertTrue(toTest.getSpecificField("moreField").getValue().equals("testValue"));
+ assertTrue(toTest.fieldStaticStatus("moreField"));
+ assertTrue(toTest.toString()
+ .equals(" templateFields : [type null null null, description null null null, "
+ + "enum null null null, moreField testValue true true]"));
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java b/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java
new file mode 100644
index 00000000..e5b64c99
--- /dev/null
+++ b/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.loop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.onap.clamp.loop.template.LoopElementModel;
+import org.onap.clamp.loop.template.LoopTemplate;
+import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
+import org.onap.clamp.loop.template.PolicyModel;
+
+
+public class LoopTemplateLoopElementModelTest {
+
+ private LoopElementModel loopElementModel = getLoopElementModel("yaml", "microService1",
+ getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"));
+ private LoopTemplate loopTemplate = getLoopTemplate("templateName", "yaml", "svg", 1);
+
+ private LoopElementModel getLoopElementModel(String yaml, String name, PolicyModel policyModel) {
+ LoopElementModel model = new LoopElementModel();
+ model.setBlueprint(yaml);
+ model.setName(name);
+ model.addPolicyModel(policyModel);
+ model.setLoopElementType("OPERATIONAL_POLICY");
+ return model;
+ }
+
+ private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
+ String policyVariant) {
+ return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
+ }
+
+ private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation,
+ Integer maxInstancesAllowed) {
+ LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null);
+ template.addLoopElementModel(loopElementModel);
+ return template;
+ }
+
+ /**
+ * This tests compareTo method.
+ */
+ @Test
+ public void compareToTest() {
+ LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
+ LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
+ assertThat(model1.compareTo(model2)).isEqualTo(1);
+
+ model1.setFlowOrder(2);
+ assertThat(model1.compareTo(model2)).isEqualTo(-1);
+
+ model2.setFlowOrder(3);
+ assertThat(model1.compareTo(model2)).isEqualTo(1);
+ }
+
+ /**
+ * This tests equals method.
+ */
+ @Test
+ public void equalsTest() {
+ LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
+ LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
+
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setLoopTemplate(loopTemplate);
+ assertThat(model1.equals(model2)).isFalse();
+ model2.setLoopTemplate(loopTemplate);
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setLoopElementModel(loopElementModel);
+ assertThat(model1.equals(model2)).isFalse();
+ model2.setLoopElementModel(loopElementModel);
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setFlowOrder(1);
+ assertThat(model1.equals(model2)).isTrue();
+ model2.setFlowOrder(2);
+ assertThat(model1.equals(model2)).isTrue();
+ }
+
+}
diff --git a/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java b/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java
new file mode 100644
index 00000000..413ce60a
--- /dev/null
+++ b/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.policy.pdpgroup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import org.junit.Test;
+
+public class PolicyModelKeyTest {
+
+ @Test
+ public void testEqualsMethod() throws IOException {
+ PolicyModelKey key1 = new PolicyModelKey("name1","1.0.0");
+ PolicyModelKey key2 = new PolicyModelKey(null,"1.0.0");
+ PolicyModelKey key3 = new PolicyModelKey("name1",null);
+
+ assertThat(key1.equals(null)).isFalse();
+ assertThat(key1.equals("key2")).isFalse();
+
+ assertThat(key2.equals(key1)).isFalse();
+ assertThat(key3.equals(key1)).isFalse();
+
+ PolicyModelKey key4 = new PolicyModelKey("name2","1.0.0");
+ PolicyModelKey key5 = new PolicyModelKey("name1","2.0.0");
+ assertThat(key1.equals(key4)).isFalse();
+ assertThat(key1.equals(key5)).isFalse();
+
+ PolicyModelKey key6 = new PolicyModelKey("name(.*)","1.0.0");
+ PolicyModelKey key7 = new PolicyModelKey("name1","1.0.0");
+ assertThat(key1.equals(key6)).isTrue();
+ assertThat(key1.equals(key7)).isTrue();
+ }
+}
diff --git a/ui-react/src/api/LoopCache.test.js b/ui-react/src/api/LoopCache.test.js
index b0eef755..3ae08170 100644
--- a/ui-react/src/api/LoopCache.test.js
+++ b/ui-react/src/api/LoopCache.test.js
@@ -39,7 +39,9 @@ describe('Verify LoopCache functions', () => {
"policies": []
}
},
- "jsonRepresentation": {
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
+ "jsonRepresentation": {
"schema": {}
}
}];
@@ -54,7 +56,9 @@ describe('Verify LoopCache functions', () => {
"controlLoop": {},
"policies": []
}
- }
+ },
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
}];
expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy);
});
@@ -92,6 +96,9 @@ describe('Verify LoopCache functions', () => {
"modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
"configurationsJson": {"domain": "measurementsForVfScaling"},
"shared": false,
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
+ "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}},
"jsonRepresentation": {"schema": {}}
};
expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
@@ -180,6 +187,84 @@ describe('Verify LoopCache functions', () => {
expect(loopCache.getComponentStates()).toStrictEqual(component);
});
+ it('getOperationalPolicyForName', () => {
+ const opPolicy = {
+ "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
+ "configurationsJson": {
+ "operational_policy": {
+ "controlLoop": {},
+ "policies": []
+ }
+ },
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
+ "jsonRepresentation": {
+ "schema": {}
+ }
+ };
+ expect(loopCache.getOperationalPolicyForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicy);
+ expect(loopCache.getOperationalPolicyForName("Not_Exist")).toBeNull();
+ });
+
+ it('getOperationalPolicyPropertiesForName', () => {
+ const opPolicyJson = {
+ "operational_policy": {
+ "controlLoop": {},
+ "policies": []
+ }};
+ expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicyJson);
+ expect(loopCache.getOperationalPolicyPropertiesForName("Not_Exist")).toBeNull();
+ });
+
+ it('getOperationalPolicyJsonRepresentationForName', () => {
+ const opPolicySchema = {
+ "schema": {}
+ };
+ expect(loopCache.getOperationalPolicyJsonRepresentationForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicySchema);
+ expect(loopCache.getOperationalPolicyJsonRepresentationForName("Not_Exist")).toBeNull();
+ });
+
+ it('getOperationalPolicySupportedPdpGroup', () => {
+ expect(loopCache.getOperationalPolicySupportedPdpGroup("Not_Exist")).toStrictEqual([]);
+ });
+
+ it('getOperationalPolicyPdpGroup', () => {
+ expect(loopCache.getOperationalPolicyPdpGroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest");
+ expect(loopCache.getOperationalPolicyPdpGroup("Not_Exist")).toBeNull();
+ });
+
+ it('getOperationalPolicyPdpSubgroup', () => {
+ expect(loopCache.getOperationalPolicyPdpSubgroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest");
+ expect(loopCache.getOperationalPolicyPdpSubgroup("Not_Exist")).toBeNull();
+ });
+
+ it('getMicroServiceSupportedPdpGroup', () => {
+ expect(loopCache.getMicroServiceSupportedPdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("supportedPdpGroupsTest");
+ expect(loopCache.getMicroServiceSupportedPdpGroup("Not_Exist")).toStrictEqual([]);
+ });
+
+ it('getMicroServicePdpGroup', () => {
+ expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest");
+ expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull();
+ });
+
+ it('getMicroServicePdpSubgroup', () => {
+ expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest");
+ expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull();
+ });
+
+ it('getMicroServiceJsonRepresentationForName', () => {
+ const msPolicySchema = {
+ "schema": {}
+ };
+ expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msPolicySchema);
+ expect(loopCache.getMicroServiceJsonRepresentationForName("Not_Exist")).toBeNull();
+ });
+
+ it('getTemplateName', () => {
+ expect(loopCache.getTemplateName()).toStrictEqual("loopTemplateTest");
+ });
+
it('updateGlobalProperties', () => {
const newGlobalProps = {
"dcaeDeployParameters": {
@@ -208,4 +293,13 @@ describe('Verify LoopCache functions', () => {
loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties);
expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties);
});
+
+ it('updateMicroServicePdpGroup', () => {
+ const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"};
+ loopCache.updateMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", "pdpGroupTest1", "pdpSubgroupTest1");
+ expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest1");
+ expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull();
+ expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest1");
+ expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull();
+ });
});
diff --git a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json b/ui-react/src/api/LoopCache_mokeLoopJsonCache.json
index 788306b8..cb9ed87b 100644
--- a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json
+++ b/ui-react/src/api/LoopCache_mokeLoopJsonCache.json
@@ -8,6 +8,7 @@
"policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
}
},
+ "loopTemplate": {"name": "loopTemplateTest"},
"modelService": {
"serviceDetails": {
"serviceType": "",
@@ -93,6 +94,8 @@
"policies": []
}
},
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
"jsonRepresentation": {
"schema": {}
}
@@ -104,6 +107,9 @@
"modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
"configurationsJson": {"domain": "measurementsForVfScaling"},
"shared": false,
+ "pdpGroup": "pdpGroupTest",
+ "pdpSubgroup": "pdpSubgroupTest",
+ "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}},
"jsonRepresentation": {"schema": {}}
}
],
diff --git a/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js b/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js
new file mode 100644
index 00000000..18ec6fdc
--- /dev/null
+++ b/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+import React from 'react';
+import { shallow } from 'enzyme';
+import CreateLoopModal from './CreateLoopModal';
+import LoopService from '../../../api/LoopService';
+import TemplateService from '../../../api/TemplateService';
+
+describe('Verify CreateLoopModal', () => {
+
+ it('Test the render method', async () => {
+ const flushPromises = () => new Promise(setImmediate);
+ TemplateService.getTemplateNames = jest.fn().mockImplementation(() => {
+ return Promise.resolve(["template1","template2"]);
+ });
+
+ const component = shallow(<CreateLoopModal/>);
+ expect(component).toMatchSnapshot();
+ await flushPromises();
+ component.update();
+
+ expect(component.state('templateNames')).toStrictEqual([{"label": "template1", "value": "template1"}, {"label": "template2", "value": "template2"}]);
+ });
+
+ it('handleDropdownListChange event', async () => {
+ const flushPromises = () => new Promise(setImmediate);
+ const event = {value: 'template1'};
+ TemplateService.getBlueprintMicroServiceTemplateSvg = jest.fn().mockImplementation(() => {
+ return Promise.resolve("");
+ });
+
+ const component = shallow(<CreateLoopModal/>);
+ component.find('StateManager').simulate('change', event);
+ await flushPromises();
+ component.update();
+ expect(component.state('chosenTemplateName')).toEqual("template1");
+ expect(component.state('content')).toEqual("Error1");
+
+ TemplateService.getBlueprintMicroServiceTemplateSvg = jest.fn().mockImplementation(() => {
+ return Promise.resolve("svgContentTest");
+ });
+ component.find('StateManager').simulate('change', {value: 'template2'});
+ await flushPromises();
+ component.update();
+ expect(component.state('chosenTemplateName')).toEqual("template2");
+ expect(component.state('content')).toEqual("svgContentTest");
+ });
+
+
+
+ it('handleModelName event', () => {
+ const event = {target: {value : "model1"} };
+ const component = shallow(<CreateLoopModal/>);
+ component.find('input').simulate('change', event);
+ component.update();
+ expect(component.state('modelName')).toEqual("model1");
+ });
+
+
+ it('Test handleClose', () => {
+ const historyMock = { push: jest.fn() };
+ const handleClose = jest.spyOn(CreateLoopModal.prototype,'handleClose');
+ const component = shallow(<CreateLoopModal history={historyMock} />)
+
+ component.find('[variant="secondary"]').prop('onClick')();
+
+ expect(handleClose).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
+
+ handleClose.mockClear();
+ });
+
+ it('Test handleCreate Fail', () => {
+ const handleCreate = jest.spyOn(CreateLoopModal.prototype,'handleCreate');
+ const component = shallow(<CreateLoopModal/>)
+
+ component.find('[variant="primary"]').prop('onClick')();
+
+ expect(handleCreate).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(true);
+
+ handleCreate.mockClear();
+ });
+
+ it('Test handleCreate Suc', async () => {
+ const flushPromises = () => new Promise(setImmediate);
+ const historyMock = { push: jest.fn() };
+ const loadLoopFunction = jest.fn();
+
+ LoopService.createLoop = jest.fn().mockImplementation(() => {
+ return Promise.resolve({
+ ok: true,
+ status: 200,
+ json: () => {}
+ });
+ });
+
+ const handleCreate = jest.spyOn(CreateLoopModal.prototype,'handleCreate');
+ const component = shallow(<CreateLoopModal history={historyMock} loadLoopFunction={loadLoopFunction}/>)
+ component.setState({
+ modelName: "modelNameTest",
+ chosenTemplateName: "template1"
+ });
+
+ component.find('[variant="primary"]').prop('onClick')();
+ await flushPromises();
+ component.update();
+
+ expect(handleCreate).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
+
+ handleCreate.mockClear();
+ });
+
+});
diff --git a/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap b/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap
new file mode 100644
index 00000000..305c87bf
--- /dev/null
+++ b/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap
@@ -0,0 +1,141 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Verify CreateLoopModal Test the render method 1`] = `
+<Styled(Bootstrap(Modal))
+ backdrop="static"
+ keyboard={false}
+ onHide={[Function]}
+ show={true}
+ size="xl"
+>
+ <ModalHeader
+ closeButton={true}
+ closeLabel="Close"
+ >
+ <ModalTitle>
+ Create Model
+ </ModalTitle>
+ </ModalHeader>
+ <ModalBody>
+ <FormGroup
+ as={
+ Object {
+ "$$typeof": Symbol(react.forward_ref),
+ "defaultProps": Object {
+ "noGutters": false,
+ },
+ "render": [Function],
+ }
+ }
+ controlId="formPlaintextEmail"
+ >
+ <FormLabel
+ column={true}
+ sm="2"
+ srOnly={false}
+ >
+ Template Name:
+ </FormLabel>
+ <Col
+ sm="10"
+ >
+ <StateManager
+ defaultInputValue=""
+ defaultMenuIsOpen={false}
+ defaultValue={null}
+ onChange={[Function]}
+ options={Array []}
+ />
+ </Col>
+ </FormGroup>
+ <FormGroup
+ as={
+ Object {
+ "$$typeof": Symbol(react.forward_ref),
+ "defaultProps": Object {
+ "noGutters": false,
+ },
+ "render": [Function],
+ }
+ }
+ controlId="formSvgPreview"
+ style={
+ Object {
+ "alignItems": "center",
+ }
+ }
+ >
+ <FormLabel
+ column={true}
+ sm="2"
+ srOnly={false}
+ >
+ Model Preview:
+ </FormLabel>
+ <Col
+ sm="10"
+ >
+ <styled.svg
+ dangerouslySetInnerHTML={
+ Object {
+ "__html": "",
+ }
+ }
+ value=""
+ />
+ </Col>
+ </FormGroup>
+ <FormGroup
+ as={
+ Object {
+ "$$typeof": Symbol(react.forward_ref),
+ "defaultProps": Object {
+ "noGutters": false,
+ },
+ "render": [Function],
+ }
+ }
+ controlId="formPlaintextEmail"
+ >
+ <FormLabel
+ column={true}
+ sm="2"
+ srOnly={false}
+ >
+ Model Name:
+ </FormLabel>
+ <input
+ onChange={[Function]}
+ style={
+ Object {
+ "marginLeft": "1em",
+ "width": "50%",
+ }
+ }
+ type="text"
+ value=""
+ />
+ </FormGroup>
+ </ModalBody>
+ <ModalFooter>
+ <Button
+ active={false}
+ disabled={false}
+ onClick={[Function]}
+ type="null"
+ variant="secondary"
+ >
+ Cancel
+ </Button>
+ <Button
+ active={false}
+ disabled={false}
+ onClick={[Function]}
+ type="submit"
+ variant="primary"
+ >
+ Create
+ </Button>
+ </ModalFooter>
+</Styled(Bootstrap(Modal))>
+`;