storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/buckets/__tests__/MakeBucketModal.test.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 17 import React from "react" 18 import { shallow, mount } from "enzyme" 19 import { MakeBucketModal } from "../MakeBucketModal" 20 21 describe("MakeBucketModal", () => { 22 it("should render without crashing", () => { 23 shallow(<MakeBucketModal />) 24 }) 25 26 it("should call hideMakeBucketModal when close button is clicked", () => { 27 const hideMakeBucketModal = jest.fn() 28 const wrapper = shallow( 29 <MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} /> 30 ) 31 wrapper.find("button").simulate("click") 32 expect(hideMakeBucketModal).toHaveBeenCalled() 33 }) 34 35 it("bucketName should be cleared before hiding the modal", () => { 36 const hideMakeBucketModal = jest.fn() 37 const wrapper = shallow( 38 <MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} /> 39 ) 40 wrapper.find("input").simulate("change", { 41 target: { value: "test" } 42 }) 43 expect(wrapper.state("bucketName")).toBe("test") 44 wrapper.find("button").simulate("click") 45 expect(wrapper.state("bucketName")).toBe("") 46 }) 47 48 it("should call makeBucket when the form is submitted", () => { 49 const makeBucket = jest.fn() 50 const hideMakeBucketModal = jest.fn() 51 const wrapper = shallow( 52 <MakeBucketModal 53 makeBucket={makeBucket} 54 hideMakeBucketModal={hideMakeBucketModal} 55 /> 56 ) 57 wrapper.find("input").simulate("change", { 58 target: { value: "test" } 59 }) 60 wrapper.find("form").simulate("submit", { preventDefault: jest.fn() }) 61 expect(makeBucket).toHaveBeenCalledWith("test") 62 }) 63 64 it("should call hideMakeBucketModal and clear bucketName after the form is submited", () => { 65 const makeBucket = jest.fn() 66 const hideMakeBucketModal = jest.fn() 67 const wrapper = shallow( 68 <MakeBucketModal 69 makeBucket={makeBucket} 70 hideMakeBucketModal={hideMakeBucketModal} 71 /> 72 ) 73 wrapper.find("input").simulate("change", { 74 target: { value: "test" } 75 }) 76 wrapper.find("form").simulate("submit", { preventDefault: jest.fn() }) 77 expect(hideMakeBucketModal).toHaveBeenCalled() 78 expect(wrapper.state("bucketName")).toBe("") 79 }) 80 })