storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/alert/__tests___/actions.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 configureStore from "redux-mock-store" 18 import thunk from "redux-thunk" 19 import * as actionsAlert from "../actions" 20 21 const middlewares = [thunk] 22 const mockStore = configureStore(middlewares) 23 24 jest.useFakeTimers() 25 26 describe("Alert actions", () => { 27 it("creates alert/SET action", () => { 28 const store = mockStore() 29 const expectedActions = [ 30 { 31 type: "alert/SET", 32 alert: { id: 0, message: "Test alert", type: "danger" } 33 } 34 ] 35 store.dispatch(actionsAlert.set({ message: "Test alert", type: "danger" })) 36 const actions = store.getActions() 37 expect(actions).toEqual(expectedActions) 38 }) 39 40 it("creates alert/CLEAR action for non danger alerts", () => { 41 const store = mockStore() 42 const expectedActions = [ 43 { 44 type: "alert/SET", 45 alert: { id: 1, message: "Test alert" } 46 }, 47 { 48 type: "alert/CLEAR", 49 alert: { id: 1 } 50 } 51 ] 52 store.dispatch(actionsAlert.set({ message: "Test alert" })) 53 jest.runAllTimers() 54 const actions = store.getActions() 55 expect(actions).toEqual(expectedActions) 56 }) 57 58 it("creates alert/CLEAR action directly", () => { 59 const store = mockStore() 60 const expectedActions = [ 61 { 62 type: "alert/CLEAR" 63 } 64 ] 65 store.dispatch(actionsAlert.clear()) 66 const actions = store.getActions() 67 expect(actions).toEqual(expectedActions) 68 }) 69 })