3 * * ============LICENSE_START=======================================================
4 * * Copyright (C) 2021 Nordix Foundation.
5 * * ================================================================================
6 * * Licensed under the Apache License, Version 2.0 (the "License");
7 * * you may not use this file except in compliance with the License.
8 * * You may obtain a copy of the License at
10 * * http://www.apache.org/licenses/LICENSE-2.0
12 * * Unless required by applicable law or agreed to in writing, software
13 * * distributed under the License is distributed on an "AS IS" BASIS,
14 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * * See the License for the specific language governing permissions and
16 * * limitations under the License.
18 * * SPDX-License-Identifier: Apache-2.0
19 * * ============LICENSE_END=========================================================
22 import React from 'react';
23 import { mount, shallow } from 'enzyme';
24 import ReadAndConvertYaml from './ReadAndConvertYaml';
25 import toJson from "enzyme-to-json";
26 import { act } from "react-dom/test-utils";
27 import { createMemoryHistory } from "history";
29 describe('Verify ReadAndConvertYaml', () => {
33 fetch.mockImplementation(() => {
34 return Promise.resolve({
38 return Promise.resolve({
39 "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
42 "topology_template": {},
43 "name": "ToscaServiceTemplateSimple",
46 "id": "0.19518677404255147"
53 it("renders without crashing", () => {
54 shallow(<ReadAndConvertYaml/>);
57 it("renders correctly", () => {
58 const tree = shallow(<ReadAndConvertYaml/>);
59 expect(toJson(tree)).toMatchSnapshot();
62 it('should have a GetToscaTemplate element', () => {
63 const container = shallow(<ReadAndConvertYaml/>)
64 expect(container.find('GetToscaTemplate').length).toEqual(1);
67 it('should call getToscaServiceTemplateHandler on click', async () => {
68 const component = mount(<ReadAndConvertYaml/>);
69 const logSpy = jest.spyOn(console, 'log');
72 component.find('GetToscaTemplate').simulate('click');
73 expect(logSpy).toHaveBeenCalledWith('getToscaServiceTemplateHandler called');
77 it('handleClose called when bottom button clicked', () => {
78 const history = createMemoryHistory();
79 const component = mount(<ReadAndConvertYaml history={ history }/>)
80 const logSpy = jest.spyOn(console, 'log');
84 component.find('[variant="secondary"]').simulate('click');
85 expect(logSpy).toHaveBeenCalledWith('handleClose called');
89 it('handleClose called when top-right button clicked', () => {
90 const history = createMemoryHistory();
91 const component = mount(<ReadAndConvertYaml history={ history }/>)
92 const logSpy = jest.spyOn(console, 'log');
96 component.find('[size="xl"]').get(0).props.onHide();
97 expect(logSpy).toHaveBeenCalledWith('handleClose called');