2018-02-14 21:34:59 -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 reducer from "../reducer"
|
|
|
|
import * as actions from "../actions"
|
|
|
|
|
|
|
|
describe("uploads reducer", () => {
|
|
|
|
it("should return the initial state", () => {
|
|
|
|
const initialState = reducer(undefined, {})
|
|
|
|
expect(initialState).toEqual({
|
|
|
|
files: {},
|
2018-03-22 15:25:56 -04:00
|
|
|
showAbortModal: false
|
2018-02-14 21:34:59 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle ADD", () => {
|
|
|
|
const newState = reducer(undefined, {
|
|
|
|
type: actions.ADD,
|
|
|
|
slug: "a-b-c",
|
|
|
|
size: 100,
|
2018-03-22 15:25:56 -04:00
|
|
|
name: "test"
|
2018-02-14 21:34:59 -05:00
|
|
|
})
|
|
|
|
expect(newState.files).toEqual({
|
2018-03-26 15:49:12 -04:00
|
|
|
"a-b-c": { loaded: 0, size: 100, name: "test" }
|
2018-02-14 21:34:59 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle UPDATE_PROGRESS", () => {
|
|
|
|
const newState = reducer(
|
|
|
|
{
|
2018-03-26 15:49:12 -04:00
|
|
|
files: { "a-b-c": { loaded: 0, size: 100, name: "test" } }
|
2018-02-14 21:34:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: actions.UPDATE_PROGRESS,
|
|
|
|
slug: "a-b-c",
|
2018-03-22 15:25:56 -04:00
|
|
|
loaded: 50
|
|
|
|
}
|
2018-02-14 21:34:59 -05:00
|
|
|
)
|
|
|
|
expect(newState.files).toEqual({
|
2018-03-26 15:49:12 -04:00
|
|
|
"a-b-c": { loaded: 50, size: 100, name: "test" }
|
2018-02-14 21:34:59 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle STOP", () => {
|
|
|
|
const newState = reducer(
|
|
|
|
{
|
|
|
|
files: {
|
2018-03-26 15:49:12 -04:00
|
|
|
"a-b-c": { loaded: 70, size: 100, name: "test1" },
|
|
|
|
"x-y-z": { loaded: 50, size: 100, name: "test2" }
|
2018-03-22 15:25:56 -04:00
|
|
|
}
|
2018-02-14 21:34:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: actions.STOP,
|
2018-03-22 15:25:56 -04:00
|
|
|
slug: "a-b-c"
|
|
|
|
}
|
2018-02-14 21:34:59 -05:00
|
|
|
)
|
|
|
|
expect(newState.files).toEqual({
|
2018-03-26 15:49:12 -04:00
|
|
|
"x-y-z": { loaded: 50, size: 100, name: "test2" }
|
2018-02-14 21:34:59 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should handle SHOW_ABORT_MODAL", () => {
|
|
|
|
const newState = reducer(
|
|
|
|
{
|
2018-03-22 15:25:56 -04:00
|
|
|
showAbortModal: false
|
2018-02-14 21:34:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: actions.SHOW_ABORT_MODAL,
|
2018-03-22 15:25:56 -04:00
|
|
|
show: true
|
|
|
|
}
|
2018-02-14 21:34:59 -05:00
|
|
|
)
|
|
|
|
expect(newState.showAbortModal).toBeTruthy()
|
|
|
|
})
|
|
|
|
})
|