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 ViewBlueprintMicroServiceTemplatesModal from './ViewBlueprintMicroServiceTemplatesModal';
26 import { mount } from 'enzyme';
28 describe('Verify ViewBlueprintMicroServiceTemplatesModal', () => {
34 it('Test API Successful', () => {
35 fetch.mockImplementationOnce(() => {
36 return Promise.resolve({
40 return Promise.resolve({
42 "content": "MTCA version 1",
43 "templateName": "MTCA",
44 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
46 "templateId":"aaaa_bbbb_cccc",
47 "timestamp":"2019-09-06 19:09:42"
52 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal/>);
55 it('Test API Exception', () => {
56 fetch.mockImplementationOnce(() => {
57 return Promise.resolve({
61 return Promise.resolve({
63 "content": "MTCA version 1",
64 "templateName": "MTCA",
65 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
67 "templateId":"aaaa_bbbb_cccc",
68 "timestamp":"2019-09-06 19:09:42"
73 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal/>);
76 it('Test API Rejection', () => {
77 const myMockFunc = fetch.mockImplementationOnce(() => Promise.reject('error'));
78 setTimeout( () => myMockFunc().catch(e => {
83 new Promise(resolve => setTimeout(resolve, 200));
84 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal/>);
85 expect(myMockFunc.mock.calls.length).toBe(1);
88 it('Test the tosca model view render method', () => {
89 fetch.mockImplementationOnce(() => {
90 return Promise.resolve({
94 return Promise.resolve({
96 "content": "MTCA version 1",
97 "templateName": "MTCA",
98 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
100 "templateId":"aaaa_bbbb_cccc",
101 "timestamp":"2019-09-06 19:09:42"
106 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal/>);
107 component.setState({ bpTemplNames: {
109 "content": "MTCA version 1",
110 "templateName": "MTCA",
111 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
112 "updatedBy":"tester",
113 "templateId":"aaaa_bbbb_cccc",
114 "timestamp":"2019-09-06 19:09:42"
117 expect(component).toMatchSnapshot();
120 it('Test Table icons', () => {
121 fetch.mockImplementationOnce(() => {
122 return Promise.resolve({
126 return Promise.resolve({
128 "content": "MTCA version 1",
129 "templateName": "MTCA",
130 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
131 "updatedBy":"tester",
132 "templateId":"aaaa_bbbb_cccc",
133 "timestamp":"2019-09-06 19:09:42"
138 const component = mount(<ViewBlueprintMicroServiceTemplatesModal/>);
139 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
142 it('Test handleYamlContent', () => {
143 fetch.mockImplementationOnce(() => {
144 return Promise.resolve({
148 return Promise.resolve({
150 "content": "MTCA version 1",
151 "templateName": "MTCA",
152 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
153 "updatedBy":"tester",
154 "templateId":"aaaa_bbbb_cccc",
155 "timestamp":"2019-09-06 19:09:42"
160 const yamlContent = 'MTCA Tosca model details';
161 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal/>);
162 component.find('[value="Please select Blue print template to view the details"]').prop('onChange')({ target: { value: yamlContent }});
163 expect(component.state('content')).toEqual(yamlContent);
166 it('Test handleClose', () => {
167 fetch.mockImplementationOnce(() => {
168 return Promise.resolve({
172 return Promise.resolve({
174 "content": "MTCA version 1",
175 "templateName": "MTCA",
176 "templatePolicy.policyModelId" : "onap.policies.monitoring.docker.mtca.app",
177 "updatedBy":"tester",
178 "templateId":"aaaa_bbbb_cccc",
179 "timestamp":"2019-09-06 19:09:42"
184 const historyMock = { push: jest.fn() };
185 const handleClose = jest.spyOn(ViewBlueprintMicroServiceTemplatesModal.prototype,'handleClose');
186 const component = shallow(<ViewBlueprintMicroServiceTemplatesModal history={historyMock} />)
187 component.find('[variant="secondary"]').prop('onClick')();
188 expect(handleClose).toHaveBeenCalledTimes(1);
189 expect(component.state('show')).toEqual(false);
190 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
191 handleClose.mockClear();