4284dd3eda06d7ef136d936de82ff72138c04f61
[clamp.git] / ui-react / src / components / dialogs / ViewToscaModals / ViewToscaModals.test.js
1 /*-
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  */
23 import React from 'react';
24 import { shallow } from 'enzyme';
25 import ViewToscaModals from './ViewToscaModals';
26 import { mount } from 'enzyme';
27
28
29 describe('Verify ViewToscaModals', () => {
30         beforeEach(() => {
31                 fetch.resetMocks();
32                 fetch.mockImplementation(() => {
33                         return Promise.resolve({
34                                 ok: true,
35                                 status: 200,
36                                 json: () => {
37                                         return Promise.resolve({
38                                                 "index": "1",
39                                         "toscaModelYaml":"MTCA",
40                                                 "toscaModelName":"DCAE_MTCAConfig",
41                                                 "version":"16",
42                                                 "userId":"aj928f",
43                                                 "policyType":"mtca",
44                                                 "lastUpdatedDate":"05-07-2019 19:09:42"
45                                         });
46                                 }
47                         });
48                 });
49         });
50
51         it('Test the tosca model view render method', () => {
52                 const component = shallow(<ViewToscaModals/>);
53                 component.setState({ toscaNames: {
54                         "index": "1",
55                         "toscaModelYaml": "MTCA",
56                         "toscaModelName": "DCAE_MTCAConfig",
57                         "version" : "16",
58                         "userId" : "aj928f",
59                         "policyType" : "mtca",
60                         "lastUpdatedDate" : "05-07-2019 19:09:42"
61                 }
62         });
63     expect(component).toMatchSnapshot();
64   });
65
66         it('Test Table icons', () => {
67                 const component = mount(<ViewToscaModals/>);
68                 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
69
70   });
71
72         it('Test handleYamlContent', () => {
73                 const yamlContent = 'MTCA Tosca model details';
74                 const component = shallow(<ViewToscaModals/>);
75                 component.find('[value="Please select Tosca model to view the details"]').prop('onChange')({ target: { value: yamlContent }});
76     expect(component.state('content')).toEqual(yamlContent);
77   });
78
79         it('Test handleClose', () => {
80                 const historyMock = { push: jest.fn() };
81     const handleClose = jest.spyOn(ViewToscaModals.prototype,'handleClose');
82     const component = shallow(<ViewToscaModals 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();
88   });
89 });