storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/uploads/__tests__/reducer.test.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import reducer from "../reducer" 18 import * as actions from "../actions" 19 20 describe("uploads reducer", () => { 21 it("should return the initial state", () => { 22 const initialState = reducer(undefined, {}) 23 expect(initialState).toEqual({ 24 files: {}, 25 showAbortModal: false 26 }) 27 }) 28 29 it("should handle ADD", () => { 30 const newState = reducer(undefined, { 31 type: actions.ADD, 32 slug: "a-b-c", 33 size: 100, 34 name: "test" 35 }) 36 expect(newState.files).toEqual({ 37 "a-b-c": { loaded: 0, size: 100, name: "test" } 38 }) 39 }) 40 41 it("should handle UPDATE_PROGRESS", () => { 42 const newState = reducer( 43 { 44 files: { "a-b-c": { loaded: 0, size: 100, name: "test" } } 45 }, 46 { 47 type: actions.UPDATE_PROGRESS, 48 slug: "a-b-c", 49 loaded: 50 50 } 51 ) 52 expect(newState.files).toEqual({ 53 "a-b-c": { loaded: 50, size: 100, name: "test" } 54 }) 55 }) 56 57 it("should handle STOP", () => { 58 const newState = reducer( 59 { 60 files: { 61 "a-b-c": { loaded: 70, size: 100, name: "test1" }, 62 "x-y-z": { loaded: 50, size: 100, name: "test2" } 63 } 64 }, 65 { 66 type: actions.STOP, 67 slug: "a-b-c" 68 } 69 ) 70 expect(newState.files).toEqual({ 71 "x-y-z": { loaded: 50, size: 100, name: "test2" } 72 }) 73 }) 74 75 it("should handle SHOW_ABORT_MODAL", () => { 76 const newState = reducer( 77 { 78 showAbortModal: false 79 }, 80 { 81 type: actions.SHOW_ABORT_MODAL, 82 show: true 83 } 84 ) 85 expect(newState.showAbortModal).toBeTruthy() 86 }) 87 })