blob: 9b74fe76a4bdeea12ac4946702d8a862f06ebae1 [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 LoopProperties from './LoopProperties';
26import LoopCache from '../../api/LoopCache';
xuegao564fdb02019-10-02 11:18:10 +020027import LoopService from '../../api/LoopService';
xuegao841ddaa2019-09-19 14:23:14 +020028
29describe('Verify LoopProperties', () => {
30 const loopCache = new LoopCache({
31 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
32 "globalPropertiesJson": {
33 "dcaeDeployParameters": {
34 "location_id": "",
35 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
36 }
37 }
38 });
39
40 it('Test the render method', () => {
41 const component = shallow(
42 <LoopProperties loopCache={loopCache}/>
43 )
44 component.setState({ show: true,
45 temporaryPropertiesJson: {
46 "dcaeDeployParameters": {
47 "location_id": "",
48 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
49 }
50 }
51 });
52
53 expect(component.state('temporaryPropertiesJson')).toEqual({
54 "dcaeDeployParameters": {
55 "location_id": "",
56 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"}
57 });
58 expect(component.state('show')).toEqual(true);
59
60 expect(component).toMatchSnapshot();
61 });
xuegao564fdb02019-10-02 11:18:10 +020062
63 it('Test handleClose', () => {
64 const historyMock = { push: jest.fn() };
65 const handleClose = jest.spyOn(LoopProperties.prototype,'handleClose');
66 const component = shallow(<LoopProperties history={historyMock} loopCache={loopCache}/>)
67
68 component.find('[variant="secondary"]').prop('onClick')();
69
70 expect(handleClose).toHaveBeenCalledTimes(1);
71 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
72 });
73
74 it('Test handleSave successful', async () => {
75 const flushPromises = () => new Promise(setImmediate);
76 const historyMock = { push: jest.fn() };
77 const loadLoopFunction = jest.fn();
78 const handleSave = jest.spyOn(LoopProperties.prototype,'handleSave');
79 LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => {
80 return Promise.resolve({
81 ok: true,
82 status: 200,
83 text: () => "OK"
84 });
85 });
86
87 const component = shallow(<LoopProperties history={historyMock}
88 loopCache={loopCache} loadLoopFunction={loadLoopFunction} />)
89
90 component.find('[variant="primary"]').prop('onClick')();
91 await flushPromises();
92 component.update();
93
94 expect(handleSave).toHaveBeenCalledTimes(1);
95 expect(component.state('show')).toEqual(false);
96 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
97 });
98
99 it('Onchange event', () => {
100 const event = {target:{name:"dcaeDeployParameters", value:"{\"location_id\": \"testLocation\",\"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName1_tca\"}"}};
101 const component = shallow(<LoopProperties loopCache={loopCache}/>);
102
103 component.find('FormControl').simulate('change', event);
104 component.update();
105
106 expect(component.state('temporaryPropertiesJson').dcaeDeployParameters.location_id).toEqual("testLocation");
107 });
xuegao841ddaa2019-09-19 14:23:14 +0200108});