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": {
42 "operational_policy": {
50 it('Test the render method no loopName', () => {
51 const localLoopCache = new LoopCache({
52 "microServicePolicies": [{
53 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
54 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
55 "properties": {"domain": "measurementsForVfScaling"},
57 "jsonRepresentation": {"schema": {}}
60 const component = shallow(
61 <LoopSvg.WrappedComponent loopCache={localLoopCache}/>
64 expect(component).toMatchSnapshot();
67 it('Test the render method', () => {
68 const component = shallow(
69 <LoopSvg.WrappedComponent loopCache={loopCache}/>
72 expect(component).toMatchSnapshot();
75 it('Test the render method svg not empty', async () => {
76 const flushPromises = () => new Promise(setImmediate);
77 LoopService.getSvg = jest.fn().mockImplementation(() => {
78 return Promise.resolve("<svg><text test</text></svg>");
80 const component = shallow(
81 <LoopSvg.WrappedComponent loopCache={loopCache}/>
83 await flushPromises();
84 expect(component).toMatchSnapshot();
87 it('Test handleSvgClick', () => {
88 const historyMock = { push: jest.fn() };
90 const component = shallow(
91 <LoopSvg.WrappedComponent loopCache={loopCache} history={historyMock}/>
93 let dummyElement = document.createElement('div');
94 dummyElement.setAttribute("data-element-id","TCA_h2NMX_v1_0_ResourceInstanceName1_tca");
96 const event = { target: { parentNode: { parentNode:{ parentNode: dummyElement }}}};
98 component.simulate('click', event);
101 expect(historyMock.push.mock.calls[0]).toEqual([ '/policyModal/MICRO-SERVICE-POLICY/TCA_h2NMX_v1_0_ResourceInstanceName1_tca']);
103 //click operational policy
104 dummyElement.setAttribute("data-element-id","OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca");
105 const event2 = { target: { parentNode: { parentNode:{ parentNode: dummyElement }}}};
107 component.simulate('click', event2);
110 expect(historyMock.push.mock.calls[1]).toEqual([ '/policyModal/OPERATIONAL-POLICY/OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca']);
113 it('Test componentWillReceiveProps method', () => {
114 const localLoopCache = new LoopCache({
115 "microServicePolicies": [{
116 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
117 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
118 "properties": {"domain": "measurementsForVfScaling"},
120 "jsonRepresentation": {"schema": {}}
123 const component = shallow(
124 <LoopSvg.WrappedComponent loopCache={localLoopCache}/>
127 expect(component.state('componentModalMapping').size).toEqual(1);
129 component.setProps({loopCache: loopCache});
130 expect(component.state('componentModalMapping').size).toEqual(2);