2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
23 import React from 'react';
24 import { shallow } from 'enzyme';
25 import ViewToscaPolicyModal from './ViewToscaPolicyModal';
26 import { mount } from 'enzyme';
29 describe('Verify ViewToscaPolicyModal', () => {
34 it('Test API Successful', () => {
35 fetch.mockImplementationOnce(() => {
36 return Promise.resolve({
40 return Promise.resolve({
42 "policyModelTosca":"TCA",
43 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
45 "policyAcronym": "TCA",
46 "updatedDate": "2020-01-31T20:49:48.658795600Z",
52 const component = shallow(<ViewToscaPolicyModal/>);
55 it('Test API Exception', () => {
56 fetch.mockImplementationOnce(() => {
57 return Promise.resolve({
61 return Promise.resolve({
63 "policyModelTosca":"TCA",
64 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
66 "policyAcronym": "TCA",
67 "updatedDate": "2020-01-31T20:49:48.658795600Z",
73 const component = shallow(<ViewToscaPolicyModal/>);
76 it('Test API Rejection', () => {
77 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
80 myMockFunc().catch(e => {
85 new Promise(resolve => setTimeout(resolve, 200));
86 const component = shallow(<ViewToscaPolicyModal/>);
87 expect(myMockFunc.mock.calls.length).toBe(1);
91 it('Test the tosca model view render method', () => {
92 fetch.mockImplementationOnce(() => {
93 return Promise.resolve({
97 return Promise.resolve({
99 "policyModelTosca":"TCA",
100 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
102 "policyAcronym": "TCA",
103 "updatedDate": "2020-01-31T20:49:48.658795600Z",
109 const component = shallow(<ViewToscaPolicyModal/>);
110 component.setState({ toscaNames: {
112 "policyModelTosca":"TCA",
113 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
115 "policyAcronym": "TCA",
116 "updatedDate": "2020-01-31T20:49:48.658795600Z",
120 expect(component).toMatchSnapshot();
123 it('Test Table icons', () => {
124 fetch.mockImplementationOnce(() => {
125 return Promise.resolve({
129 return Promise.resolve({
131 "policyModelTosca":"TCA",
132 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
134 "policyAcronym": "TCA",
135 "updatedDate": "2020-01-31T20:49:48.658795600Z",
141 const component = mount(<ViewToscaPolicyModal/>);
142 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
145 it('Test handleYamlContent', () => {
146 fetch.mockImplementationOnce(() => {
147 return Promise.resolve({
151 return Promise.resolve({
153 "policyModelTosca":"TCA",
154 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
156 "policyAcronym":"TCA",
157 "updatedDate": "2020-01-31T20:49:48.658795600Z",
163 const yamlContent = 'TCA Tosca model details';
164 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);
169 it('Test handleClose', () => {
170 fetch.mockImplementationOnce(() => {
171 return Promise.resolve({
175 return Promise.resolve({
177 "policyModelTosca":"TCA",
178 "policyModelType":"onap.policies.monitoring.cdap.tca.hi.lo.app",
180 "policyAcronym": "TCA",
181 "updatedDate": "2020-01-31T20:49:48.658795600Z",
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();