blob: 7680ec4b945b970c2906ca1c7f86f6c1930b4a12 [file] [log] [blame]
sebdet3b7f6692020-02-17 06:03:31 -08001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * 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 ViewLoopTemplatesModal from './ViewLoopTemplatesModal';
26import { mount } from 'enzyme';
sebdetc0ec0fc2020-05-18 12:31:11 +020027import { BrowserRouter as Router } from 'react-router-dom';
sebdet3b7f6692020-02-17 06:03:31 -080028
29describe('Verify ViewLoopTemplatesModal', () => {
30 beforeEach(() => {
31 fetch.resetMocks();
jingjincs3173d552020-03-04 09:11:10 +010032 });
sebdet3b7f6692020-02-17 06:03:31 -080033
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",
42 "name": "MTCA version 1",
43 "modelService.serviceDetails.name": "MTCA",
44 "allowedLoopType" : "CLOSED",
45 "maximumInstancesAllowed":1,
46 "updatedDate":"2019-09-06 19:09:42"
47 });
48 }
49 });
50 });
51 const component = shallow(<ViewLoopTemplatesModal/>);
52 });
53
54 it('Test API Exception', () => {
55 fetch.mockImplementationOnce(() => {
56 return Promise.resolve({
57 ok: false,
58 status: 500,
59 json: () => {
60 return Promise.resolve({
61 "index": "1",
62 "name": "MTCA version 1",
63 "modelService.serviceDetails.name": "MTCA",
64 "allowedLoopType" : "CLOSED",
65 "maximumInstancesAllowed":1,
66 "updatedDate":"2019-09-06 19:09:42"
67 });
68 }
69 });
70 });
71 const component = shallow(<ViewLoopTemplatesModal/>);
72 });
73
74 it('Test API Rejection', () => {
75 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
76 setTimeout( () => myMockFunc().catch(e => {
JulienBe0cde2b52020-04-03 13:21:13 +020077 console.info(e);
sebdet3b7f6692020-02-17 06:03:31 -080078 }),
79 100
80 );
sebdet3b7f6692020-02-17 06:03:31 -080081 const component = shallow(<ViewLoopTemplatesModal/>);
82 expect(myMockFunc.mock.calls.length).toBe(1);
83 });
84
85 it('Test the tosca model view render method', () => {
86 fetch.mockImplementationOnce(() => {
87 return Promise.resolve({
88 ok: true,
89 status: 200,
90 json: () => {
91 return Promise.resolve({
92 "index": "1",
93 "name": "MTCA version 1",
94 "modelService.serviceDetails.name": "MTCA",
95 "allowedLoopType" : "CLOSED",
96 "maximumInstancesAllowed":1,
97 "updatedDate":"2019-09-06 19:09:42"
98 });
99 }
100 });
101 });
102 const component = shallow(<ViewLoopTemplatesModal/>);
103 component.setState({ loopTemplateData: {
104 "index": "1",
105 "name": "MTCA version 1",
106 "modelService.serviceDetails.name": "MTCA",
107 "allowedLoopType" : "CLOSED",
108 "maximumInstancesAllowed":1,
109 "updatedDate":"2019-09-06 19:09:42"
110 }
111 });
112 expect(component).toMatchSnapshot();
113 });
114
115 it('Test Table icons', () => {
116 fetch.mockImplementationOnce(() => {
117 return Promise.resolve({
118 ok: true,
119 status: 200,
120 json: () => {
121 return Promise.resolve({
122 "index": "1",
123 "name": "MTCA version 1",
124 "modelService.serviceDetails.name": "MTCA",
125 "allowedLoopType" : "CLOSED",
126 "maximumInstancesAllowed":1,
127 "updatedDate":"2019-09-06 19:09:42"
128 });
129 }
130 });
131 });
sebdetc0ec0fc2020-05-18 12:31:11 +0200132 const component = mount(<Router><ViewLoopTemplatesModal/></Router>);
sebdet3b7f6692020-02-17 06:03:31 -0800133 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
134 });
sebdet3b7f6692020-02-17 06:03:31 -0800135
136 it('Test handleClose', () => {
137 fetch.mockImplementationOnce(() => {
138 return Promise.resolve({
139 ok: true,
140 status: 200,
141 json: () => {
142 return Promise.resolve({
143 "index": "1",
144 "name": "MTCA version 1",
145 "modelService.serviceDetails.name": "MTCA",
146 "allowedLoopType" : "CLOSED",
147 "maximumInstancesAllowed":1,
148 "updatedDate":"2019-09-06 19:09:42"
149 });
150 }
151 });
152 });
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();
161 });
JulienBe0cde2b52020-04-03 13:21:13 +0200162 });