2018-02-09 21:34:14 -05:00
|
|
|
/*
|
|
|
|
* 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 configureStore from "redux-mock-store"
|
|
|
|
import thunk from "redux-thunk"
|
2018-02-13 01:30:02 -05:00
|
|
|
import * as actionsObjects from "../actions"
|
2018-02-18 23:07:59 -05:00
|
|
|
import * as alertActions from "../../alert/actions"
|
2018-02-20 21:00:43 -05:00
|
|
|
import { minioBrowserPrefix } from "../../constants"
|
2018-02-09 21:34:14 -05:00
|
|
|
|
|
|
|
jest.mock("../../web", () => ({
|
2018-02-20 21:00:43 -05:00
|
|
|
LoggedIn: jest.fn(() => true).mockReturnValueOnce(false),
|
2018-02-09 21:34:14 -05:00
|
|
|
ListObjects: jest.fn(() => {
|
|
|
|
return Promise.resolve({
|
2018-03-26 15:49:12 -04:00
|
|
|
objects: [{ name: "test1" }, { name: "test2" }],
|
2018-02-09 21:34:14 -05:00
|
|
|
istruncated: false,
|
2018-02-23 22:29:30 -05:00
|
|
|
nextmarker: "test2",
|
2018-03-22 15:25:56 -04:00
|
|
|
writable: false
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
2018-02-18 23:07:59 -05:00
|
|
|
}),
|
|
|
|
RemoveObject: jest.fn(({ bucketName, objects }) => {
|
|
|
|
if (!bucketName) {
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.reject({ message: "Invalid bucket" })
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
return Promise.resolve({})
|
|
|
|
}),
|
|
|
|
PresignedGet: jest.fn(({ bucket, object }) => {
|
|
|
|
if (!bucket) {
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.reject({ message: "Invalid bucket" })
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.resolve({ url: "https://test.com/bk1/pre1/b.txt" })
|
2018-02-20 21:00:43 -05:00
|
|
|
}),
|
|
|
|
CreateURLToken: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementationOnce(() => {
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.resolve({ token: "test" })
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
.mockImplementationOnce(() => {
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.reject({ message: "Error in creating token" })
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
.mockImplementationOnce(() => {
|
2018-03-26 15:49:12 -04:00
|
|
|
return Promise.resolve({ token: "test" })
|
2018-03-22 15:25:56 -04:00
|
|
|
})
|
2018-02-09 21:34:14 -05:00
|
|
|
}))
|
|
|
|
|
|
|
|
const middlewares = [thunk]
|
|
|
|
const mockStore = configureStore(middlewares)
|
|
|
|
|
|
|
|
describe("Objects actions", () => {
|
|
|
|
it("creates objects/SET_LIST action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_LIST",
|
2018-03-26 15:49:12 -04:00
|
|
|
objects: [{ name: "test1" }, { name: "test2" }],
|
2018-02-09 21:34:14 -05:00
|
|
|
isTruncated: false,
|
2018-03-22 15:25:56 -04:00
|
|
|
marker: "test2"
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
store.dispatch(
|
|
|
|
actionsObjects.setList(
|
2018-03-26 15:49:12 -04:00
|
|
|
[{ name: "test1" }, { name: "test2" }],
|
2018-02-09 21:34:14 -05:00
|
|
|
"test2",
|
2018-03-22 15:25:56 -04:00
|
|
|
false
|
|
|
|
)
|
2018-02-09 21:34:14 -05:00
|
|
|
)
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SORT_BY action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_BY",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortBy: "name"
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.setSortBy("name"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SORT_ORDER action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_ORDER",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortOrder: true
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.setSortOrder(true))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_LIST after fetching the objects", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "" }
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_LIST",
|
2018-03-26 15:49:12 -04:00
|
|
|
objects: [{ name: "test1" }, { name: "test2" }],
|
2018-02-09 21:34:14 -05:00
|
|
|
marker: "test2",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: false
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_BY",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortBy: ""
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_ORDER",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortOrder: false
|
2018-02-23 22:29:30 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_PREFIX_WRITABLE",
|
2018-03-22 15:25:56 -04:00
|
|
|
prefixWritable: false
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
return store.dispatch(actionsObjects.fetchObjects()).then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/APPEND_LIST after fetching more objects", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "" }
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/APPEND_LIST",
|
2018-03-26 15:49:12 -04:00
|
|
|
objects: [{ name: "test1" }, { name: "test2" }],
|
2018-02-09 21:34:14 -05:00
|
|
|
marker: "test2",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: false
|
2018-02-23 22:29:30 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_PREFIX_WRITABLE",
|
2018-03-22 15:25:56 -04:00
|
|
|
prefixWritable: false
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
return store.dispatch(actionsObjects.fetchObjects(true)).then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SORT_BY and objects/SET_SORT_ORDER when sortObjects is called", () => {
|
|
|
|
const store = mockStore({
|
|
|
|
objects: {
|
|
|
|
list: [],
|
|
|
|
sortBy: "",
|
|
|
|
sortOrder: false,
|
|
|
|
isTruncated: false,
|
2018-03-22 15:25:56 -04:00
|
|
|
marker: ""
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_BY",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortBy: "name"
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_SORT_ORDER",
|
2018-03-22 15:25:56 -04:00
|
|
|
sortOrder: true
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "objects/SET_LIST",
|
|
|
|
objects: [],
|
|
|
|
isTruncated: false,
|
2018-03-22 15:25:56 -04:00
|
|
|
marker: ""
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.sortObjects("name"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
2018-02-20 21:00:43 -05:00
|
|
|
it("should update browser url and creates objects/SET_CURRENT_PREFIX and objects/CHECKED_LIST_RESET actions when selectPrefix is called", () => {
|
2018-02-09 21:34:14 -05:00
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "test" },
|
|
|
|
objects: { currentPrefix: "" }
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
2018-03-26 15:49:12 -04:00
|
|
|
{ type: "objects/SET_CURRENT_PREFIX", prefix: "abc/" },
|
|
|
|
{ type: "objects/CHECKED_LIST_RESET" }
|
2018-02-09 21:34:14 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.selectPrefix("abc/"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
expect(window.location.pathname.endsWith("/test/abc/")).toBeTruthy()
|
|
|
|
})
|
2018-02-18 23:07:59 -05:00
|
|
|
|
2018-02-23 22:29:30 -05:00
|
|
|
it("create objects/SET_PREFIX_WRITABLE action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
2018-03-26 15:49:12 -04:00
|
|
|
{ type: "objects/SET_PREFIX_WRITABLE", prefixWritable: true }
|
2018-02-23 22:29:30 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.setPrefixWritable(true))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
2018-02-18 23:07:59 -05:00
|
|
|
it("creates objects/REMOVE action", () => {
|
|
|
|
const store = mockStore()
|
2018-03-26 15:49:12 -04:00
|
|
|
const expectedActions = [{ type: "objects/REMOVE", object: "obj1" }]
|
2018-02-18 23:07:59 -05:00
|
|
|
store.dispatch(actionsObjects.removeObject("obj1"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/REMOVE action when object is deleted", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "test" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
2018-03-26 15:49:12 -04:00
|
|
|
const expectedActions = [{ type: "objects/REMOVE", object: "obj1" }]
|
2018-02-18 23:07:59 -05:00
|
|
|
store.dispatch(actionsObjects.deleteObject("obj1")).then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates alert/SET action when invalid bucket is provided", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "alert/SET",
|
2018-03-26 15:49:12 -04:00
|
|
|
alert: { type: "danger", message: "Invalid bucket", id: 0 }
|
2018-03-22 15:25:56 -04:00
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
]
|
|
|
|
return store.dispatch(actionsObjects.deleteObject("obj1")).then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SHARE_OBJECT action for showShareObject", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SHARE_OBJECT",
|
|
|
|
show: true,
|
|
|
|
object: "b.txt",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: "test"
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.showShareObject("b.txt", "test"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SHARE_OBJECT action for hideShareObject", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SHARE_OBJECT",
|
|
|
|
show: false,
|
|
|
|
object: "",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: ""
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.hideShareObject())
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/SET_SHARE_OBJECT when object is shared", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/SET_SHARE_OBJECT",
|
|
|
|
show: true,
|
|
|
|
object: "a.txt",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: "https://test.com/bk1/pre1/b.txt"
|
2018-02-18 23:07:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "alert/SET",
|
|
|
|
alert: {
|
|
|
|
type: "success",
|
|
|
|
message: "Object shared. Expires in 1 days 0 hours 0 minutes",
|
2018-03-22 15:25:56 -04:00
|
|
|
id: alertActions.alertId
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
]
|
|
|
|
return store
|
|
|
|
.dispatch(actionsObjects.shareObject("a.txt", 1, 0, 0))
|
|
|
|
.then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates alert/SET when shareObject is failed", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "alert/SET",
|
|
|
|
alert: {
|
|
|
|
type: "danger",
|
|
|
|
message: "Invalid bucket",
|
2018-03-22 15:25:56 -04:00
|
|
|
id: alertActions.alertId
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
]
|
|
|
|
return store
|
|
|
|
.dispatch(actionsObjects.shareObject("a.txt", 1, 0, 0))
|
|
|
|
.then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
2018-02-20 21:00:43 -05:00
|
|
|
|
|
|
|
describe("Download object", () => {
|
|
|
|
it("should download the object non-LoggedIn users", () => {
|
|
|
|
const setLocation = jest.fn()
|
|
|
|
Object.defineProperty(window, "location", {
|
|
|
|
set(url) {
|
|
|
|
setLocation(url)
|
2018-03-23 05:06:20 -04:00
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return {
|
|
|
|
origin: "http://localhost:8080"
|
|
|
|
}
|
2018-03-22 15:25:56 -04:00
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
store.dispatch(actionsObjects.downloadObject("obj1"))
|
|
|
|
const url = `${
|
|
|
|
window.location.origin
|
|
|
|
}${minioBrowserPrefix}/download/bk1/${encodeURI("pre1/obj1")}?token=''`
|
|
|
|
expect(setLocation).toHaveBeenCalledWith(url)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should download the object for LoggedIn users", () => {
|
|
|
|
const setLocation = jest.fn()
|
|
|
|
Object.defineProperty(window, "location", {
|
|
|
|
set(url) {
|
|
|
|
setLocation(url)
|
2018-03-23 05:06:20 -04:00
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return {
|
|
|
|
origin: "http://localhost:8080"
|
|
|
|
}
|
2018-03-22 15:25:56 -04:00
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
return store.dispatch(actionsObjects.downloadObject("obj1")).then(() => {
|
|
|
|
const url = `${
|
|
|
|
window.location.origin
|
|
|
|
}${minioBrowserPrefix}/download/bk1/${encodeURI(
|
2018-03-22 15:25:56 -04:00
|
|
|
"pre1/obj1"
|
2018-02-20 21:00:43 -05:00
|
|
|
)}?token=test`
|
|
|
|
expect(setLocation).toHaveBeenCalledWith(url)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("create alert/SET action when CreateUrlToken fails", () => {
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "pre1/" }
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "alert/SET",
|
|
|
|
alert: {
|
|
|
|
type: "danger",
|
|
|
|
message: "Error in creating token",
|
2018-03-22 15:25:56 -04:00
|
|
|
id: alertActions.alertId
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
]
|
|
|
|
return store.dispatch(actionsObjects.downloadObject("obj1")).then(() => {
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/CHECKED_LIST_ADD action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/CHECKED_LIST_ADD",
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj1"
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.checkObject("obj1"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/CHECKED_LIST_REMOVE action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
|
|
|
type: "objects/CHECKED_LIST_REMOVE",
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj1"
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.uncheckObject("obj1"))
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("creates objects/CHECKED_LIST_RESET action", () => {
|
|
|
|
const store = mockStore()
|
|
|
|
const expectedActions = [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
type: "objects/CHECKED_LIST_RESET"
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
]
|
|
|
|
store.dispatch(actionsObjects.resetCheckedList())
|
|
|
|
const actions = store.getActions()
|
|
|
|
expect(actions).toEqual(expectedActions)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should download checked objects", () => {
|
|
|
|
const open = jest.fn()
|
|
|
|
const send = jest.fn()
|
|
|
|
const xhrMockClass = () => ({
|
|
|
|
open: open,
|
2018-03-22 15:25:56 -04:00
|
|
|
send: send
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
|
|
|
|
|
|
|
|
const store = mockStore({
|
2018-03-26 15:49:12 -04:00
|
|
|
buckets: { currentBucket: "bk1" },
|
|
|
|
objects: { currentPrefix: "pre1/", checkedList: ["obj1"] }
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
return store.dispatch(actionsObjects.downloadCheckedObjects()).then(() => {
|
|
|
|
const requestUrl = `${
|
|
|
|
location.origin
|
|
|
|
}${minioBrowserPrefix}/zip?token=test`
|
|
|
|
expect(open).toHaveBeenCalledWith("POST", requestUrl, true)
|
|
|
|
expect(send).toHaveBeenCalledWith(
|
|
|
|
JSON.stringify({
|
|
|
|
bucketName: "bk1",
|
|
|
|
prefix: "pre1/",
|
2018-03-22 15:25:56 -04:00
|
|
|
objects: ["obj1"]
|
|
|
|
})
|
2018-02-20 21:00:43 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|