blob: 055ad0e68bf7a9fa6accf5d20896cd065e85f9ae [file] [log] [blame]
xuegaofb4b25f2020-03-11 11:22:15 +01001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
6 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
23import React from 'react';
24import { mount } from 'enzyme';
25import ModifyLoopModal from './ModifyLoopModal';
26import LoopCache from '../../../api/LoopCache';
27import LoopService from '../../../api/LoopService';
28import PolicyToscaService from '../../../api/PolicyToscaService';
29
30describe('Verify ModifyLoopModal', () => {
31 beforeEach(() => {
32 PolicyToscaService.getToscaPolicyModels = jest.fn().mockImplementation(() => {
33 return Promise.resolve([{
34 "policyModelType":"test",
35 "policyAcronym":"test",
36 "version":"1.0.0",
37 "updatedBy":"",
38 "updatedDate":""
39 }]);
40 });
41 PolicyToscaService.getToscaPolicyModelYaml = jest.fn().mockImplementation(() => {
42 return Promise.resolve("OK");
43 });
44 })
45
46 const loopCache = new LoopCache({
47 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
48 "microServicePolicies": [{
49 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
50 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
51 "properties": {"domain": "measurementsForVfScaling"},
52 "shared": false,
53 "jsonRepresentation": {"schema": {}}
54 }],
55 "globalPropertiesJson": {
56 "dcaeDeployParameters": {
57 "testMs": {
58 "location_id": "",
59 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
60 }
61 }
62 }
63 });
64 const historyMock = { push: jest.fn() };
65 const flushPromises = () => new Promise(setImmediate);
66
67 it('Test handleClose', () => {
68 const handleClose = jest.spyOn(ModifyLoopModal.prototype,'handleClose');
69 const component = mount(<ModifyLoopModal history={historyMock} loopCache={loopCache}/>)
70
71 component.find('[variant="secondary"]').get(0).props.onClick();
72
73 expect(handleClose).toHaveBeenCalledTimes(1);
74 expect(component.state('show')).toEqual(false);
75 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
76 });
77
78 it('Test getToscaPolicyModelYaml', async () => {
79 const flushPromises = () => new Promise(setImmediate);
80 const component = mount(<ModifyLoopModal history={historyMock} loopCache={loopCache}/>)
81 component.setState({
82 "selectedRowData": {"tableData":{"id":0}}
83 });
84 const instance = component.instance();
85
86 instance.getToscaPolicyModelYaml("","1.0.0");
87 expect(component.state('content')).toEqual("Please select Tosca model to view the details");
88
89 instance.getToscaPolicyModelYaml("test","1.0.0");
90 await flushPromises();
91 expect(component.state('content')).toEqual("OK");
92
93 PolicyToscaService.getToscaPolicyModelYaml = jest.fn().mockImplementation(() => {
94 return Promise.resolve("");
95 });
96 instance.getToscaPolicyModelYaml("test","1.0.0");
97 await flushPromises();
98 expect(component.state('content')).toEqual("No Tosca model Yaml available");
99 });
100
101 it('Test handleYamlContent', async () => {
102 const component = mount(<ModifyLoopModal loopCache={loopCache}/>)
103 const instance = component.instance();
104
105 const event = {"target":{"value":"testValue"}}
106 instance.handleYamlContent(event);
107 expect(component.state('content')).toEqual("testValue");
108 });
109});