|
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + act, |
| 4 | + reduxRender, |
| 5 | + screen, |
| 6 | + fireEvent, |
| 7 | + waitFor |
| 8 | +} from '../../../test-utils'; |
| 9 | +import { setToastText, showToast } from '../actions/toast'; |
| 10 | +import Toast from './Toast'; |
| 11 | + |
| 12 | +// TODO: update action calls after reducer refactor is merged. |
| 13 | + |
| 14 | +describe(`Toast`, () => { |
| 15 | + it('is hidden by default', () => { |
| 16 | + reduxRender(<Toast />); |
| 17 | + expect(screen.queryByRole('status')).not.toBeInTheDocument(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('opens when an action is dispatched', async () => { |
| 21 | + const { store } = reduxRender(<Toast />); |
| 22 | + act(() => { |
| 23 | + store.dispatch(showToast(1500)); |
| 24 | + store.dispatch(setToastText('Toast.SketchSaved')); |
| 25 | + }); |
| 26 | + |
| 27 | + const toast = screen.queryByRole('status'); |
| 28 | + expect(toast).toBeVisible(); |
| 29 | + expect(toast).toHaveTextContent('Sketch saved.'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('closes automatically after time', async () => { |
| 33 | + const { store } = reduxRender(<Toast />); |
| 34 | + act(() => { |
| 35 | + store.dispatch(showToast(100)); |
| 36 | + store.dispatch(setToastText('Toast.SketchSaved')); |
| 37 | + }); |
| 38 | + |
| 39 | + expect(screen.queryByRole('status')).toBeInTheDocument(); |
| 40 | + |
| 41 | + await waitFor(() => { |
| 42 | + expect(screen.queryByRole('status')).not.toBeInTheDocument(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('closes when "X" button is pressed', () => { |
| 47 | + reduxRender(<Toast />, { |
| 48 | + initialState: { toast: { isVisible: true, text: 'Hello World' } } |
| 49 | + }); |
| 50 | + const button = screen.getByRole('button'); |
| 51 | + fireEvent.click(button); |
| 52 | + expect(screen.queryByRole('status')).not.toBeInTheDocument(); |
| 53 | + }); |
| 54 | +}); |
0 commit comments