Browser: Update UI with new components and elements (#5671)

This commit is contained in:
Rushan
2018-03-21 23:39:23 +05:30
committed by Harshavardhana
parent 384b4fdf28
commit 1459c4be1e
199 changed files with 10549 additions and 4702 deletions
@@ -26,9 +26,11 @@ describe("Bucket", () => {
it("should call selectBucket when clicked", () => {
const selectBucket = jest.fn()
const wrapper = shallow(
<Bucket bucket={"test"} selectBucket={selectBucket} />
<Bucket bucket={"test"} selectBucket={selectBucket} />,
)
wrapper.find("li").simulate("click", { preventDefault: jest.fn() })
wrapper.find("li").simulate("click", {
preventDefault: jest.fn(),
})
expect(selectBucket).toHaveBeenCalledWith("test")
})
@@ -26,26 +26,28 @@ describe("BucketContainer", () => {
beforeEach(() => {
store = mockStore({
buckets: {
currentBucket: "Test"
}
currentBucket: "Test",
},
})
store.dispatch = jest.fn()
})
it("should render without crashing", () => {
shallow(<BucketContainer store={store}/>)
shallow(<BucketContainer store={store} />)
})
it('maps state and dispatch to props', () => {
const wrapper = shallow(<BucketContainer store={store}/>)
expect(wrapper.props()).toEqual(expect.objectContaining({
isActive: expect.any(Boolean),
selectBucket: expect.any(Function)
}))
it("maps state and dispatch to props", () => {
const wrapper = shallow(<BucketContainer store={store} />)
expect(wrapper.props()).toEqual(
expect.objectContaining({
isActive: expect.any(Boolean),
selectBucket: expect.any(Function),
}),
)
})
it('maps selectBucket to dispatch action', () => {
const wrapper = shallow(<BucketContainer store={store}/>)
it("maps selectBucket to dispatch action", () => {
const wrapper = shallow(<BucketContainer store={store} />)
wrapper.props().selectBucket()
expect(store.dispatch).toHaveBeenCalled()
})
@@ -24,13 +24,9 @@ describe("BucketDropdown", () => {
})
it("should call toggleDropdown on dropdown toggle", () => {
const spy = jest.spyOn(BucketDropdown.prototype, 'toggleDropdown')
const wrapper = shallow(
<BucketDropdown />
)
wrapper
.find("Uncontrolled(Dropdown)")
.simulate("toggle")
const spy = jest.spyOn(BucketDropdown.prototype, "toggleDropdown")
const wrapper = shallow(<BucketDropdown />)
wrapper.find("Uncontrolled(Dropdown)").simulate("toggle")
expect(spy).toHaveBeenCalled()
spy.mockReset()
spy.mockRestore()
@@ -39,24 +35,28 @@ describe("BucketDropdown", () => {
it("should call showBucketPolicy when Edit Policy link is clicked", () => {
const showBucketPolicy = jest.fn()
const wrapper = shallow(
<BucketDropdown showBucketPolicy={showBucketPolicy} />
<BucketDropdown showBucketPolicy={showBucketPolicy} />,
)
wrapper
.find("li a")
.at(0)
.simulate("click", { stopPropagation: jest.fn() })
.simulate("click", {
stopPropagation: jest.fn(),
})
expect(showBucketPolicy).toHaveBeenCalled()
})
it("should call deleteBucket when Delete link is clicked", () => {
const deleteBucket = jest.fn()
const wrapper = shallow(
<BucketDropdown bucket={"test"} deleteBucket={deleteBucket} />
<BucketDropdown bucket={"test"} deleteBucket={deleteBucket} />,
)
wrapper
.find("li a")
.at(1)
.simulate("click", { stopPropagation: jest.fn() })
.simulate("click", {
stopPropagation: jest.fn(),
})
expect(deleteBucket).toHaveBeenCalledWith("test")
})
})
@@ -23,7 +23,7 @@ jest.mock("../../web", () => ({
LoggedIn: jest
.fn(() => false)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true),
}))
describe("BucketList", () => {
@@ -35,7 +35,7 @@ describe("BucketList", () => {
it("should call fetchBuckets before component is mounted", () => {
const fetchBuckets = jest.fn()
const wrapper = shallow(
<BucketList visibleBuckets={[]} fetchBuckets={fetchBuckets} />
<BucketList visibleBuckets={[]} fetchBuckets={fetchBuckets} />,
)
expect(fetchBuckets).toHaveBeenCalled()
})
@@ -49,7 +49,7 @@ describe("BucketList", () => {
visibleBuckets={[]}
setBucketList={setBucketList}
selectBucket={selectBucket}
/>
/>,
)
expect(setBucketList).toHaveBeenCalledWith(["bk1"])
expect(selectBucket).toHaveBeenCalledWith("bk1", "pre1")
@@ -21,13 +21,13 @@ import { READ_ONLY, WRITE_ONLY, READ_WRITE } from "../../constants"
describe("BucketPolicyModal", () => {
it("should render without crashing", () => {
shallow(<BucketPolicyModal policies={[]}/>)
shallow(<BucketPolicyModal policies={[]} />)
})
it("should call hideBucketPolicy when close button is clicked", () => {
const hideBucketPolicy = jest.fn()
const wrapper = shallow(
<BucketPolicyModal hideBucketPolicy={hideBucketPolicy} policies={[]} />
<BucketPolicyModal hideBucketPolicy={hideBucketPolicy} policies={[]} />,
)
wrapper.find("button").simulate("click")
expect(hideBucketPolicy).toHaveBeenCalled()
@@ -35,7 +35,7 @@ describe("BucketPolicyModal", () => {
it("should include the PolicyInput and Policy components when there are any policies", () => {
const wrapper = shallow(
<BucketPolicyModal policies={ [{prefix: "test", policy: READ_ONLY}] } />
<BucketPolicyModal policies={[{ prefix: "test", policy: READ_ONLY }]} />,
)
expect(wrapper.find("Connect(PolicyInput)").length).toBe(1)
expect(wrapper.find("Connect(Policy)").length).toBe(1)
@@ -26,7 +26,11 @@ describe("BucketSearch", () => {
it("should call onChange with search text", () => {
const onChange = jest.fn()
const wrapper = shallow(<BucketSearch onChange={onChange} />)
wrapper.find("input").simulate("change", { target: { value: "test" } })
wrapper.find("input").simulate("change", {
target: {
value: "test",
},
})
expect(onChange).toHaveBeenCalledWith("test")
})
})
@@ -26,7 +26,7 @@ describe("MakeBucketModal", () => {
it("should call hideMakeBucketModal when close button is clicked", () => {
const hideMakeBucketModal = jest.fn()
const wrapper = shallow(
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />,
)
wrapper.find("button").simulate("click")
expect(hideMakeBucketModal).toHaveBeenCalled()
@@ -35,10 +35,12 @@ describe("MakeBucketModal", () => {
it("bucketName should be cleared before hiding the modal", () => {
const hideMakeBucketModal = jest.fn()
const wrapper = shallow(
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />
<MakeBucketModal hideMakeBucketModal={hideMakeBucketModal} />,
)
wrapper.find("input").simulate("change", {
target: { value: "test" }
target: {
value: "test",
},
})
expect(wrapper.state("bucketName")).toBe("test")
wrapper.find("button").simulate("click")
@@ -52,12 +54,16 @@ describe("MakeBucketModal", () => {
<MakeBucketModal
makeBucket={makeBucket}
hideMakeBucketModal={hideMakeBucketModal}
/>
/>,
)
wrapper.find("input").simulate("change", {
target: { value: "test" }
target: {
value: "test",
},
})
wrapper.find("form").simulate("submit", {
preventDefault: jest.fn(),
})
wrapper.find("form").simulate("submit", { preventDefault: jest.fn() })
expect(makeBucket).toHaveBeenCalledWith("test")
})
@@ -68,12 +74,16 @@ describe("MakeBucketModal", () => {
<MakeBucketModal
makeBucket={makeBucket}
hideMakeBucketModal={hideMakeBucketModal}
/>
/>,
)
wrapper.find("input").simulate("change", {
target: { value: "test" }
target: {
value: "test",
},
})
wrapper.find("form").simulate("submit", {
preventDefault: jest.fn(),
})
wrapper.find("form").simulate("submit", { preventDefault: jest.fn() })
expect(hideMakeBucketModal).toHaveBeenCalled()
expect(wrapper.state("bucketName")).toBe("")
})
@@ -23,32 +23,36 @@ import web from "../../web"
jest.mock("../../web", () => ({
SetBucketPolicy: jest.fn(() => {
return Promise.resolve()
})
}),
}))
describe("Policy", () => {
it("should render without crashing", () => {
shallow(<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />)
shallow(
<Policy currentBucket={"bucket"} prefix={"foo"} policy={READ_ONLY} />,
)
})
it("should call web.setBucketPolicy and fetchPolicies on submit", () => {
const fetchPolicies = jest.fn()
const wrapper = shallow(
<Policy
<Policy
currentBucket={"bucket"}
prefix={"foo"}
policy={READ_ONLY}
fetchPolicies={fetchPolicies}
/>
/>,
)
wrapper.find("button").simulate("click", { preventDefault: jest.fn() })
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
})
expect(web.SetBucketPolicy).toHaveBeenCalledWith({
bucketName: "bucket",
prefix: "foo",
policy: "none"
policy: "none",
})
setImmediate(() => {
expect(fetchPolicies).toHaveBeenCalledWith("bucket")
})
@@ -56,8 +60,13 @@ describe("Policy", () => {
it("should change the empty string to '*' while displaying prefixes", () => {
const wrapper = shallow(
<Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} />
<Policy currentBucket={"bucket"} prefix={""} policy={READ_ONLY} />,
)
expect(wrapper.find(".pmbl-item").at(0).text()).toEqual("*")
expect(
wrapper
.find(".pmbl-item")
.at(0)
.text(),
).toEqual("*")
})
})
@@ -23,19 +23,21 @@ import web from "../../web"
jest.mock("../../web", () => ({
SetBucketPolicy: jest.fn(() => {
return Promise.resolve()
})
}),
}))
describe("PolicyInput", () => {
it("should render without crashing", () => {
const fetchPolicies = jest.fn()
shallow(<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies}/>)
shallow(
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />,
)
})
it("should call fetchPolicies after the component has mounted", () => {
const fetchPolicies = jest.fn()
const wrapper = shallow(
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />
<PolicyInput currentBucket={"bucket"} fetchPolicies={fetchPolicies} />,
)
setImmediate(() => {
expect(fetchPolicies).toHaveBeenCalled()
@@ -45,16 +47,26 @@ describe("PolicyInput", () => {
it("should call web.setBucketPolicy and fetchPolicies on submit", () => {
const fetchPolicies = jest.fn()
const wrapper = shallow(
<PolicyInput currentBucket={"bucket"} policies={[]} fetchPolicies={fetchPolicies}/>
<PolicyInput
currentBucket={"bucket"}
policies={[]}
fetchPolicies={fetchPolicies}
/>,
)
wrapper.instance().prefix = { value: "baz" }
wrapper.instance().policy = { value: READ_ONLY }
wrapper.find("button").simulate("click", { preventDefault: jest.fn() })
wrapper.instance().prefix = {
value: "baz",
}
wrapper.instance().policy = {
value: READ_ONLY,
}
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
})
expect(web.SetBucketPolicy).toHaveBeenCalledWith({
bucketName: "bucket",
prefix: "baz",
policy: READ_ONLY
policy: READ_ONLY,
})
setImmediate(() => {
@@ -65,13 +77,25 @@ describe("PolicyInput", () => {
it("should change the prefix '*' to an empty string", () => {
const fetchPolicies = jest.fn()
const wrapper = shallow(
<PolicyInput currentBucket={"bucket"} policies={[]} fetchPolicies={fetchPolicies}/>
<PolicyInput
currentBucket={"bucket"}
policies={[]}
fetchPolicies={fetchPolicies}
/>,
)
wrapper.instance().prefix = { value: "*" }
wrapper.instance().policy = { value: READ_ONLY }
wrapper.instance().prefix = {
value: "*",
}
wrapper.instance().policy = {
value: READ_ONLY,
}
wrapper.find("button").simulate("click", { preventDefault: jest.fn() })
wrapper.find("button").simulate("click", {
preventDefault: jest.fn(),
})
expect(wrapper.instance().prefix).toEqual({ value: "" })
expect(wrapper.instance().prefix).toEqual({
value: "",
})
})
})
+113 -34
View File
@@ -17,23 +17,31 @@
import configureStore from "redux-mock-store"
import thunk from "redux-thunk"
import * as actionsBuckets from "../actions"
import * as objectActions from "../../objects/actions"
import history from "../../history"
jest.mock("../../web", () => ({
ListBuckets: jest.fn(() => {
return Promise.resolve({ buckets: [{ name: "test1" }, { name: "test2" }] })
return Promise.resolve({
buckets: [
{
name: "test1",
},
{
name: "test2",
},
],
})
}),
MakeBucket: jest.fn(() => {
return Promise.resolve()
}),
DeleteBucket: jest.fn(() => {
return Promise.resolve()
})
}),
}))
jest.mock("../../objects/actions", () => ({
selectPrefix: () => dispatch => {}
selectPrefix: () => dispatch => {},
}))
const middlewares = [thunk]
@@ -43,8 +51,14 @@ describe("Buckets actions", () => {
it("creates buckets/SET_LIST and buckets/SET_CURRENT_BUCKET with first bucket after fetching the buckets", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
]
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
const actions = store.getActions()
@@ -56,8 +70,14 @@ describe("Buckets actions", () => {
history.push("/test2")
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test2" }
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test2",
},
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
@@ -70,8 +90,14 @@ describe("Buckets actions", () => {
history.push("/test3")
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
]
window.location
return store.dispatch(actionsBuckets.fetchBuckets()).then(() => {
@@ -83,7 +109,10 @@ describe("Buckets actions", () => {
it("creates buckets/SET_CURRENT_BUCKET action when selectBucket is called", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
]
store.dispatch(actionsBuckets.selectBucket("test1"))
const actions = store.getActions()
@@ -93,7 +122,10 @@ describe("Buckets actions", () => {
it("creates buckets/SHOW_MAKE_BUCKET_MODAL for showMakeBucketModal", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_MAKE_BUCKET_MODAL", show: true }
{
type: "buckets/SHOW_MAKE_BUCKET_MODAL",
show: true,
},
]
store.dispatch(actionsBuckets.showMakeBucketModal())
const actions = store.getActions()
@@ -103,7 +135,10 @@ describe("Buckets actions", () => {
it("creates buckets/SHOW_MAKE_BUCKET_MODAL for hideMakeBucketModal", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_MAKE_BUCKET_MODAL", show: false }
{
type: "buckets/SHOW_MAKE_BUCKET_MODAL",
show: false,
},
]
store.dispatch(actionsBuckets.hideMakeBucketModal())
const actions = store.getActions()
@@ -113,7 +148,10 @@ describe("Buckets actions", () => {
it("creates buckets/SHOW_BUCKET_POLICY for showBucketPolicy", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_BUCKET_POLICY", show: true }
{
type: "buckets/SHOW_BUCKET_POLICY",
show: true,
},
]
store.dispatch(actionsBuckets.showBucketPolicy())
const actions = store.getActions()
@@ -123,7 +161,10 @@ describe("Buckets actions", () => {
it("creates buckets/SHOW_BUCKET_POLICY for hideBucketPolicy", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SHOW_BUCKET_POLICY", show: false }
{
type: "buckets/SHOW_BUCKET_POLICY",
show: false,
},
]
store.dispatch(actionsBuckets.hideBucketPolicy())
const actions = store.getActions()
@@ -133,7 +174,10 @@ describe("Buckets actions", () => {
it("creates buckets/SET_POLICIES action", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/SET_POLICIES", policies: ["test1", "test2"] }
{
type: "buckets/SET_POLICIES",
policies: ["test1", "test2"],
},
]
store.dispatch(actionsBuckets.setPolicies(["test1", "test2"]))
const actions = store.getActions()
@@ -142,7 +186,12 @@ describe("Buckets actions", () => {
it("creates buckets/ADD action", () => {
const store = mockStore()
const expectedActions = [{ type: "buckets/ADD", bucket: "test" }]
const expectedActions = [
{
type: "buckets/ADD",
bucket: "test",
},
]
store.dispatch(actionsBuckets.addBucket("test"))
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
@@ -150,7 +199,12 @@ describe("Buckets actions", () => {
it("creates buckets/REMOVE action", () => {
const store = mockStore()
const expectedActions = [{ type: "buckets/REMOVE", bucket: "test" }]
const expectedActions = [
{
type: "buckets/REMOVE",
bucket: "test",
},
]
store.dispatch(actionsBuckets.removeBucket("test"))
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
@@ -159,8 +213,14 @@ describe("Buckets actions", () => {
it("creates buckets/ADD and buckets/SET_CURRENT_BUCKET after creating the bucket", () => {
const store = mockStore()
const expectedActions = [
{ type: "buckets/ADD", bucket: "test1" },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
{
type: "buckets/ADD",
bucket: "test1",
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
]
return store.dispatch(actionsBuckets.makeBucket("test1")).then(() => {
const actions = store.getActions()
@@ -168,18 +228,37 @@ describe("Buckets actions", () => {
})
})
it("creates alert/SET, buckets/REMOVE, buckets/SET_LIST and buckets/SET_CURRENT_BUCKET " +
"after deleting the bucket", () => {
const store = mockStore()
const expectedActions = [
{ type: "alert/SET", alert: {id: 0, message: "Bucket 'test3' has been deleted.", type: "info"} },
{ type: "buckets/REMOVE", bucket: "test3" },
{ type: "buckets/SET_LIST", buckets: ["test1", "test2"] },
{ type: "buckets/SET_CURRENT_BUCKET", bucket: "test1" }
]
return store.dispatch(actionsBuckets.deleteBucket("test3")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
})
it(
"creates alert/SET, buckets/REMOVE, buckets/SET_LIST and buckets/SET_CURRENT_BUCKET " +
"after deleting the bucket",
() => {
const store = mockStore()
const expectedActions = [
{
type: "alert/SET",
alert: {
id: 0,
message: "Bucket 'test3' has been deleted.",
type: "info",
},
},
{
type: "buckets/REMOVE",
bucket: "test3",
},
{
type: "buckets/SET_LIST",
buckets: ["test1", "test2"],
},
{
type: "buckets/SET_CURRENT_BUCKET",
bucket: "test1",
},
]
return store.dispatch(actionsBuckets.deleteBucket("test3")).then(() => {
const actions = store.getActions()
expect(actions).toEqual(expectedActions)
})
},
)
})
@@ -26,36 +26,40 @@ describe("buckets reducer", () => {
filter: "",
currentBucket: "",
showBucketPolicy: false,
showMakeBucketModal: false
showMakeBucketModal: false,
})
})
it("should handle SET_LIST", () => {
const newState = reducer(undefined, {
type: actions.SET_LIST,
buckets: ["bk1", "bk2"]
buckets: ["bk1", "bk2"],
})
expect(newState.list).toEqual(["bk1", "bk2"])
})
it("should handle ADD", () => {
const newState = reducer(
{ list: ["test1", "test2"] },
{
list: ["test1", "test2"],
},
{
type: actions.ADD,
bucket: "test3"
}
bucket: "test3",
},
)
expect(newState.list).toEqual(["test3", "test1", "test2"])
})
it("should handle REMOVE", () => {
const newState = reducer(
{ list: ["test1", "test2"] },
{
list: ["test1", "test2"],
},
{
type: actions.REMOVE,
bucket: "test2"
}
bucket: "test2",
},
)
expect(newState.list).toEqual(["test1"])
})
@@ -63,7 +67,7 @@ describe("buckets reducer", () => {
it("should handle SET_FILTER", () => {
const newState = reducer(undefined, {
type: actions.SET_FILTER,
filter: "test"
filter: "test",
})
expect(newState.filter).toEqual("test")
})
@@ -71,7 +75,7 @@ describe("buckets reducer", () => {
it("should handle SET_CURRENT_BUCKET", () => {
const newState = reducer(undefined, {
type: actions.SET_CURRENT_BUCKET,
bucket: "test"
bucket: "test",
})
expect(newState.currentBucket).toEqual("test")
})
@@ -79,7 +83,7 @@ describe("buckets reducer", () => {
it("should handle SET_POLICIES", () => {
const newState = reducer(undefined, {
type: actions.SET_POLICIES,
policies: ["test1", "test2"]
policies: ["test1", "test2"],
})
expect(newState.policies).toEqual(["test1", "test2"])
})
@@ -87,15 +91,15 @@ describe("buckets reducer", () => {
it("should handle SHOW_BUCKET_POLICY", () => {
const newState = reducer(undefined, {
type: actions.SHOW_BUCKET_POLICY,
show: true
show: true,
})
expect(newState.showBucketPolicy).toBeTruthy()
})
it("should handle SHOW_MAKE_BUCKET_MODAL", () => {
const newState = reducer(undefined, {
type: actions.SHOW_MAKE_BUCKET_MODAL,
show: true
show: true,
})
expect(newState.showMakeBucketModal).toBeTruthy()
})
@@ -21,8 +21,8 @@ describe("getVisibleBuckets", () => {
beforeEach(() => {
state = {
buckets: {
list: ["test1", "test11", "test2"]
}
list: ["test1", "test11", "test2"],
},
}
})