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 ViewLoopTemplatesModal from './ViewLoopTemplatesModal';
26 import { mount } from 'enzyme';
28 describe('Verify ViewLoopTemplatesModal', () => {
33 it('Test API Successful', () => {
34 fetch.mockImplementationOnce(() => {
35 return Promise.resolve({
39 return Promise.resolve({
41 "name": "MTCA version 1",
42 "modelService.serviceDetails.name": "MTCA",
43 "allowedLoopType" : "CLOSED",
44 "maximumInstancesAllowed":1,
45 "updatedDate":"2019-09-06 19:09:42"
50 const component = shallow(<ViewLoopTemplatesModal/>);
53 it('Test API Exception', () => {
54 fetch.mockImplementationOnce(() => {
55 return Promise.resolve({
59 return Promise.resolve({
61 "name": "MTCA version 1",
62 "modelService.serviceDetails.name": "MTCA",
63 "allowedLoopType" : "CLOSED",
64 "maximumInstancesAllowed":1,
65 "updatedDate":"2019-09-06 19:09:42"
70 const component = shallow(<ViewLoopTemplatesModal/>);
73 it('Test API Rejection', () => {
74 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
75 setTimeout( () => myMockFunc().catch(e => {
80 new Promise(resolve => setTimeout(resolve, 200));
81 const component = shallow(<ViewLoopTemplatesModal/>);
82 expect(myMockFunc.mock.calls.length).toBe(1);
85 it('Test the tosca model view render method', () => {
86 fetch.mockImplementationOnce(() => {
87 return Promise.resolve({
91 return Promise.resolve({
93 "name": "MTCA version 1",
94 "modelService.serviceDetails.name": "MTCA",
95 "allowedLoopType" : "CLOSED",
96 "maximumInstancesAllowed":1,
97 "updatedDate":"2019-09-06 19:09:42"
102 const component = shallow(<ViewLoopTemplatesModal/>);
103 component.setState({ loopTemplateData: {
105 "name": "MTCA version 1",
106 "modelService.serviceDetails.name": "MTCA",
107 "allowedLoopType" : "CLOSED",
108 "maximumInstancesAllowed":1,
109 "updatedDate":"2019-09-06 19:09:42"
112 expect(component).toMatchSnapshot();
115 it('Test Table icons', () => {
116 fetch.mockImplementationOnce(() => {
117 return Promise.resolve({
121 return Promise.resolve({
123 "name": "MTCA version 1",
124 "modelService.serviceDetails.name": "MTCA",
125 "allowedLoopType" : "CLOSED",
126 "maximumInstancesAllowed":1,
127 "updatedDate":"2019-09-06 19:09:42"
132 const component = mount(<ViewLoopTemplatesModal/>);
133 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
136 it('Test handleClose', () => {
137 fetch.mockImplementationOnce(() => {
138 return Promise.resolve({
142 return Promise.resolve({
144 "name": "MTCA version 1",
145 "modelService.serviceDetails.name": "MTCA",
146 "allowedLoopType" : "CLOSED",
147 "maximumInstancesAllowed":1,
148 "updatedDate":"2019-09-06 19:09:42"
153 const historyMock = { push: jest.fn() };
154 const handleClose = jest.spyOn(ViewLoopTemplatesModal.prototype,'handleClose');
155 const component = shallow(<ViewLoopTemplatesModal history={historyMock} />)
156 component.find('[variant="secondary"]').prop('onClick')();
157 expect(handleClose).toHaveBeenCalledTimes(1);
158 expect(component.state('show')).toEqual(false);
159 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
160 handleClose.mockClear();