blob: 952e888671f7c4bd84a8c5c6b141db19b75a25ab [file] [log] [blame]
drveerendra684057e2019-11-11 19:37:39 -05001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
ash742683a83e2a2020-01-31 15:40:15 +00005 * Copyright (C) 2020 AT&T Intellectual Property. All rights
drveerendra684057e2019-11-11 19:37:39 -05006 * 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 ViewToscaPolicyModal from './ViewToscaPolicyModal';
26import { mount } from 'enzyme';
27
28
29describe('Verify ViewToscaPolicyModal', () => {
30 beforeEach(() => {
31 fetch.resetMocks();
32 });
33
34 it('Test API Successful', () => {
35 fetch.mockImplementationOnce(() => {
36 return Promise.resolve({
37 ok: true,
38 status: 200,
39 json: () => {
40 return Promise.resolve({
41 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +000042 "policyModelTosca":"TCA",
43 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
44 "version":"1.0.0",
45 "policyAcronym": "TCA",
46 "updatedDate": "2020-01-31T20:49:48.658795600Z",
47 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -050048 });
49 }
50 });
51 });
52 const component = shallow(<ViewToscaPolicyModal/>);
53 });
54
55 it('Test API Exception', () => {
56 fetch.mockImplementationOnce(() => {
57 return Promise.resolve({
58 ok: false,
59 status: 500,
60 json: () => {
61 return Promise.resolve({
62 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +000063 "policyModelTosca":"TCA",
64 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
65 "version":"1.0.0",
66 "policyAcronym": "TCA",
67 "updatedDate": "2020-01-31T20:49:48.658795600Z",
68 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -050069 });
70 }
71 });
72 });
73 const component = shallow(<ViewToscaPolicyModal/>);
74 });
75
76 it('Test API Rejection', () => {
77 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
78 setTimeout(
79 () =>
80 myMockFunc().catch(e => {
81 console.log(e);
82 }),
83 100
84 );
85 new Promise(resolve => setTimeout(resolve, 200));
86 const component = shallow(<ViewToscaPolicyModal/>);
87 expect(myMockFunc.mock.calls.length).toBe(1);
88 });
89
90
91 it('Test the tosca model view render method', () => {
92 fetch.mockImplementationOnce(() => {
93 return Promise.resolve({
94 ok: true,
95 status: 200,
96 json: () => {
97 return Promise.resolve({
98 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +000099 "policyModelTosca":"TCA",
100 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
101 "version":"1.0.0",
102 "policyAcronym": "TCA",
103 "updatedDate": "2020-01-31T20:49:48.658795600Z",
104 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500105 });
106 }
107 });
108 });
109 const component = shallow(<ViewToscaPolicyModal/>);
110 component.setState({ toscaNames: {
111 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000112 "policyModelTosca":"TCA",
113 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
114 "version":"1.0.0",
115 "policyAcronym": "TCA",
116 "updatedDate": "2020-01-31T20:49:48.658795600Z",
117 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500118 }
119 });
120 expect(component).toMatchSnapshot();
121 });
122
123 it('Test Table icons', () => {
124 fetch.mockImplementationOnce(() => {
125 return Promise.resolve({
126 ok: true,
127 status: 200,
128 json: () => {
129 return Promise.resolve({
130 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000131 "policyModelTosca":"TCA",
132 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
133 "version":"1.0.0",
134 "policyAcronym": "TCA",
135 "updatedDate": "2020-01-31T20:49:48.658795600Z",
136 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500137 });
138 }
139 });
140 });
141 const component = mount(<ViewToscaPolicyModal/>);
142 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
143 });
144
145 it('Test handleYamlContent', () => {
146 fetch.mockImplementationOnce(() => {
147 return Promise.resolve({
148 ok: true,
149 status: 200,
150 json: () => {
151 return Promise.resolve({
152 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000153 "policyModelTosca":"TCA",
154 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
155 "version":"1.0.0",
156 "policyAcronym":"TCA",
157 "updatedDate": "2020-01-31T20:49:48.658795600Z",
158 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500159 });
160 }
161 });
162 });
ash742683a83e2a2020-01-31 15:40:15 +0000163 const yamlContent = 'TCA Tosca model details';
drveerendra684057e2019-11-11 19:37:39 -0500164 const component = shallow(<ViewToscaPolicyModal/>);
165 component.find('[value="Please select Tosca model to view the details"]').prop('onChange')({ target: { value: yamlContent }});
166 expect(component.state('content')).toEqual(yamlContent);
167 });
168
169 it('Test handleClose', () => {
170 fetch.mockImplementationOnce(() => {
171 return Promise.resolve({
172 ok: true,
173 status: 200,
174 json: () => {
175 return Promise.resolve({
176 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000177 "policyModelTosca":"TCA",
178 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
179 "version":"1.0.0",
180 "policyAcronym": "TCA",
181 "updatedDate": "2020-01-31T20:49:48.658795600Z",
182 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500183 });
184 }
185 });
186 });
187 const historyMock = { push: jest.fn() };
188 const handleClose = jest.spyOn(ViewToscaPolicyModal.prototype,'handleClose');
189 const component = shallow(<ViewToscaPolicyModal history={historyMock} />)
190 component.find('[variant="secondary"]').prop('onClick')();
191 expect(handleClose).toHaveBeenCalledTimes(1);
192 expect(component.state('show')).toEqual(false);
193 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
194 handleClose.mockClear();
195 });
196});