storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/__tests__/ObjectItem.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 } from "enzyme" 19 import { ObjectItem } from "../ObjectItem" 20 21 describe("ObjectItem", () => { 22 it("should render without crashing", () => { 23 shallow(<ObjectItem name={"test"} />) 24 }) 25 26 it("should render with content type", () => { 27 const wrapper = shallow(<ObjectItem name={"test.jpg"} contentType={""} />) 28 expect(wrapper.prop("data-type")).toBe("image") 29 }) 30 31 it("shouldn't call onClick when the object isclicked", () => { 32 const onClick = jest.fn() 33 const checkObject = jest.fn() 34 const wrapper = shallow( 35 <ObjectItem name={"test"} checkObject={checkObject} /> 36 ) 37 wrapper.find("a").simulate("click", { preventDefault: jest.fn() }) 38 expect(onClick).not.toHaveBeenCalled() 39 }) 40 41 it("should call onClick when the folder isclicked", () => { 42 const onClick = jest.fn() 43 const wrapper = shallow(<ObjectItem name={"test/"} onClick={onClick} />) 44 wrapper.find("a").simulate("click", { preventDefault: jest.fn() }) 45 expect(onClick).toHaveBeenCalled() 46 }) 47 48 it("should call checkObject when the object/prefix is checked", () => { 49 const checkObject = jest.fn() 50 const wrapper = shallow( 51 <ObjectItem name={"test"} checked={false} checkObject={checkObject} /> 52 ) 53 wrapper.find("input[type='checkbox']").simulate("change") 54 expect(checkObject).toHaveBeenCalledWith("test") 55 }) 56 57 it("should render checked checkbox", () => { 58 const wrapper = shallow(<ObjectItem name={"test"} checked={true} />) 59 expect(wrapper.find("input[type='checkbox']").prop("checked")).toBeTruthy() 60 }) 61 62 it("should call uncheckObject when the object/prefix is unchecked", () => { 63 const checkObject = jest.fn() 64 const uncheckObject = jest.fn() 65 const wrapper = shallow( 66 <ObjectItem 67 name={"test"} 68 checked={true} 69 checkObject={checkObject} 70 uncheckObject={uncheckObject} 71 /> 72 ) 73 wrapper.find("input[type='checkbox']").simulate("change") 74 expect(uncheckObject).toHaveBeenCalledWith("test") 75 }) 76 })