drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 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'; |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 25 | import ViewToscaModal from './ViewToscaModal'; |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 26 | import { mount } from 'enzyme'; |
| 27 | |
| 28 | |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 29 | describe('Verify ViewToscaModal', () => { |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 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', () => { |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 52 | const component = shallow(<ViewToscaModal/>); |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 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', () => { |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 67 | const component = mount(<ViewToscaModal/>); |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 68 | expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy(); |
| 69 | |
| 70 | }); |
| 71 | |
| 72 | it('Test handleYamlContent', () => { |
| 73 | const yamlContent = 'MTCA Tosca model details'; |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 74 | const component = shallow(<ViewToscaModal/>); |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 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() }; |
sebdet | 81f5cab | 2019-11-06 11:40:46 +0100 | [diff] [blame^] | 81 | const handleClose = jest.spyOn(ViewToscaModal.prototype,'handleClose'); |
| 82 | const component = shallow(<ViewToscaModal history={historyMock} />) |
drveerendra | f6b2625 | 2019-10-31 12:45:30 -0400 | [diff] [blame] | 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 | }); |