storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/alert/__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 actionsAlert from "../actions"
    19  
    20  describe("alert reducer", () => {
    21    it("should return the initial state", () => {
    22      expect(reducer(undefined, {})).toEqual({
    23        show: false,
    24        type: "danger"
    25      })
    26    })
    27  
    28    it("should handle SET_ALERT", () => {
    29      expect(
    30        reducer(undefined, {
    31          type: actionsAlert.SET,
    32          alert: { id: 1, type: "danger", message: "Test message" }
    33        })
    34      ).toEqual({
    35        show: true,
    36        id: 1,
    37        type: "danger",
    38        message: "Test message"
    39      })
    40    })
    41  
    42    it("should clear alert if id not passed", () => {
    43      expect(
    44        reducer(
    45          { show: true, type: "danger", message: "Test message" },
    46          {
    47            type: actionsAlert.CLEAR
    48          }
    49        )
    50      ).toEqual({
    51        show: false,
    52        type: "danger"
    53      })
    54    })
    55  
    56    it("should clear alert if id is matching", () => {
    57      expect(
    58        reducer(
    59          { show: true, id: 1, type: "danger", message: "Test message" },
    60          {
    61            type: actionsAlert.CLEAR,
    62            alert: { id: 1 }
    63          }
    64        )
    65      ).toEqual({
    66        show: false,
    67        type: "danger"
    68      })
    69    })
    70  
    71    it("should not clear alert if id is not matching", () => {
    72      expect(
    73        reducer(
    74          { show: true, id: 1, type: "danger", message: "Test message" },
    75          {
    76            type: actionsAlert.CLEAR,
    77            alert: { id: 2 }
    78          }
    79        )
    80      ).toEqual({
    81        show: true,
    82        id: 1,
    83        type: "danger",
    84        message: "Test message"
    85      })
    86    })
    87  })