storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/buckets/__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("buckets reducer", () => {
    21    it("should return the initial state", () => {
    22      const initialState = reducer(undefined, {})
    23      expect(initialState).toEqual({
    24        list: [],
    25        policies: [],
    26        filter: "",
    27        currentBucket: "",
    28        showBucketPolicy: false,
    29        showMakeBucketModal: false
    30      })
    31    })
    32  
    33    it("should handle SET_LIST", () => {
    34      const newState = reducer(undefined, {
    35        type: actions.SET_LIST,
    36        buckets: ["bk1", "bk2"]
    37      })
    38      expect(newState.list).toEqual(["bk1", "bk2"])
    39    })
    40  
    41    it("should handle ADD", () => {
    42      const newState = reducer(
    43        { list: ["test1", "test2"] },
    44        {
    45          type: actions.ADD,
    46          bucket: "test3"
    47        }
    48      )
    49      expect(newState.list).toEqual(["test3", "test1", "test2"])
    50    })
    51  
    52    it("should handle REMOVE", () => {
    53      const newState = reducer(
    54        { list: ["test1", "test2"] },
    55        {
    56          type: actions.REMOVE,
    57          bucket: "test2"
    58        }
    59      )
    60      expect(newState.list).toEqual(["test1"])
    61    })
    62  
    63    it("should handle SET_FILTER", () => {
    64      const newState = reducer(undefined, {
    65        type: actions.SET_FILTER,
    66        filter: "test"
    67      })
    68      expect(newState.filter).toEqual("test")
    69    })
    70  
    71    it("should handle SET_CURRENT_BUCKET", () => {
    72      const newState = reducer(undefined, {
    73        type: actions.SET_CURRENT_BUCKET,
    74        bucket: "test"
    75      })
    76      expect(newState.currentBucket).toEqual("test")
    77    })
    78  
    79    it("should handle SET_POLICIES", () => {
    80      const newState = reducer(undefined, {
    81        type: actions.SET_POLICIES,
    82        policies: ["test1", "test2"]
    83      })
    84      expect(newState.policies).toEqual(["test1", "test2"])
    85    })
    86  
    87    it("should handle SHOW_BUCKET_POLICY", () => {
    88      const newState = reducer(undefined, {
    89        type: actions.SHOW_BUCKET_POLICY,
    90        show: true
    91      })
    92      expect(newState.showBucketPolicy).toBeTruthy()
    93    })
    94    
    95    it("should handle SHOW_MAKE_BUCKET_MODAL", () => {
    96      const newState = reducer(undefined, {
    97        type: actions.SHOW_MAKE_BUCKET_MODAL,
    98        show: true
    99      })
   100      expect(newState.showMakeBucketModal).toBeTruthy()
   101    })
   102  })