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 DeployLoop from './DeployLoop';
26 import LoopCache from '../../api/LoopCache';
27 import LoopActionService from '../../api/LoopActionService';
28 import LoopService from '../../api/LoopService';
30 describe('Verify DeployLoop', () => {
31 const loopCache = new LoopCache({
32 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
33 "globalPropertiesJson": {
34 "dcaeDeployParameters": {
36 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
41 it('Test the render method', () => {
42 const component = shallow(
43 <DeployLoop loopCache={loopCache}/>
46 expect(component).toMatchSnapshot();
49 it('Test handleClose', () => {
50 const historyMock = { push: jest.fn() };
51 const handleClose = jest.spyOn(DeployLoop.prototype,'handleClose');
52 const component = shallow(<DeployLoop history={historyMock} loopCache={loopCache}/>)
54 component.find('[variant="secondary"]').prop('onClick')();
56 expect(handleClose).toHaveBeenCalledTimes(1);
57 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
60 it('Test handleSave successful', async () => {
61 const flushPromises = () => new Promise(setImmediate);
62 const historyMock = { push: jest.fn() };
63 const updateLoopFunction = jest.fn();
64 const showAlert = jest.fn();
65 const handleSave = jest.spyOn(DeployLoop.prototype,'handleSave');
66 LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => {
67 return Promise.resolve({
73 LoopActionService.performAction = jest.fn().mockImplementation(() => {
74 return Promise.resolve({
80 LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
81 return Promise.resolve({
88 const component = shallow(<DeployLoop history={historyMock}
89 loopCache={loopCache} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />)
91 component.find('[variant="primary"]').prop('onClick')();
92 await flushPromises();
95 expect(handleSave).toHaveBeenCalledTimes(1);
96 expect(component.state('show')).toEqual(false);
97 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
98 handleSave.mockClear();
101 it('Onchange event', () => {
102 const event = { target: { name: "location_id", value: "testLocation"} };
103 const component = shallow(<DeployLoop loopCache={loopCache}/>);
104 const forms = component.find('StateManager');
106 component.find('[name="location_id"]').simulate('change', event);
108 expect(component.state('temporaryPropertiesJson').dcaeDeployParameters.location_id).toEqual("testLocation");