storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/__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 import { SORT_ORDER_ASC, SORT_BY_NAME } from "../../constants" 20 21 describe("objects reducer", () => { 22 it("should return the initial state", () => { 23 const initialState = reducer(undefined, {}) 24 expect(initialState).toEqual({ 25 list: [], 26 filter: "", 27 listLoading: false, 28 sortBy: "", 29 sortOrder: SORT_ORDER_ASC, 30 currentPrefix: "", 31 prefixWritable: false, 32 shareObject: { 33 show: false, 34 object: "", 35 url: "" 36 }, 37 checkedList: [] 38 }) 39 }) 40 41 it("should handle SET_LIST", () => { 42 const newState = reducer(undefined, { 43 type: actions.SET_LIST, 44 objects: [{ name: "obj1" }, { name: "obj2" }] 45 }) 46 expect(newState.list).toEqual([{ name: "obj1" }, { name: "obj2" }]) 47 }) 48 49 it("should handle REMOVE", () => { 50 const newState = reducer( 51 { list: [{ name: "obj1" }, { name: "obj2" }] }, 52 { 53 type: actions.REMOVE, 54 object: "obj1" 55 } 56 ) 57 expect(newState.list).toEqual([{ name: "obj2" }]) 58 }) 59 60 it("should handle REMOVE with non-existent object", () => { 61 const newState = reducer( 62 { list: [{ name: "obj1" }, { name: "obj2" }] }, 63 { 64 type: actions.REMOVE, 65 object: "obj3" 66 } 67 ) 68 expect(newState.list).toEqual([{ name: "obj1" }, { name: "obj2" }]) 69 }) 70 71 it("should handle SET_SORT_BY", () => { 72 const newState = reducer(undefined, { 73 type: actions.SET_SORT_BY, 74 sortBy: SORT_BY_NAME 75 }) 76 expect(newState.sortBy).toEqual(SORT_BY_NAME) 77 }) 78 79 it("should handle SET_SORT_ORDER", () => { 80 const newState = reducer(undefined, { 81 type: actions.SET_SORT_ORDER, 82 sortOrder: SORT_ORDER_ASC 83 }) 84 expect(newState.sortOrder).toEqual(SORT_ORDER_ASC) 85 }) 86 87 it("should handle SET_CURRENT_PREFIX", () => { 88 const newState = reducer( 89 { currentPrefix: "test1/" }, 90 { 91 type: actions.SET_CURRENT_PREFIX, 92 prefix: "test2/" 93 } 94 ) 95 expect(newState.currentPrefix).toEqual("test2/") 96 }) 97 98 it("should handle SET_PREFIX_WRITABLE", () => { 99 const newState = reducer(undefined, { 100 type: actions.SET_PREFIX_WRITABLE, 101 prefixWritable: true 102 }) 103 expect(newState.prefixWritable).toBeTruthy() 104 }) 105 106 it("should handle SET_SHARE_OBJECT", () => { 107 const newState = reducer(undefined, { 108 type: actions.SET_SHARE_OBJECT, 109 show: true, 110 object: "a.txt", 111 url: "test" 112 }) 113 expect(newState.shareObject).toEqual({ 114 show: true, 115 object: "a.txt", 116 url: "test" 117 }) 118 }) 119 120 it("should handle CHECKED_LIST_ADD", () => { 121 const newState = reducer(undefined, { 122 type: actions.CHECKED_LIST_ADD, 123 object: "obj1" 124 }) 125 expect(newState.checkedList).toEqual(["obj1"]) 126 }) 127 128 it("should handle SELECTED_LIST_REMOVE", () => { 129 const newState = reducer( 130 { checkedList: ["obj1", "obj2"] }, 131 { 132 type: actions.CHECKED_LIST_REMOVE, 133 object: "obj1" 134 } 135 ) 136 expect(newState.checkedList).toEqual(["obj2"]) 137 }) 138 139 it("should handle CHECKED_LIST_RESET", () => { 140 const newState = reducer( 141 { checkedList: ["obj1", "obj2"] }, 142 { 143 type: actions.CHECKED_LIST_RESET 144 } 145 ) 146 expect(newState.checkedList).toEqual([]) 147 }) 148 })