mirror of
https://github.com/minio/minio.git
synced 2025-11-22 02:35:30 -05:00
Browser: Update UI with new components and elements (#5671)
This commit is contained in:
@@ -26,7 +26,7 @@ describe("DeleteObjectConfirmModal", () => {
|
||||
it("should call deleteObject when Delete is clicked", () => {
|
||||
const deleteObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<DeleteObjectConfirmModal deleteObject={deleteObject} />
|
||||
<DeleteObjectConfirmModal deleteObject={deleteObject} />,
|
||||
)
|
||||
wrapper.find("ConfirmModal").prop("okHandler")()
|
||||
expect(deleteObject).toHaveBeenCalled()
|
||||
@@ -37,7 +37,7 @@ describe("DeleteObjectConfirmModal", () => {
|
||||
const wrapper = shallow(
|
||||
<DeleteObjectConfirmModal
|
||||
hideDeleteConfirmModal={hideDeleteConfirmModal}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper.find("ConfirmModal").prop("cancelHandler")()
|
||||
expect(hideDeleteConfirmModal).toHaveBeenCalled()
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Minio Cloud Storage (C) 2018 Minio, Inc.
|
||||
*
|
||||
* 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 } from "enzyme"
|
||||
import { ObjectActions } from "../ObjectActions"
|
||||
|
||||
describe("ObjectActions", () => {
|
||||
it("should render without crashing", () => {
|
||||
shallow(<ObjectActions object={{ name: "obj1" }} currentPrefix={"pre1/"} />)
|
||||
})
|
||||
|
||||
it("should show DeleteObjectConfirmModal when delete action is clicked", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectActions object={{ name: "obj1" }} currentPrefix={"pre1/"} />
|
||||
)
|
||||
wrapper
|
||||
.find("a")
|
||||
.last()
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
expect(wrapper.state("showDeleteConfirmation")).toBeTruthy()
|
||||
expect(wrapper.find("DeleteObjectConfirmModal").length).toBe(1)
|
||||
})
|
||||
|
||||
it("should hide DeleteObjectConfirmModal when Cancel button is clicked", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectActions object={{ name: "obj1" }} currentPrefix={"pre1/"} />
|
||||
)
|
||||
wrapper
|
||||
.find("a")
|
||||
.last()
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
wrapper.find("DeleteObjectConfirmModal").prop("hideDeleteConfirmModal")()
|
||||
wrapper.update()
|
||||
expect(wrapper.state("showDeleteConfirmation")).toBeFalsy()
|
||||
expect(wrapper.find("DeleteObjectConfirmModal").length).toBe(0)
|
||||
})
|
||||
|
||||
it("should call deleteObject with object name", () => {
|
||||
const deleteObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectActions
|
||||
object={{ name: "obj1" }}
|
||||
currentPrefix={"pre1/"}
|
||||
deleteObject={deleteObject}
|
||||
/>
|
||||
)
|
||||
wrapper
|
||||
.find("a")
|
||||
.last()
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
wrapper.find("DeleteObjectConfirmModal").prop("deleteObject")()
|
||||
expect(deleteObject).toHaveBeenCalledWith("obj1")
|
||||
})
|
||||
|
||||
it("should call shareObject with object and expiry", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectActions
|
||||
object={{ name: "obj1" }}
|
||||
currentPrefix={"pre1/"}
|
||||
shareObject={shareObject}
|
||||
/>
|
||||
)
|
||||
wrapper
|
||||
.find("a")
|
||||
.first()
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
expect(shareObject).toHaveBeenCalledWith("obj1", 5, 0, 0)
|
||||
})
|
||||
|
||||
it("should render ShareObjectModal when an object is shared", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectActions
|
||||
object={{ name: "obj1" }}
|
||||
currentPrefix={"pre1/"}
|
||||
showShareObjectModal={true}
|
||||
/>
|
||||
)
|
||||
expect(wrapper.find("Connect(ShareObjectModal)").length).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -31,19 +31,25 @@ describe("ObjectContainer", () => {
|
||||
|
||||
it("should pass actions to ObjectItem", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectContainer object={{ name: "test1.jpg" }} checkedObjectsCount={0} />
|
||||
<ObjectContainer
|
||||
object={{ name: "test1.jpg" }}
|
||||
checkedObjectsCount={0}
|
||||
/>,
|
||||
)
|
||||
expect(wrapper.find("Connect(ObjectItem)").prop("actionButtons")).not.toBe(
|
||||
undefined
|
||||
undefined,
|
||||
)
|
||||
})
|
||||
|
||||
it("should pass empty actions to ObjectItem when checkedObjectCount is more than 0", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectContainer object={{ name: "test1.jpg" }} checkedObjectsCount={1} />
|
||||
<ObjectContainer
|
||||
object={{ name: "test1.jpg" }}
|
||||
checkedObjectsCount={1}
|
||||
/>,
|
||||
)
|
||||
expect(wrapper.find("Connect(ObjectItem)").prop("actionButtons")).toBe(
|
||||
undefined
|
||||
undefined,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,14 +31,16 @@ describe("ObjectItem", () => {
|
||||
it("should call onClick when the object isclicked", () => {
|
||||
const onClick = jest.fn()
|
||||
const wrapper = shallow(<ObjectItem name={"test"} onClick={onClick} />)
|
||||
wrapper.find("a").simulate("click", { preventDefault: jest.fn() })
|
||||
wrapper.find("a").simulate("click", {
|
||||
preventDefault: jest.fn(),
|
||||
})
|
||||
expect(onClick).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("should call checkObject when the object/prefix is checked", () => {
|
||||
const checkObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectItem name={"test"} checked={false} checkObject={checkObject} />
|
||||
<ObjectItem name={"test"} checked={false} checkObject={checkObject} />,
|
||||
)
|
||||
wrapper.find("input[type='checkbox']").simulate("change")
|
||||
expect(checkObject).toHaveBeenCalledWith("test")
|
||||
@@ -52,7 +54,7 @@ describe("ObjectItem", () => {
|
||||
it("should call uncheckObject when the object/prefix is unchecked", () => {
|
||||
const uncheckObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectItem name={"test"} checked={true} uncheckObject={uncheckObject} />
|
||||
<ObjectItem name={"test"} checked={true} uncheckObject={uncheckObject} />,
|
||||
)
|
||||
wrapper.find("input[type='checkbox']").simulate("change")
|
||||
expect(uncheckObject).toHaveBeenCalledWith("test")
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("ObjectsBulkActions", () => {
|
||||
<ObjectsBulkActions
|
||||
checkedObjectsCount={1}
|
||||
downloadChecked={downloadChecked}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper.find("#download-checked").simulate("click")
|
||||
expect(downloadChecked).toHaveBeenCalled()
|
||||
@@ -43,7 +43,10 @@ describe("ObjectsBulkActions", () => {
|
||||
it("should call clearChecked when close button is clicked", () => {
|
||||
const clearChecked = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectsBulkActions checkedObjectsCount={1} clearChecked={clearChecked} />
|
||||
<ObjectsBulkActions
|
||||
checkedObjectsCount={1}
|
||||
clearChecked={clearChecked}
|
||||
/>,
|
||||
)
|
||||
wrapper.find("#close-bulk-actions").simulate("click")
|
||||
expect(clearChecked).toHaveBeenCalled()
|
||||
@@ -62,7 +65,7 @@ describe("ObjectsBulkActions", () => {
|
||||
<ObjectsBulkActions
|
||||
checkedObjectsCount={1}
|
||||
deleteChecked={deleteChecked}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper.find("#delete-checked").simulate("click")
|
||||
wrapper.update()
|
||||
|
||||
@@ -28,43 +28,43 @@ describe("ObjectsHeader", () => {
|
||||
const sortObjects = jest.fn()
|
||||
const wrapper = shallow(<ObjectsHeader sortObjects={sortObjects} />)
|
||||
expect(
|
||||
wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-asc")
|
||||
wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-asc"),
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-asc")
|
||||
wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-asc"),
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-asc")
|
||||
wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-asc"),
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should render name column with desc class when objects are sorted by name", () => {
|
||||
const sortObjects = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectsHeader sortObjects={sortObjects} sortNameOrder={true} />
|
||||
<ObjectsHeader sortObjects={sortObjects} sortNameOrder={true} />,
|
||||
)
|
||||
expect(
|
||||
wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-desc")
|
||||
wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-desc"),
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should render size column with desc class when objects are sorted by size", () => {
|
||||
const sortObjects = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectsHeader sortObjects={sortObjects} sortSizeOrder={true} />
|
||||
<ObjectsHeader sortObjects={sortObjects} sortSizeOrder={true} />,
|
||||
)
|
||||
expect(
|
||||
wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-desc")
|
||||
wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-desc"),
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should render last modified column with desc class when objects are sorted by last modified", () => {
|
||||
const sortObjects = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ObjectsHeader sortObjects={sortObjects} sortLastModifiedOrder={true} />
|
||||
<ObjectsHeader sortObjects={sortObjects} sortLastModifiedOrder={true} />,
|
||||
)
|
||||
expect(
|
||||
wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-desc")
|
||||
wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-desc"),
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ describe("ObjectsList", () => {
|
||||
|
||||
it("should render ObjectContainer for every object", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectsList objects={[{ name: "test1.jpg" }, { name: "test2.jpg" }]} />
|
||||
<ObjectsList objects={[{ name: "test1.jpg" }, { name: "test2.jpg" }]} />,
|
||||
)
|
||||
expect(wrapper.find("Connect(ObjectContainer)").length).toBe(2)
|
||||
})
|
||||
|
||||
it("should render PrefixContainer for every prefix", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectsList objects={[{ name: "abc/" }, { name: "xyz/" }]} />
|
||||
<ObjectsList objects={[{ name: "abc/" }, { name: "xyz/" }]} />,
|
||||
)
|
||||
expect(wrapper.find("Connect(PrefixContainer)").length).toBe(2)
|
||||
})
|
||||
|
||||
@@ -28,19 +28,26 @@ describe("ObjectsList", () => {
|
||||
<ObjectsListContainer
|
||||
objects={[{ name: "test1.jpg" }, { name: "test2.jpg" }]}
|
||||
loadObjects={jest.fn()}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
expect(wrapper.find("ObjectsList").length).toBe(1)
|
||||
expect(wrapper.find("ObjectsList").prop("objects")).toEqual([
|
||||
{ name: "test1.jpg" },
|
||||
{ name: "test2.jpg" }
|
||||
{
|
||||
name: "test1.jpg",
|
||||
},
|
||||
{
|
||||
name: "test2.jpg",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should show the loading indicator at the bottom if there are more elements to display", () => {
|
||||
const wrapper = shallow(
|
||||
<ObjectsListContainer currentBucket="test1" isTruncated={true} />
|
||||
<ObjectsListContainer currentBucket="test1" isTruncated={true} />,
|
||||
)
|
||||
expect(wrapper.find(".text-center").prop("style")).toHaveProperty(
|
||||
"display",
|
||||
"block",
|
||||
)
|
||||
expect(wrapper.find(".text-center").prop("style")).toHaveProperty("display", "block")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,26 +31,26 @@ describe("Path", () => {
|
||||
|
||||
it("should render bucket and prefix", () => {
|
||||
const wrapper = shallow(
|
||||
<Path currentBucket={"test1"} currentPrefix={"a/b/"} />
|
||||
<Path currentBucket={"test1"} currentPrefix={"a/b/"} />,
|
||||
)
|
||||
expect(wrapper.find("span").length).toBe(3)
|
||||
expect(
|
||||
wrapper
|
||||
.find("span")
|
||||
.at(0)
|
||||
.text()
|
||||
.text(),
|
||||
).toBe("test1")
|
||||
expect(
|
||||
wrapper
|
||||
.find("span")
|
||||
.at(1)
|
||||
.text()
|
||||
.text(),
|
||||
).toBe("a")
|
||||
expect(
|
||||
wrapper
|
||||
.find("span")
|
||||
.at(2)
|
||||
.text()
|
||||
.text(),
|
||||
).toBe("b")
|
||||
})
|
||||
|
||||
@@ -61,12 +61,14 @@ describe("Path", () => {
|
||||
currentBucket={"test1"}
|
||||
currentPrefix={"a/b/"}
|
||||
selectPrefix={selectPrefix}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper
|
||||
.find("a")
|
||||
.at(2)
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
.simulate("click", {
|
||||
preventDefault: jest.fn(),
|
||||
})
|
||||
expect(selectPrefix).toHaveBeenCalledWith("a/b/")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ describe("PrefixContainer", () => {
|
||||
object={{ name: "abc/" }}
|
||||
currentPrefix={"xyz/"}
|
||||
selectPrefix={selectPrefix}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper.find("Connect(ObjectItem)").prop("onClick")()
|
||||
expect(selectPrefix).toHaveBeenCalledWith("xyz/abc/")
|
||||
|
||||
@@ -20,13 +20,13 @@ import { ShareObjectModal } from "../ShareObjectModal"
|
||||
import {
|
||||
SHARE_OBJECT_EXPIRY_DAYS,
|
||||
SHARE_OBJECT_EXPIRY_HOURS,
|
||||
SHARE_OBJECT_EXPIRY_MINUTES
|
||||
SHARE_OBJECT_EXPIRY_MINUTES,
|
||||
} from "../../constants"
|
||||
|
||||
jest.mock("../../web", () => ({
|
||||
LoggedIn: jest.fn(() => {
|
||||
return true
|
||||
})
|
||||
}),
|
||||
}))
|
||||
|
||||
describe("ShareObjectModal", () => {
|
||||
@@ -35,7 +35,7 @@ describe("ShareObjectModal", () => {
|
||||
<ShareObjectModal
|
||||
object={{ name: "obj1" }}
|
||||
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -46,7 +46,7 @@ describe("ShareObjectModal", () => {
|
||||
object={{ name: "obj1" }}
|
||||
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
|
||||
hideShareObject={hideShareObject}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper
|
||||
.find("button")
|
||||
@@ -60,13 +60,13 @@ describe("ShareObjectModal", () => {
|
||||
<ShareObjectModal
|
||||
object={{ name: "obj1" }}
|
||||
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
expect(
|
||||
wrapper
|
||||
.find("input")
|
||||
.first()
|
||||
.prop("value")
|
||||
.prop("value"),
|
||||
).toBe(`${window.location.protocol}//test`)
|
||||
})
|
||||
|
||||
@@ -79,7 +79,7 @@ describe("ShareObjectModal", () => {
|
||||
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
|
||||
hideShareObject={hideShareObject}
|
||||
showCopyAlert={showCopyAlert}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
wrapper.find("CopyToClipboard").prop("onCopy")()
|
||||
expect(showCopyAlert).toHaveBeenCalledWith("Link copied to clipboard!")
|
||||
@@ -88,35 +88,41 @@ describe("ShareObjectModal", () => {
|
||||
|
||||
describe("Update expiry values", () => {
|
||||
const props = {
|
||||
object: { name: "obj1" },
|
||||
shareObjectDetails: { show: true, object: "obj1", url: "test" }
|
||||
object: {
|
||||
name: "obj1",
|
||||
},
|
||||
shareObjectDetails: {
|
||||
show: true,
|
||||
object: "obj1",
|
||||
url: "test",
|
||||
},
|
||||
}
|
||||
it("should have default expiry values", () => {
|
||||
const wrapper = shallow(<ShareObjectModal {...props} />)
|
||||
expect(wrapper.state("expiry")).toEqual({
|
||||
days: SHARE_OBJECT_EXPIRY_DAYS,
|
||||
hours: SHARE_OBJECT_EXPIRY_HOURS,
|
||||
minutes: SHARE_OBJECT_EXPIRY_MINUTES
|
||||
minutes: SHARE_OBJECT_EXPIRY_MINUTES,
|
||||
})
|
||||
})
|
||||
|
||||
it("should not allow any increments when days is already max", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />,
|
||||
)
|
||||
wrapper.setState({
|
||||
expiry: {
|
||||
days: 7,
|
||||
hours: 0,
|
||||
minutes: 0
|
||||
}
|
||||
minutes: 0,
|
||||
},
|
||||
})
|
||||
wrapper.find("#increase-hours").simulate("click")
|
||||
expect(wrapper.state("expiry")).toEqual({
|
||||
days: 7,
|
||||
hours: 0,
|
||||
minutes: 0
|
||||
minutes: 0,
|
||||
})
|
||||
expect(shareObject).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -124,14 +130,14 @@ describe("ShareObjectModal", () => {
|
||||
it("should not allow expiry values less than minimum value", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />,
|
||||
)
|
||||
wrapper.setState({
|
||||
expiry: {
|
||||
days: 5,
|
||||
hours: 0,
|
||||
minutes: 0
|
||||
}
|
||||
minutes: 0,
|
||||
},
|
||||
})
|
||||
wrapper.find("#decrease-hours").simulate("click")
|
||||
expect(wrapper.state("expiry").hours).toBe(0)
|
||||
@@ -143,14 +149,14 @@ describe("ShareObjectModal", () => {
|
||||
it("should not allow expiry values more than maximum value", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />,
|
||||
)
|
||||
wrapper.setState({
|
||||
expiry: {
|
||||
days: 1,
|
||||
hours: 23,
|
||||
minutes: 59
|
||||
}
|
||||
minutes: 59,
|
||||
},
|
||||
})
|
||||
wrapper.find("#increase-hours").simulate("click")
|
||||
expect(wrapper.state("expiry").hours).toBe(23)
|
||||
@@ -162,20 +168,20 @@ describe("ShareObjectModal", () => {
|
||||
it("should set hours and minutes to 0 when days reaches max", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />,
|
||||
)
|
||||
wrapper.setState({
|
||||
expiry: {
|
||||
days: 6,
|
||||
hours: 5,
|
||||
minutes: 30
|
||||
}
|
||||
minutes: 30,
|
||||
},
|
||||
})
|
||||
wrapper.find("#increase-days").simulate("click")
|
||||
expect(wrapper.state("expiry")).toEqual({
|
||||
days: 7,
|
||||
hours: 0,
|
||||
minutes: 0
|
||||
minutes: 0,
|
||||
})
|
||||
expect(shareObject).toHaveBeenCalled()
|
||||
})
|
||||
@@ -183,20 +189,20 @@ describe("ShareObjectModal", () => {
|
||||
it("should set days to MAX when all of them becomes 0", () => {
|
||||
const shareObject = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />
|
||||
<ShareObjectModal {...props} shareObject={shareObject} />,
|
||||
)
|
||||
wrapper.setState({
|
||||
expiry: {
|
||||
days: 0,
|
||||
hours: 1,
|
||||
minutes: 0
|
||||
}
|
||||
minutes: 0,
|
||||
},
|
||||
})
|
||||
wrapper.find("#decrease-hours").simulate("click")
|
||||
expect(wrapper.state("expiry")).toEqual({
|
||||
days: 7,
|
||||
hours: 0,
|
||||
minutes: 0
|
||||
minutes: 0,
|
||||
})
|
||||
expect(shareObject).toHaveBeenCalledWith("obj1", 7, 0, 0)
|
||||
})
|
||||
|
||||
@@ -24,35 +24,54 @@ jest.mock("../../web", () => ({
|
||||
LoggedIn: jest.fn(() => true).mockReturnValueOnce(false),
|
||||
ListObjects: jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
objects: [{ name: "test1" }, { name: "test2" }],
|
||||
objects: [
|
||||
{
|
||||
name: "test1",
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
},
|
||||
],
|
||||
istruncated: false,
|
||||
nextmarker: "test2",
|
||||
writable: false
|
||||
writable: false,
|
||||
})
|
||||
}),
|
||||
RemoveObject: jest.fn(({ bucketName, objects }) => {
|
||||
if (!bucketName) {
|
||||
return Promise.reject({ message: "Invalid bucket" })
|
||||
return Promise.reject({
|
||||
message: "Invalid bucket",
|
||||
})
|
||||
}
|
||||
return Promise.resolve({})
|
||||
}),
|
||||
PresignedGet: jest.fn(({ bucket, object }) => {
|
||||
if (!bucket) {
|
||||
return Promise.reject({ message: "Invalid bucket" })
|
||||
return Promise.reject({
|
||||
message: "Invalid bucket",
|
||||
})
|
||||
}
|
||||
return Promise.resolve({ url: "https://test.com/bk1/pre1/b.txt" })
|
||||
return Promise.resolve({
|
||||
url: "https://test.com/bk1/pre1/b.txt",
|
||||
})
|
||||
}),
|
||||
CreateURLToken: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve({ token: "test" })
|
||||
return Promise.resolve({
|
||||
token: "test",
|
||||
})
|
||||
})
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.reject({ message: "Error in creating token" })
|
||||
return Promise.reject({
|
||||
message: "Error in creating token",
|
||||
})
|
||||
})
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve({ token: "test" })
|
||||
})
|
||||
return Promise.resolve({
|
||||
token: "test",
|
||||
})
|
||||
}),
|
||||
}))
|
||||
|
||||
const middlewares = [thunk]
|
||||
@@ -64,17 +83,31 @@ describe("Objects actions", () => {
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_LIST",
|
||||
objects: [{ name: "test1" }, { name: "test2" }],
|
||||
objects: [
|
||||
{
|
||||
name: "test1",
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
},
|
||||
],
|
||||
isTruncated: false,
|
||||
marker: "test2"
|
||||
}
|
||||
marker: "test2",
|
||||
},
|
||||
]
|
||||
store.dispatch(
|
||||
actionsObjects.setList(
|
||||
[{ name: "test1" }, { name: "test2" }],
|
||||
[
|
||||
{
|
||||
name: "test1",
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
},
|
||||
],
|
||||
"test2",
|
||||
false
|
||||
)
|
||||
false,
|
||||
),
|
||||
)
|
||||
const actions = store.getActions()
|
||||
expect(actions).toEqual(expectedActions)
|
||||
@@ -85,8 +118,8 @@ describe("Objects actions", () => {
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_SORT_BY",
|
||||
sortBy: "name"
|
||||
}
|
||||
sortBy: "name",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.setSortBy("name"))
|
||||
const actions = store.getActions()
|
||||
@@ -98,8 +131,8 @@ describe("Objects actions", () => {
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_SORT_ORDER",
|
||||
sortOrder: true
|
||||
}
|
||||
sortOrder: true,
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.setSortOrder(true))
|
||||
const actions = store.getActions()
|
||||
@@ -108,28 +141,39 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates objects/SET_LIST after fetching the objects", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_LIST",
|
||||
objects: [{ name: "test1" }, { name: "test2" }],
|
||||
objects: [
|
||||
{
|
||||
name: "test1",
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
},
|
||||
],
|
||||
marker: "test2",
|
||||
isTruncated: false
|
||||
isTruncated: false,
|
||||
},
|
||||
{
|
||||
type: "objects/SET_SORT_BY",
|
||||
sortBy: ""
|
||||
sortBy: "",
|
||||
},
|
||||
{
|
||||
type: "objects/SET_SORT_ORDER",
|
||||
sortOrder: false
|
||||
sortOrder: false,
|
||||
},
|
||||
{
|
||||
type: "objects/SET_PREFIX_WRITABLE",
|
||||
prefixWritable: false
|
||||
}
|
||||
prefixWritable: false,
|
||||
},
|
||||
]
|
||||
return store.dispatch(actionsObjects.fetchObjects()).then(() => {
|
||||
const actions = store.getActions()
|
||||
@@ -139,20 +183,31 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates objects/APPEND_LIST after fetching more objects", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/APPEND_LIST",
|
||||
objects: [{ name: "test1" }, { name: "test2" }],
|
||||
objects: [
|
||||
{
|
||||
name: "test1",
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
},
|
||||
],
|
||||
marker: "test2",
|
||||
isTruncated: false
|
||||
isTruncated: false,
|
||||
},
|
||||
{
|
||||
type: "objects/SET_PREFIX_WRITABLE",
|
||||
prefixWritable: false
|
||||
}
|
||||
prefixWritable: false,
|
||||
},
|
||||
]
|
||||
return store.dispatch(actionsObjects.fetchObjects(true)).then(() => {
|
||||
const actions = store.getActions()
|
||||
@@ -167,24 +222,24 @@ describe("Objects actions", () => {
|
||||
sortBy: "",
|
||||
sortOrder: false,
|
||||
isTruncated: false,
|
||||
marker: ""
|
||||
}
|
||||
marker: "",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_SORT_BY",
|
||||
sortBy: "name"
|
||||
sortBy: "name",
|
||||
},
|
||||
{
|
||||
type: "objects/SET_SORT_ORDER",
|
||||
sortOrder: true
|
||||
sortOrder: true,
|
||||
},
|
||||
{
|
||||
type: "objects/SET_LIST",
|
||||
objects: [],
|
||||
isTruncated: false,
|
||||
marker: ""
|
||||
}
|
||||
marker: "",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.sortObjects("name"))
|
||||
const actions = store.getActions()
|
||||
@@ -193,12 +248,21 @@ describe("Objects actions", () => {
|
||||
|
||||
it("should update browser url and creates objects/SET_CURRENT_PREFIX and objects/CHECKED_LIST_RESET actions when selectPrefix is called", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "test" },
|
||||
objects: { currentPrefix: "" }
|
||||
buckets: {
|
||||
currentBucket: "test",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{ type: "objects/SET_CURRENT_PREFIX", prefix: "abc/" },
|
||||
{ type: "objects/CHECKED_LIST_RESET" }
|
||||
{
|
||||
type: "objects/SET_CURRENT_PREFIX",
|
||||
prefix: "abc/",
|
||||
},
|
||||
{
|
||||
type: "objects/CHECKED_LIST_RESET",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.selectPrefix("abc/"))
|
||||
const actions = store.getActions()
|
||||
@@ -209,7 +273,10 @@ describe("Objects actions", () => {
|
||||
it("create objects/SET_PREFIX_WRITABLE action", () => {
|
||||
const store = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: "objects/SET_PREFIX_WRITABLE", prefixWritable: true }
|
||||
{
|
||||
type: "objects/SET_PREFIX_WRITABLE",
|
||||
prefixWritable: true,
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.setPrefixWritable(true))
|
||||
const actions = store.getActions()
|
||||
@@ -218,7 +285,12 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates objects/REMOVE action", () => {
|
||||
const store = mockStore()
|
||||
const expectedActions = [{ type: "objects/REMOVE", object: "obj1" }]
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/REMOVE",
|
||||
object: "obj1",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.removeObject("obj1"))
|
||||
const actions = store.getActions()
|
||||
expect(actions).toEqual(expectedActions)
|
||||
@@ -226,10 +298,19 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates objects/REMOVE action when object is deleted", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "test" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "test",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
const expectedActions = [{ type: "objects/REMOVE", object: "obj1" }]
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/REMOVE",
|
||||
object: "obj1",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.deleteObject("obj1")).then(() => {
|
||||
const actions = store.getActions()
|
||||
expect(actions).toEqual(expectedActions)
|
||||
@@ -238,14 +319,22 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates alert/SET action when invalid bucket is provided", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "alert/SET",
|
||||
alert: { type: "danger", message: "Invalid bucket", id: 0 }
|
||||
}
|
||||
alert: {
|
||||
type: "danger",
|
||||
message: "Invalid bucket",
|
||||
id: 0,
|
||||
},
|
||||
},
|
||||
]
|
||||
return store.dispatch(actionsObjects.deleteObject("obj1")).then(() => {
|
||||
const actions = store.getActions()
|
||||
@@ -260,8 +349,8 @@ describe("Objects actions", () => {
|
||||
type: "objects/SET_SHARE_OBJECT",
|
||||
show: true,
|
||||
object: "b.txt",
|
||||
url: "test"
|
||||
}
|
||||
url: "test",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.showShareObject("b.txt", "test"))
|
||||
const actions = store.getActions()
|
||||
@@ -275,8 +364,8 @@ describe("Objects actions", () => {
|
||||
type: "objects/SET_SHARE_OBJECT",
|
||||
show: false,
|
||||
object: "",
|
||||
url: ""
|
||||
}
|
||||
url: "",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.hideShareObject())
|
||||
const actions = store.getActions()
|
||||
@@ -285,24 +374,28 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates objects/SET_SHARE_OBJECT when object is shared", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/SET_SHARE_OBJECT",
|
||||
show: true,
|
||||
object: "a.txt",
|
||||
url: "https://test.com/bk1/pre1/b.txt"
|
||||
url: "https://test.com/bk1/pre1/b.txt",
|
||||
},
|
||||
{
|
||||
type: "alert/SET",
|
||||
alert: {
|
||||
type: "success",
|
||||
message: "Object shared. Expires in 1 days 0 hours 0 minutes",
|
||||
id: alertActions.alertId
|
||||
}
|
||||
}
|
||||
id: alertActions.alertId,
|
||||
},
|
||||
},
|
||||
]
|
||||
return store
|
||||
.dispatch(actionsObjects.shareObject("a.txt", 1, 0, 0))
|
||||
@@ -314,8 +407,12 @@ describe("Objects actions", () => {
|
||||
|
||||
it("creates alert/SET when shareObject is failed", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
@@ -323,9 +420,9 @@ describe("Objects actions", () => {
|
||||
alert: {
|
||||
type: "danger",
|
||||
message: "Invalid bucket",
|
||||
id: alertActions.alertId
|
||||
}
|
||||
}
|
||||
id: alertActions.alertId,
|
||||
},
|
||||
},
|
||||
]
|
||||
return store
|
||||
.dispatch(actionsObjects.shareObject("a.txt", 1, 0, 0))
|
||||
@@ -341,11 +438,15 @@ describe("Objects actions", () => {
|
||||
Object.defineProperty(window, "location", {
|
||||
set(url) {
|
||||
setLocation(url)
|
||||
}
|
||||
},
|
||||
})
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
store.dispatch(actionsObjects.downloadObject("obj1"))
|
||||
const url = `${
|
||||
@@ -359,17 +460,21 @@ describe("Objects actions", () => {
|
||||
Object.defineProperty(window, "location", {
|
||||
set(url) {
|
||||
setLocation(url)
|
||||
}
|
||||
},
|
||||
})
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
return store.dispatch(actionsObjects.downloadObject("obj1")).then(() => {
|
||||
const url = `${
|
||||
window.location.origin
|
||||
}${minioBrowserPrefix}/download/bk1/${encodeURI(
|
||||
"pre1/obj1"
|
||||
"pre1/obj1",
|
||||
)}?token=test`
|
||||
expect(setLocation).toHaveBeenCalledWith(url)
|
||||
})
|
||||
@@ -377,8 +482,12 @@ describe("Objects actions", () => {
|
||||
|
||||
it("create alert/SET action when CreateUrlToken fails", () => {
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "pre1/" }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
},
|
||||
})
|
||||
const expectedActions = [
|
||||
{
|
||||
@@ -386,9 +495,9 @@ describe("Objects actions", () => {
|
||||
alert: {
|
||||
type: "danger",
|
||||
message: "Error in creating token",
|
||||
id: alertActions.alertId
|
||||
}
|
||||
}
|
||||
id: alertActions.alertId,
|
||||
},
|
||||
},
|
||||
]
|
||||
return store.dispatch(actionsObjects.downloadObject("obj1")).then(() => {
|
||||
const actions = store.getActions()
|
||||
@@ -402,8 +511,8 @@ describe("Objects actions", () => {
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/CHECKED_LIST_ADD",
|
||||
object: "obj1"
|
||||
}
|
||||
object: "obj1",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.checkObject("obj1"))
|
||||
const actions = store.getActions()
|
||||
@@ -415,8 +524,8 @@ describe("Objects actions", () => {
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/CHECKED_LIST_REMOVE",
|
||||
object: "obj1"
|
||||
}
|
||||
object: "obj1",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.uncheckObject("obj1"))
|
||||
const actions = store.getActions()
|
||||
@@ -427,8 +536,8 @@ describe("Objects actions", () => {
|
||||
const store = mockStore()
|
||||
const expectedActions = [
|
||||
{
|
||||
type: "objects/CHECKED_LIST_RESET"
|
||||
}
|
||||
type: "objects/CHECKED_LIST_RESET",
|
||||
},
|
||||
]
|
||||
store.dispatch(actionsObjects.resetCheckedList())
|
||||
const actions = store.getActions()
|
||||
@@ -440,13 +549,18 @@ describe("Objects actions", () => {
|
||||
const send = jest.fn()
|
||||
const xhrMockClass = () => ({
|
||||
open: open,
|
||||
send: send
|
||||
send: send,
|
||||
})
|
||||
window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
|
||||
|
||||
const store = mockStore({
|
||||
buckets: { currentBucket: "bk1" },
|
||||
objects: { currentPrefix: "pre1/", checkedList: ["obj1"] }
|
||||
buckets: {
|
||||
currentBucket: "bk1",
|
||||
},
|
||||
objects: {
|
||||
currentPrefix: "pre1/",
|
||||
checkedList: ["obj1"],
|
||||
},
|
||||
})
|
||||
return store.dispatch(actionsObjects.downloadCheckedObjects()).then(() => {
|
||||
const requestUrl = `${
|
||||
@@ -457,8 +571,8 @@ describe("Objects actions", () => {
|
||||
JSON.stringify({
|
||||
bucketName: "bk1",
|
||||
prefix: "pre1/",
|
||||
objects: ["obj1"]
|
||||
})
|
||||
objects: ["obj1"],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,20 +31,34 @@ describe("objects reducer", () => {
|
||||
shareObject: {
|
||||
show: false,
|
||||
object: "",
|
||||
url: ""
|
||||
url: "",
|
||||
},
|
||||
checkedList: []
|
||||
checkedList: [],
|
||||
})
|
||||
})
|
||||
|
||||
it("should handle SET_LIST", () => {
|
||||
const newState = reducer(undefined, {
|
||||
type: actions.SET_LIST,
|
||||
objects: [{ name: "obj1" }, { name: "obj2" }],
|
||||
objects: [
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
],
|
||||
marker: "obj2",
|
||||
isTruncated: false
|
||||
isTruncated: false,
|
||||
})
|
||||
expect(newState.list).toEqual([{ name: "obj1" }, { name: "obj2" }])
|
||||
expect(newState.list).toEqual([
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
])
|
||||
expect(newState.marker).toBe("obj2")
|
||||
expect(newState.isTruncated).toBeFalsy()
|
||||
})
|
||||
@@ -52,22 +66,44 @@ describe("objects reducer", () => {
|
||||
it("should handle APPEND_LIST", () => {
|
||||
const newState = reducer(
|
||||
{
|
||||
list: [{ name: "obj1" }, { name: "obj2" }],
|
||||
list: [
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
],
|
||||
marker: "obj2",
|
||||
isTruncated: true
|
||||
isTruncated: true,
|
||||
},
|
||||
{
|
||||
type: actions.APPEND_LIST,
|
||||
objects: [{ name: "obj3" }, { name: "obj4" }],
|
||||
objects: [
|
||||
{
|
||||
name: "obj3",
|
||||
},
|
||||
{
|
||||
name: "obj4",
|
||||
},
|
||||
],
|
||||
marker: "obj4",
|
||||
isTruncated: false
|
||||
}
|
||||
isTruncated: false,
|
||||
},
|
||||
)
|
||||
expect(newState.list).toEqual([
|
||||
{ name: "obj1" },
|
||||
{ name: "obj2" },
|
||||
{ name: "obj3" },
|
||||
{ name: "obj4" }
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
{
|
||||
name: "obj3",
|
||||
},
|
||||
{
|
||||
name: "obj4",
|
||||
},
|
||||
])
|
||||
expect(newState.marker).toBe("obj4")
|
||||
expect(newState.isTruncated).toBeFalsy()
|
||||
@@ -75,30 +111,59 @@ describe("objects reducer", () => {
|
||||
|
||||
it("should handle REMOVE", () => {
|
||||
const newState = reducer(
|
||||
{ list: [{ name: "obj1" }, { name: "obj2" }] },
|
||||
{
|
||||
list: [
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: actions.REMOVE,
|
||||
object: "obj1"
|
||||
}
|
||||
object: "obj1",
|
||||
},
|
||||
)
|
||||
expect(newState.list).toEqual([{ name: "obj2" }])
|
||||
expect(newState.list).toEqual([
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should handle REMOVE with non-existent object", () => {
|
||||
const newState = reducer(
|
||||
{ list: [{ name: "obj1" }, { name: "obj2" }] },
|
||||
{
|
||||
list: [
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: actions.REMOVE,
|
||||
object: "obj3"
|
||||
}
|
||||
object: "obj3",
|
||||
},
|
||||
)
|
||||
expect(newState.list).toEqual([{ name: "obj1" }, { name: "obj2" }])
|
||||
expect(newState.list).toEqual([
|
||||
{
|
||||
name: "obj1",
|
||||
},
|
||||
{
|
||||
name: "obj2",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should handle SET_SORT_BY", () => {
|
||||
const newState = reducer(undefined, {
|
||||
type: actions.SET_SORT_BY,
|
||||
sortBy: "name"
|
||||
sortBy: "name",
|
||||
})
|
||||
expect(newState.sortBy).toEqual("name")
|
||||
})
|
||||
@@ -106,18 +171,22 @@ describe("objects reducer", () => {
|
||||
it("should handle SET_SORT_ORDER", () => {
|
||||
const newState = reducer(undefined, {
|
||||
type: actions.SET_SORT_ORDER,
|
||||
sortOrder: true
|
||||
sortOrder: true,
|
||||
})
|
||||
expect(newState.sortOrder).toEqual(true)
|
||||
})
|
||||
|
||||
it("should handle SET_CURRENT_PREFIX", () => {
|
||||
const newState = reducer(
|
||||
{ currentPrefix: "test1/", marker: "abc", isTruncated: true },
|
||||
{
|
||||
currentPrefix: "test1/",
|
||||
marker: "abc",
|
||||
isTruncated: true,
|
||||
},
|
||||
{
|
||||
type: actions.SET_CURRENT_PREFIX,
|
||||
prefix: "test2/"
|
||||
}
|
||||
prefix: "test2/",
|
||||
},
|
||||
)
|
||||
expect(newState.currentPrefix).toEqual("test2/")
|
||||
expect(newState.marker).toEqual("")
|
||||
@@ -127,7 +196,7 @@ describe("objects reducer", () => {
|
||||
it("should handle SET_PREFIX_WRITABLE", () => {
|
||||
const newState = reducer(undefined, {
|
||||
type: actions.SET_PREFIX_WRITABLE,
|
||||
prefixWritable: true
|
||||
prefixWritable: true,
|
||||
})
|
||||
expect(newState.prefixWritable).toBeTruthy()
|
||||
})
|
||||
@@ -137,40 +206,44 @@ describe("objects reducer", () => {
|
||||
type: actions.SET_SHARE_OBJECT,
|
||||
show: true,
|
||||
object: "a.txt",
|
||||
url: "test"
|
||||
url: "test",
|
||||
})
|
||||
expect(newState.shareObject).toEqual({
|
||||
show: true,
|
||||
object: "a.txt",
|
||||
url: "test"
|
||||
url: "test",
|
||||
})
|
||||
})
|
||||
|
||||
it("should handle CHECKED_LIST_ADD", () => {
|
||||
const newState = reducer(undefined, {
|
||||
type: actions.CHECKED_LIST_ADD,
|
||||
object: "obj1"
|
||||
object: "obj1",
|
||||
})
|
||||
expect(newState.checkedList).toEqual(["obj1"])
|
||||
})
|
||||
|
||||
it("should handle SELECTED_LIST_REMOVE", () => {
|
||||
const newState = reducer(
|
||||
{ checkedList: ["obj1", "obj2"] },
|
||||
{
|
||||
checkedList: ["obj1", "obj2"],
|
||||
},
|
||||
{
|
||||
type: actions.CHECKED_LIST_REMOVE,
|
||||
object: "obj1"
|
||||
}
|
||||
object: "obj1",
|
||||
},
|
||||
)
|
||||
expect(newState.checkedList).toEqual(["obj2"])
|
||||
})
|
||||
|
||||
it("should handle CHECKED_LIST_RESET", () => {
|
||||
const newState = reducer(
|
||||
{ checkedList: ["obj1", "obj2"] },
|
||||
{
|
||||
type: actions.CHECKED_LIST_RESET
|
||||
}
|
||||
checkedList: ["obj1", "obj2"],
|
||||
},
|
||||
{
|
||||
type: actions.CHECKED_LIST_RESET,
|
||||
},
|
||||
)
|
||||
expect(newState.checkedList).toEqual([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user