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.
|
|
|
|
*/
|
|
|
|
|
2018-02-13 01:30:02 -05:00
|
|
|
import reducer from "../reducer"
|
|
|
|
import * as actions from "../actions"
|
2018-02-09 21:34:14 -05:00
|
|
|
|
|
|
|
describe("objects reducer", () => {
|
|
|
|
it("should return the initial state", () => {
|
|
|
|
const initialState = reducer(undefined, {})
|
|
|
|
expect(initialState).toEqual({
|
|
|
|
list: [],
|
|
|
|
sortBy: "",
|
|
|
|
sortOrder: false,
|
|
|
|
currentPrefix: "",
|
|
|
|
marker: "",
|
2018-02-18 23:07:59 -05:00
|
|
|
isTruncated: false,
|
2018-02-23 22:29:30 -05:00
|
|
|
prefixWritable: false,
|
2018-02-18 23:07:59 -05:00
|
|
|
shareObject: {
|
|
|
|
show: false,
|
|
|
|
object: "",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: ""
|
2018-02-20 21:00:43 -05:00
|
|
|
},
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: []
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle SET_LIST", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.SET_LIST,
|
2018-03-21 14:09:23 -04:00
|
|
|
objects: [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
],
|
2018-02-09 21:34:14 -05:00
|
|
|
marker: "obj2",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: false
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
2018-03-21 14:09:23 -04:00
|
|
|
expect(newState.list).toEqual([
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
])
|
2018-02-09 21:34:14 -05:00
|
|
|
expect(newState.marker).toBe("obj2")
|
|
|
|
expect(newState.isTruncated).toBeFalsy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle APPEND_LIST", () => {
|
|
|
|
const newState = reducer(
|
|
|
|
{
|
2018-03-21 14:09:23 -04:00
|
|
|
list: [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
],
|
2018-02-09 21:34:14 -05:00
|
|
|
marker: "obj2",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: true
|
2018-02-09 21:34:14 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: actions.APPEND_LIST,
|
2018-03-21 14:09:23 -04:00
|
|
|
objects: [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj3"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj4"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
],
|
2018-02-09 21:34:14 -05:00
|
|
|
marker: "obj4",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: false
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
)
|
|
|
|
expect(newState.list).toEqual([
|
2018-03-21 14:09:23 -04:00
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj3"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj4"
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
])
|
|
|
|
expect(newState.marker).toBe("obj4")
|
|
|
|
expect(newState.isTruncated).toBeFalsy()
|
|
|
|
})
|
|
|
|
|
2018-02-18 23:07:59 -05:00
|
|
|
it("should handle REMOVE", () => {
|
|
|
|
const newState = reducer(
|
2018-03-21 14:09:23 -04:00
|
|
|
{
|
|
|
|
list: [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
|
|
|
]
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
2018-02-18 23:07:59 -05:00
|
|
|
{
|
|
|
|
type: actions.REMOVE,
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj1"
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
)
|
2018-03-21 14:09:23 -04:00
|
|
|
expect(newState.list).toEqual([
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
])
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle REMOVE with non-existent object", () => {
|
|
|
|
const newState = reducer(
|
2018-03-21 14:09:23 -04:00
|
|
|
{
|
|
|
|
list: [
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
|
|
|
]
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
2018-02-18 23:07:59 -05:00
|
|
|
{
|
|
|
|
type: actions.REMOVE,
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj3"
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
)
|
2018-03-21 14:09:23 -04:00
|
|
|
expect(newState.list).toEqual([
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj1"
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "obj2"
|
|
|
|
}
|
2018-03-21 14:09:23 -04:00
|
|
|
])
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
|
2018-02-09 21:34:14 -05:00
|
|
|
it("should handle SET_SORT_BY", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.SET_SORT_BY,
|
2018-03-22 15:25:56 -04:00
|
|
|
sortBy: "name"
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
expect(newState.sortBy).toEqual("name")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle SET_SORT_ORDER", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.SET_SORT_ORDER,
|
2018-03-22 15:25:56 -04:00
|
|
|
sortOrder: true
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
expect(newState.sortOrder).toEqual(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle SET_CURRENT_PREFIX", () => {
|
|
|
|
const newState = reducer(
|
2018-03-21 14:09:23 -04:00
|
|
|
{
|
|
|
|
currentPrefix: "test1/",
|
|
|
|
marker: "abc",
|
2018-03-22 15:25:56 -04:00
|
|
|
isTruncated: true
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
2018-02-09 21:34:14 -05:00
|
|
|
{
|
|
|
|
type: actions.SET_CURRENT_PREFIX,
|
2018-03-22 15:25:56 -04:00
|
|
|
prefix: "test2/"
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
)
|
|
|
|
expect(newState.currentPrefix).toEqual("test2/")
|
|
|
|
expect(newState.marker).toEqual("")
|
|
|
|
expect(newState.isTruncated).toBeFalsy()
|
|
|
|
})
|
2018-02-18 23:07:59 -05:00
|
|
|
|
2018-02-23 22:29:30 -05:00
|
|
|
it("should handle SET_PREFIX_WRITABLE", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.SET_PREFIX_WRITABLE,
|
2018-03-22 15:25:56 -04:00
|
|
|
prefixWritable: true
|
2018-02-23 22:29:30 -05:00
|
|
|
})
|
|
|
|
expect(newState.prefixWritable).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
2018-02-18 23:07:59 -05:00
|
|
|
it("should handle SET_SHARE_OBJECT", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.SET_SHARE_OBJECT,
|
|
|
|
show: true,
|
|
|
|
object: "a.txt",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: "test"
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
expect(newState.shareObject).toEqual({
|
|
|
|
show: true,
|
|
|
|
object: "a.txt",
|
2018-03-22 15:25:56 -04:00
|
|
|
url: "test"
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
})
|
2018-02-20 21:00:43 -05:00
|
|
|
|
|
|
|
it("should handle CHECKED_LIST_ADD", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.CHECKED_LIST_ADD,
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj1"
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
expect(newState.checkedList).toEqual(["obj1"])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle SELECTED_LIST_REMOVE", () => {
|
|
|
|
const newState = reducer(
|
2018-03-21 14:09:23 -04:00
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: ["obj1", "obj2"]
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
2018-02-20 21:00:43 -05:00
|
|
|
{
|
|
|
|
type: actions.CHECKED_LIST_REMOVE,
|
2018-03-22 15:25:56 -04:00
|
|
|
object: "obj1"
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
)
|
|
|
|
expect(newState.checkedList).toEqual(["obj2"])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle CHECKED_LIST_RESET", () => {
|
|
|
|
const newState = reducer(
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
checkedList: ["obj1", "obj2"]
|
2018-03-21 14:09:23 -04:00
|
|
|
},
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
type: actions.CHECKED_LIST_RESET
|
|
|
|
}
|
2018-02-20 21:00:43 -05:00
|
|
|
)
|
|
|
|
expect(newState.checkedList).toEqual([])
|
|
|
|
})
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|