brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | import { mount, shallow } from "enzyme"; |
| 21 | import React from "react"; |
| 22 | import toJson from "enzyme-to-json"; |
| 23 | import { createMemoryHistory } from "history"; |
| 24 | import { act } from "react-dom/test-utils"; |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 25 | import ChangeOrderStateModal from "./ControlLoop/ChangeOrderStateModal"; |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 26 | |
| 27 | describe('Verify InstantiationManagementModal', () => { |
| 28 | |
| 29 | it("renders without crashing", () => { |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 30 | shallow(<ChangeOrderStateModal />); |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 31 | }); |
| 32 | |
| 33 | it("renders correctly", () => { |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 34 | const tree = shallow(<ChangeOrderStateModal />); |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 35 | expect(toJson(tree)).toMatchSnapshot(); |
| 36 | }); |
| 37 | |
| 38 | it('should have save button element', () => { |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 39 | const container = shallow(<ChangeOrderStateModal/>) |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 40 | expect(container.find('[variant="primary"]').length).toEqual(1); |
| 41 | }); |
| 42 | |
| 43 | it('handleSave called when save button clicked', () => { |
| 44 | const history = createMemoryHistory(); |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 45 | const component = mount(<ChangeOrderStateModal history={ history }/>) |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 46 | 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', () => { |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 55 | const container = shallow(<ChangeOrderStateModal/>) |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 56 | expect(container.find('[variant="secondary"]').length).toEqual(1); |
| 57 | }); |
| 58 | |
| 59 | it('handleClose called when close button clicked', () => { |
| 60 | const history = createMemoryHistory(); |
brunomilitzer | a090a83 | 2021-08-30 18:46:53 +0100 | [diff] [blame] | 61 | const component = mount(<ChangeOrderStateModal history={ history }/>) |
brunomilitzer | ad6a457 | 2021-08-19 17:20:13 +0100 | [diff] [blame] | 62 | 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 | }); |