blob: a599cec04a7b8b4b1d4cac33c6b6ee31074368ec [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 => {
JulienBe0cde2b52020-04-03 13:21:13 +020081 console.info(e);
drveerendra684057e2019-11-11 19:37:39 -050082 }),
83 100
84 );
drveerendra684057e2019-11-11 19:37:39 -050085 const component = shallow(<ViewToscaPolicyModal/>);
86 expect(myMockFunc.mock.calls.length).toBe(1);
87 });
88
89
90 it('Test the tosca model view render method', () => {
91 fetch.mockImplementationOnce(() => {
92 return Promise.resolve({
93 ok: true,
94 status: 200,
95 json: () => {
96 return Promise.resolve({
97 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +000098 "policyModelTosca":"TCA",
99 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
100 "version":"1.0.0",
101 "policyAcronym": "TCA",
102 "updatedDate": "2020-01-31T20:49:48.658795600Z",
103 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500104 });
105 }
106 });
107 });
108 const component = shallow(<ViewToscaPolicyModal/>);
109 component.setState({ toscaNames: {
110 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000111 "policyModelTosca":"TCA",
112 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
113 "version":"1.0.0",
114 "policyAcronym": "TCA",
115 "updatedDate": "2020-01-31T20:49:48.658795600Z",
116 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500117 }
118 });
119 expect(component).toMatchSnapshot();
120 });
121
122 it('Test Table icons', () => {
123 fetch.mockImplementationOnce(() => {
124 return Promise.resolve({
125 ok: true,
126 status: 200,
127 json: () => {
128 return Promise.resolve({
129 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000130 "policyModelTosca":"TCA",
131 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
132 "version":"1.0.0",
133 "policyAcronym": "TCA",
134 "updatedDate": "2020-01-31T20:49:48.658795600Z",
135 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500136 });
137 }
138 });
139 });
140 const component = mount(<ViewToscaPolicyModal/>);
141 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
142 });
143
144 it('Test handleYamlContent', () => {
145 fetch.mockImplementationOnce(() => {
146 return Promise.resolve({
147 ok: true,
148 status: 200,
149 json: () => {
150 return Promise.resolve({
151 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000152 "policyModelTosca":"TCA",
153 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
154 "version":"1.0.0",
155 "policyAcronym":"TCA",
156 "updatedDate": "2020-01-31T20:49:48.658795600Z",
157 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500158 });
159 }
160 });
161 });
ash742683a83e2a2020-01-31 15:40:15 +0000162 const yamlContent = 'TCA Tosca model details';
drveerendra684057e2019-11-11 19:37:39 -0500163 const component = shallow(<ViewToscaPolicyModal/>);
164 component.find('[value="Please select Tosca model to view the details"]').prop('onChange')({ target: { value: yamlContent }});
165 expect(component.state('content')).toEqual(yamlContent);
166 });
167
168 it('Test handleClose', () => {
169 fetch.mockImplementationOnce(() => {
170 return Promise.resolve({
171 ok: true,
172 status: 200,
173 json: () => {
174 return Promise.resolve({
175 "index": "1",
ash742683a83e2a2020-01-31 15:40:15 +0000176 "policyModelTosca":"TCA",
177 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
178 "version":"1.0.0",
179 "policyAcronym": "TCA",
180 "updatedDate": "2020-01-31T20:49:48.658795600Z",
181 "updatedBy": "admin"
drveerendra684057e2019-11-11 19:37:39 -0500182 });
183 }
184 });
185 });
186 const historyMock = { push: jest.fn() };
187 const handleClose = jest.spyOn(ViewToscaPolicyModal.prototype,'handleClose');
188 const component = shallow(<ViewToscaPolicyModal history={historyMock} />)
189 component.find('[variant="secondary"]').prop('onClick')();
190 expect(handleClose).toHaveBeenCalledTimes(1);
191 expect(component.state('show')).toEqual(false);
192 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
193 handleClose.mockClear();
194 });
JulienBe0cde2b52020-04-03 13:21:13 +0200195});