2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
23 import React from 'react';
24 import { shallow } from 'enzyme';
25 import LoopSvg from './LoopSvg';
26 import LoopCache from '../../../api/LoopCache';
27 import LoopService from '../../../api/LoopService';
29 describe('Verify LoopSvg', () => {
30 const loopCache = new LoopCache({
31 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
32 "microServicePolicies": [{
33 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
34 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
35 "properties": {"domain": "measurementsForVfScaling"},
37 "jsonRepresentation": {"schema": {}}
39 "operationalPolicies": [{
40 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
41 "configurationsJson": {
43 "operational_policy": {
51 it('Test the render method no loopName', () => {
52 const localLoopCache = new LoopCache({
53 "microServicePolicies": [{
54 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
55 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
56 "properties": {"domain": "measurementsForVfScaling"},
58 "jsonRepresentation": {"schema": {}}
61 const component = shallow(
62 <LoopSvg.WrappedComponent loopCache={localLoopCache}/>
65 expect(component).toMatchSnapshot();
68 it('Test the render method', () => {
69 const component = shallow(
70 <LoopSvg.WrappedComponent loopCache={loopCache}/>
73 expect(component).toMatchSnapshot();
76 it('Test the render method svg not empty', async () => {
77 const flushPromises = () => new Promise(setImmediate);
78 LoopService.getSvg = jest.fn().mockImplementation(() => {
79 return Promise.resolve("<svg><text test</text></svg>");
81 const component = shallow(
82 <LoopSvg.WrappedComponent loopCache={loopCache}/>
84 await flushPromises();
85 expect(component).toMatchSnapshot();
88 it('Test handleSvgClick', () => {
89 const historyMock = { push: jest.fn() };
91 const component = shallow(
92 <LoopSvg.WrappedComponent loopCache={loopCache} history={historyMock}/>
94 let dummyElement = document.createElement('div');
95 dummyElement.setAttribute("data-element-id","TCA_h2NMX_v1_0_ResourceInstanceName1_tca");
97 const event = { target: { parentNode: { parentNode:{ parentNode: dummyElement }}}};
99 component.simulate('click', event);
102 expect(historyMock.push.mock.calls[0]).toEqual([ '/policyModal/MICRO-SERVICE-POLICY/TCA_h2NMX_v1_0_ResourceInstanceName1_tca']);
104 //click operational policy
105 dummyElement.setAttribute("data-element-id","OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca");
106 const event2 = { target: { parentNode: { parentNode:{ parentNode: dummyElement }}}};
108 component.simulate('click', event2);
111 expect(historyMock.push.mock.calls[1]).toEqual([ '/policyModal/OPERATIONAL-POLICY/OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca']);
114 it('Test componentWillReceiveProps method', () => {
115 const localLoopCache = new LoopCache({
116 "microServicePolicies": [{
117 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
118 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
119 "properties": {"domain": "measurementsForVfScaling"},
121 "jsonRepresentation": {"schema": {}}
124 const component = shallow(
125 <LoopSvg.WrappedComponent loopCache={localLoopCache}/>
128 expect(component.state('componentModalMapping').size).toEqual(1);
130 component.setProps({loopCache: loopCache});
131 expect(component.state('componentModalMapping').size).toEqual(2);