2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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 "toscaModelYaml":"MTCA",
43 "toscaModelName":"DCAE_MTCAConfig",
47 "lastUpdatedDate":"05-07-2019 19:09:42"
52 const component = shallow(<ViewToscaPolicyModal/>);
55 it('Test API Exception', () => {
56 fetch.mockImplementationOnce(() => {
57 return Promise.resolve({
61 return Promise.resolve({
63 "toscaModelName":"DCAE_MTCAConfig",
67 "lastUpdatedDate":"05-07-2019 19:09:42"
72 const component = shallow(<ViewToscaPolicyModal/>);
75 it('Test API Rejection', () => {
76 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
79 myMockFunc().catch(e => {
84 new Promise(resolve => setTimeout(resolve, 200));
85 const component = shallow(<ViewToscaPolicyModal/>);
86 expect(myMockFunc.mock.calls.length).toBe(1);
90 it('Test the tosca model view render method', () => {
91 fetch.mockImplementationOnce(() => {
92 return Promise.resolve({
96 return Promise.resolve({
98 "toscaModelYaml":"MTCA",
99 "toscaModelName":"DCAE_MTCAConfig",
103 "lastUpdatedDate":"05-07-2019 19:09:42"
108 const component = shallow(<ViewToscaPolicyModal/>);
109 component.setState({ toscaNames: {
111 "toscaModelYaml": "MTCA",
112 "toscaModelName": "DCAE_MTCAConfig",
115 "policyType" : "mtca",
116 "lastUpdatedDate" : "05-07-2019 19:09:42"
119 expect(component).toMatchSnapshot();
122 it('Test Table icons', () => {
123 fetch.mockImplementationOnce(() => {
124 return Promise.resolve({
128 return Promise.resolve({
130 "toscaModelYaml":"MTCA",
131 "toscaModelName":"DCAE_MTCAConfig",
135 "lastUpdatedDate":"05-07-2019 19:09:42"
140 const component = mount(<ViewToscaPolicyModal/>);
141 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
144 it('Test handleYamlContent', () => {
145 fetch.mockImplementationOnce(() => {
146 return Promise.resolve({
150 return Promise.resolve({
152 "toscaModelYaml":"MTCA",
153 "toscaModelName":"DCAE_MTCAConfig",
157 "lastUpdatedDate":"05-07-2019 19:09:42"
162 const yamlContent = 'MTCA Tosca model details';
163 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);
168 it('Test handleClose', () => {
169 fetch.mockImplementationOnce(() => {
170 return Promise.resolve({
174 return Promise.resolve({
176 "toscaModelYaml":"MTCA",
177 "toscaModelName":"DCAE_MTCAConfig",
181 "lastUpdatedDate":"05-07-2019 19:09:42"
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();