blob: 25292d0a786daaf34b6d06f6de284edcb3a8a5f8 [file] [log] [blame]
brunomilitzerad6a4572021-08-19 17:20:13 +01001/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
18 */
19
20import { mount, shallow } from "enzyme";
21import React from "react";
22import toJson from "enzyme-to-json";
23import { createMemoryHistory } from "history";
24import { act } from "react-dom/test-utils";
brunomilitzera090a832021-08-30 18:46:53 +010025import ChangeOrderStateModal from "./ControlLoop/ChangeOrderStateModal";
brunomilitzerad6a4572021-08-19 17:20:13 +010026
27describe('Verify InstantiationManagementModal', () => {
28
29 it("renders without crashing", () => {
brunomilitzera090a832021-08-30 18:46:53 +010030 shallow(<ChangeOrderStateModal />);
brunomilitzerad6a4572021-08-19 17:20:13 +010031 });
32
33 it("renders correctly", () => {
brunomilitzera090a832021-08-30 18:46:53 +010034 const tree = shallow(<ChangeOrderStateModal />);
brunomilitzerad6a4572021-08-19 17:20:13 +010035 expect(toJson(tree)).toMatchSnapshot();
36 });
37
38 it('should have save button element', () => {
brunomilitzera090a832021-08-30 18:46:53 +010039 const container = shallow(<ChangeOrderStateModal/>)
brunomilitzerad6a4572021-08-19 17:20:13 +010040 expect(container.find('[variant="primary"]').length).toEqual(1);
41 });
42
43 it('handleSave called when save button clicked', () => {
44 const history = createMemoryHistory();
brunomilitzera090a832021-08-30 18:46:53 +010045 const component = mount(<ChangeOrderStateModal history={ history }/>)
brunomilitzerad6a4572021-08-19 17:20:13 +010046 const logSpy = jest.spyOn(console, 'log');
47
48 act(() => {
49 component.find('[variant="primary"]').simulate('click');
50 expect(logSpy).toHaveBeenCalledWith('handleSave called');
51 });
52 });
53
54 it('should have close button element', () => {
brunomilitzera090a832021-08-30 18:46:53 +010055 const container = shallow(<ChangeOrderStateModal/>)
brunomilitzerad6a4572021-08-19 17:20:13 +010056 expect(container.find('[variant="secondary"]').length).toEqual(1);
57 });
58
59 it('handleClose called when close button clicked', () => {
60 const history = createMemoryHistory();
brunomilitzera090a832021-08-30 18:46:53 +010061 const component = mount(<ChangeOrderStateModal history={ history }/>)
brunomilitzerad6a4572021-08-19 17:20:13 +010062 const logSpy = jest.spyOn(console, 'log');
63
64 act(() => {
65 component.find('[variant="secondary"]').simulate('click');
66 expect(logSpy).toHaveBeenCalledWith('handleClose called');
67 });
68 });
69});