storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/buckets/__tests__/Policy.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 { Policy } from "../Policy" 20 import { READ_ONLY, WRITE_ONLY, READ_WRITE, NONE } from "../../constants" 21 import web from "../../web" 22 23 jest.mock("../../web", () => ({ 24 SetBucketPolicy: jest.fn(() => { 25 return Promise.resolve() 26 }) 27 })) 28 29 describe("Policy", () => { 30 it("should render without crashing", () => { 31 shallow(<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />) 32 }) 33 34 it("should not render when policy is listed as 'none'", () => { 35 const wrapper = shallow(<Policy currentBucket={"bucket"} prefix={"foo"} policy={NONE} />) 36 expect(wrapper.find(".pmb-list").length).toBe(0) 37 }) 38 39 it("should call web.setBucketPolicy and fetchPolicies on submit", () => { 40 const fetchPolicies = jest.fn() 41 const wrapper = shallow( 42 <Policy 43 currentBucket={"bucket"} 44 prefix={"foo"} 45 policy={READ_ONLY} 46 fetchPolicies={fetchPolicies} 47 /> 48 ) 49 wrapper.find("button").simulate("click", { preventDefault: jest.fn() }) 50 51 expect(web.SetBucketPolicy).toHaveBeenCalledWith({ 52 bucketName: "bucket", 53 prefix: "foo", 54 policy: "none" 55 }) 56 57 setImmediate(() => { 58 expect(fetchPolicies).toHaveBeenCalledWith("bucket") 59 }) 60 }) 61 62 it("should change the empty string to '*' while displaying prefixes", () => { 63 const wrapper = shallow( 64 <Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} /> 65 ) 66 expect(wrapper.find(".pmbl-item").at(0).text()).toEqual("*") 67 }) 68 })