2018-02-27 22:14:49 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage (C) 2018 MinIO, Inc.
|
2018-02-27 22:14:49 -05:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react"
|
|
|
|
import { shallow, mount } from "enzyme"
|
|
|
|
import { Policy } from "../Policy"
|
2018-08-30 18:20:27 -04:00
|
|
|
import { READ_ONLY, WRITE_ONLY, READ_WRITE, NONE } from "../../constants"
|
2018-02-27 22:14:49 -05:00
|
|
|
import web from "../../web"
|
|
|
|
|
|
|
|
jest.mock("../../web", () => ({
|
|
|
|
SetBucketPolicy: jest.fn(() => {
|
|
|
|
return Promise.resolve()
|
2018-03-22 15:25:56 -04:00
|
|
|
})
|
2018-02-27 22:14:49 -05:00
|
|
|
}))
|
|
|
|
|
|
|
|
describe("Policy", () => {
|
|
|
|
it("should render without crashing", () => {
|
2018-03-26 15:49:12 -04:00
|
|
|
shallow(<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />)
|
2018-02-27 22:14:49 -05:00
|
|
|
})
|
|
|
|
|
2018-08-30 18:20:27 -04:00
|
|
|
it("should not render when policy is listed as 'none'", () => {
|
|
|
|
const wrapper = shallow(<Policy currentBucket={"bucket"} prefix={"foo"} policy={NONE} />)
|
|
|
|
expect(wrapper.find(".pmb-list").length).toBe(0)
|
|
|
|
})
|
|
|
|
|
2018-02-27 22:14:49 -05:00
|
|
|
it("should call web.setBucketPolicy and fetchPolicies on submit", () => {
|
|
|
|
const fetchPolicies = jest.fn()
|
|
|
|
const wrapper = shallow(
|
2018-03-26 15:49:12 -04:00
|
|
|
<Policy
|
2018-02-27 22:14:49 -05:00
|
|
|
currentBucket={"bucket"}
|
|
|
|
prefix={"foo"}
|
|
|
|
policy={READ_ONLY}
|
|
|
|
fetchPolicies={fetchPolicies}
|
2018-03-22 15:25:56 -04:00
|
|
|
/>
|
2018-02-27 22:14:49 -05:00
|
|
|
)
|
2018-03-26 15:49:12 -04:00
|
|
|
wrapper.find("button").simulate("click", { preventDefault: jest.fn() })
|
2018-02-27 22:14:49 -05:00
|
|
|
|
|
|
|
expect(web.SetBucketPolicy).toHaveBeenCalledWith({
|
|
|
|
bucketName: "bucket",
|
|
|
|
prefix: "foo",
|
2018-03-22 15:25:56 -04:00
|
|
|
policy: "none"
|
2018-02-27 22:14:49 -05:00
|
|
|
})
|
2018-03-26 15:49:12 -04:00
|
|
|
|
2018-02-27 22:14:49 -05:00
|
|
|
setImmediate(() => {
|
|
|
|
expect(fetchPolicies).toHaveBeenCalledWith("bucket")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should change the empty string to '*' while displaying prefixes", () => {
|
|
|
|
const wrapper = shallow(
|
2018-03-22 15:25:56 -04:00
|
|
|
<Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} />
|
2018-02-27 22:14:49 -05:00
|
|
|
)
|
2018-03-26 15:49:12 -04:00
|
|
|
expect(wrapper.find(".pmbl-item").at(0).text()).toEqual("*")
|
2018-02-27 22:14:49 -05:00
|
|
|
})
|
|
|
|
})
|