blob: 4dbe3761538b0381f7c9d7695c14eff49c3ecf54 [file] [log] [blame]
drveerendraf6b26252019-10-31 12:45:30 -04001/*-
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';
sebdet81f5cab2019-11-06 11:40:46 +010025import ViewToscaModal from './ViewToscaModal';
drveerendraf6b26252019-10-31 12:45:30 -040026import { mount } from 'enzyme';
27
28
sebdet81f5cab2019-11-06 11:40:46 +010029describe('Verify ViewToscaModal', () => {
drveerendraf6b26252019-10-31 12:45:30 -040030 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', () => {
sebdet81f5cab2019-11-06 11:40:46 +010052 const component = shallow(<ViewToscaModal/>);
drveerendraf6b26252019-10-31 12:45:30 -040053 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', () => {
sebdet81f5cab2019-11-06 11:40:46 +010067 const component = mount(<ViewToscaModal/>);
drveerendraf6b26252019-10-31 12:45:30 -040068 expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy();
69
70 });
71
72 it('Test handleYamlContent', () => {
73 const yamlContent = 'MTCA Tosca model details';
sebdet81f5cab2019-11-06 11:40:46 +010074 const component = shallow(<ViewToscaModal/>);
drveerendraf6b26252019-10-31 12:45:30 -040075 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() };
sebdet81f5cab2019-11-06 11:40:46 +010081 const handleClose = jest.spyOn(ViewToscaModal.prototype,'handleClose');
82 const component = shallow(<ViewToscaModal history={historyMock} />)
drveerendraf6b26252019-10-31 12:45:30 -040083 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});