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 DeployLoopModal from './DeployLoopModal';
26 import LoopCache from '../../../api/LoopCache';
27 import LoopActionService from '../../../api/LoopActionService';
28 import LoopService from '../../../api/LoopService';
30 describe('Verify DeployLoopModal', () => {
31 const loopCache = new LoopCache({
32 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
33 "globalPropertiesJson": {
34 "dcaeDeployParameters": {
37 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
43 it('Test the render method', () => {
44 const component = shallow(
45 <DeployLoopModal loopCache={loopCache}/>
48 expect(component).toMatchSnapshot();
51 it('Test handleClose', () => {
52 const historyMock = { push: jest.fn() };
53 const handleClose = jest.spyOn(DeployLoopModal.prototype,'handleClose');
54 const component = shallow(<DeployLoopModal history={historyMock} loopCache={loopCache}/>)
56 component.find('[variant="secondary"]').prop('onClick')();
58 expect(handleClose).toHaveBeenCalledTimes(1);
59 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
62 it('Test handleSave successful', async () => {
63 const flushPromises = () => new Promise(setImmediate);
64 const historyMock = { push: jest.fn() };
65 const updateLoopFunction = jest.fn();
66 const showSucAlert = jest.fn();
67 const showFailAlert = jest.fn();
68 const handleSave = jest.spyOn(DeployLoopModal.prototype,'handleSave');
69 LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => {
70 return Promise.resolve({
76 LoopActionService.performAction = jest.fn().mockImplementation(() => {
77 return Promise.resolve({
83 LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
84 return Promise.resolve({
91 const component = shallow(<DeployLoopModal history={historyMock}
92 loopCache={loopCache} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />)
94 component.find('[variant="primary"]').prop('onClick')();
95 await flushPromises();
98 expect(handleSave).toHaveBeenCalledTimes(1);
99 expect(component.state('show')).toEqual(false);
100 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
101 handleSave.mockClear();
104 it('Onchange event', () => {
105 const event = { target: { name: "location_id", value: "testLocation"} };
106 const component = shallow(<DeployLoopModal loopCache={loopCache}/>);
108 component.find('[name="location_id"]').simulate('change', event);
110 expect(component.state('temporaryPropertiesJson').dcaeDeployParameters.testMs.location_id).toEqual("testLocation");