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 ViewToscaModal from './ViewToscaModal';
26 import { mount } from 'enzyme';
29 describe('Verify ViewToscaModal', () => {
32 fetch.mockImplementation(() => {
33 return Promise.resolve({
37 return Promise.resolve({
39 "toscaModelYaml":"MTCA",
40 "toscaModelName":"DCAE_MTCAConfig",
44 "lastUpdatedDate":"05-07-2019 19:09:42"
51 it('Test the tosca model view render method', () => {
52 const component = shallow(<ViewToscaModal/>);
53 component.setState({ toscaNames: {
55 "toscaModelYaml": "MTCA",
56 "toscaModelName": "DCAE_MTCAConfig",
59 "policyType" : "mtca",
60 "lastUpdatedDate" : "05-07-2019 19:09:42"
63 expect(component).toMatchSnapshot();
66 it('Test Table icons', () => {
67 const component = mount(<ViewToscaModal/>);
68 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
72 it('Test handleYamlContent', () => {
73 const yamlContent = 'MTCA Tosca model details';
74 const component = shallow(<ViewToscaModal/>);
75 component.find('[value="Please select Tosca model to view the details"]').prop('onChange')({ target: { value: yamlContent }});
76 expect(component.state('content')).toEqual(yamlContent);
79 it('Test handleClose', () => {
80 const historyMock = { push: jest.fn() };
81 const handleClose = jest.spyOn(ViewToscaModal.prototype,'handleClose');
82 const component = shallow(<ViewToscaModal history={historyMock} />)
83 component.find('[variant="secondary"]').prop('onClick')();
84 expect(handleClose).toHaveBeenCalledTimes(1);
85 expect(component.state('show')).toEqual(false);
86 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
87 handleClose.mockClear();