blob: 2959ed652a603d9234c87dbe56b75d8ecf9813d6 [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();
64 const handleSave = jest.spyOn(DeployLoop.prototype,'handleSave');
65 LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => {
66 return Promise.resolve({
67 ok: true,
68 status: 200,
69 text: () => "OK"
70 });
71 });
72 LoopActionService.performAction = jest.fn().mockImplementation(() => {
73 return Promise.resolve({
74 ok: true,
75 status: 200,
76 json: () => {}
77 });
78 });
79 LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
80 return Promise.resolve({
81 ok: true,
82 status: 200,
83 json: () => {}
84 });
85 });
86 const jsdomAlert = window.alert;
87 window.alert = () => {};
88 const component = shallow(<DeployLoop history={historyMock}
89 loopCache={loopCache} updateLoopFunction={updateLoopFunction} />)
90
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([ '/']);
98 window.alert = jsdomAlert;
99 handleSave.mockClear();
100 });
101
102 it('Onchange event', () => {
103 const event = { target: { name: "location_id", value: "testLocation"} };
104 const component = shallow(<DeployLoop loopCache={loopCache}/>);
105 const forms = component.find('StateManager');
106
107 component.find('[name="location_id"]').simulate('change', event);
108 component.update();
109 expect(component.state('temporaryPropertiesJson').dcaeDeployParameters.location_id).toEqual("testLocation");
110 });
xuegao841ddaa2019-09-19 14:23:14 +0200111});