blob: 44bc7837980032203f63a75bb3dfcfaf4c84f3a4 [file] [log] [blame]
xuegao841ddaa2019-09-19 14:23:14 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 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 { shallow } from 'enzyme';
25import DeployLoop from './DeployLoop';
26import LoopCache from '../../api/LoopCache';
xuegao564fdb02019-10-02 11:18:10 +020027import LoopActionService from '../../api/LoopActionService';
28import LoopService from '../../api/LoopService';
xuegao841ddaa2019-09-19 14:23:14 +020029
30describe('Verify DeployLoop', () => {
31 const loopCache = new LoopCache({
32 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
33 "globalPropertiesJson": {
34 "dcaeDeployParameters": {
35 "location_id": "",
36 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
37 }
38 }
39 });
40
41 it('Test the render method', () => {
42 const component = shallow(
43 <DeployLoop loopCache={loopCache}/>
44 )
45
46 expect(component).toMatchSnapshot();
47 });
xuegao564fdb02019-10-02 11:18:10 +020048
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}/>)
53
54 component.find('[variant="secondary"]').prop('onClick')();
55
56 expect(handleClose).toHaveBeenCalledTimes(1);
57 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
58 });
59
60 it('Test handleSave successful', async () => {
61 const flushPromises = () => new Promise(setImmediate);
62 const historyMock = { push: jest.fn() };
63 const updateLoopFunction = jest.fn();
xuegao0efeb6b2019-10-07 14:36:34 +020064 const showAlert = jest.fn();
xuegao564fdb02019-10-02 11:18:10 +020065 const handleSave = jest.spyOn(DeployLoop.prototype,'handleSave');
66 LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => {
67 return Promise.resolve({
68 ok: true,
69 status: 200,
70 text: () => "OK"
71 });
72 });
73 LoopActionService.performAction = jest.fn().mockImplementation(() => {
74 return Promise.resolve({
75 ok: true,
76 status: 200,
77 json: () => {}
78 });
79 });
80 LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
81 return Promise.resolve({
82 ok: true,
83 status: 200,
84 json: () => {}
85 });
86 });
xuegao0efeb6b2019-10-07 14:36:34 +020087
xuegao564fdb02019-10-02 11:18:10 +020088 const component = shallow(<DeployLoop history={historyMock}
xuegao0efeb6b2019-10-07 14:36:34 +020089 loopCache={loopCache} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />)
xuegao564fdb02019-10-02 11:18:10 +020090
91 component.find('[variant="primary"]').prop('onClick')();
92 await flushPromises();
93 component.update();
94
95 expect(handleSave).toHaveBeenCalledTimes(1);
96 expect(component.state('show')).toEqual(false);
97 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
xuegao564fdb02019-10-02 11:18:10 +020098 handleSave.mockClear();
99 });
100
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');
105
106 component.find('[name="location_id"]').simulate('change', event);
107 component.update();
108 expect(component.state('temporaryPropertiesJson').dcaeDeployParameters.location_id).toEqual("testLocation");
109 });
xuegao841ddaa2019-09-19 14:23:14 +0200110});