|
| 1 | +import React from "react"; |
| 2 | +import { shallow } from "enzyme"; |
| 3 | +import HelmValuesEditor from "./HelmValuesEditor"; |
| 4 | + |
| 5 | +const mockShipAppMetadata = { |
| 6 | + values: "some: values", |
| 7 | + readme: "a readme", |
| 8 | + name: "test", |
| 9 | +} |
| 10 | + |
| 11 | +const mockGetStep = {}; |
| 12 | + |
| 13 | +describe("HelmValuesEditor", () => { |
| 14 | + describe("with invalid helm values", () => { |
| 15 | + describe("saved and finalized", () => { |
| 16 | + it("allows for the save button to be clicked after an error", async() => { |
| 17 | + const mockSaveValues = jest.fn(); |
| 18 | + mockSaveValues.mockImplementation(() => Promise.resolve({ errors: ["Test error"]})); |
| 19 | + |
| 20 | + const mockSpecValue = "some: different values"; |
| 21 | + const wrapper = shallow( |
| 22 | + <HelmValuesEditor |
| 23 | + shipAppMetadata={mockShipAppMetadata} |
| 24 | + saveValues={mockSaveValues} |
| 25 | + getStep={mockGetStep} |
| 26 | + /> |
| 27 | + ); |
| 28 | + |
| 29 | + wrapper.setState({ specValue: mockSpecValue }); |
| 30 | + await wrapper.instance().handleSaveValues(true); |
| 31 | + |
| 32 | + expect(mockSaveValues.mock.calls).toHaveLength(1); |
| 33 | + const elements = wrapper.find("button"); |
| 34 | + expect(elements).toHaveLength(2); |
| 35 | + elements.forEach((element) => { |
| 36 | + expect(element.prop("disabled")).toEqual(false); |
| 37 | + }); |
| 38 | + }); |
| 39 | + }); |
| 40 | + describe("saved", () => { |
| 41 | + it("allows for the save button to be clicked after an error", async() => { |
| 42 | + const mockSaveValues = jest.fn(); |
| 43 | + mockSaveValues.mockImplementation(() => Promise.resolve({ errors: ["Test error"]})); |
| 44 | + |
| 45 | + const mockSpecValue = "some: different values"; |
| 46 | + const wrapper = shallow( |
| 47 | + <HelmValuesEditor |
| 48 | + shipAppMetadata={mockShipAppMetadata} |
| 49 | + saveValues={mockSaveValues} |
| 50 | + getStep={mockGetStep} |
| 51 | + /> |
| 52 | + ); |
| 53 | + |
| 54 | + wrapper.setState({ specValue: mockSpecValue }); |
| 55 | + await wrapper.instance().handleSaveValues(false); |
| 56 | + |
| 57 | + expect(mockSaveValues.mock.calls).toHaveLength(1); |
| 58 | + const elements = wrapper.find("button"); |
| 59 | + expect(elements).toHaveLength(2); |
| 60 | + elements.forEach((element) => { |
| 61 | + expect(element.prop("disabled")).toEqual(false); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments