flash_alerts.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import {Message} from 'semantic-ui-react';
  3. import FlashAlerts, {Alert} from 'packs/frontend/components/misc/flash_alerts';
  4. describe('<Alert />', () => {
  5. describe('constructor()', () => {
  6. it('sets initial state', () => {
  7. const wrapper = shallow(<Alert />);
  8. expect(wrapper.state('visible')).toBeTruthy();
  9. });
  10. });
  11. describe('onDismiss()', () => {
  12. it('alters state', () => {
  13. const wrapper = shallow(<Alert />);
  14. wrapper.instance().onDismiss();
  15. expect(wrapper.state('visible')).toBeFalsy();
  16. });
  17. });
  18. describe('render()', () => {
  19. describe('should be visible', () => {
  20. it('renders the alert', () => {
  21. const wrapper = mount(<Alert className="foo-alert" />);
  22. expect(wrapper).toMatchSnapshot();
  23. expect(wrapper.find(Message).length).toEqual(1);
  24. });
  25. });
  26. describe('should be hidden', () => {
  27. const wrapper = mount(<Alert className="foo-alert" />);
  28. wrapper.setState({visible: false});
  29. expect(wrapper).toMatchSnapshot();
  30. expect(wrapper.find(Message).length).toEqual(0);
  31. });
  32. });
  33. });
  34. describe('<FlashAlerts />', () => {
  35. describe('render()', () => {
  36. it('renders child alerts', () => {
  37. const wrapper = mount(
  38. <FlashAlerts
  39. alerts={[
  40. {className: 'foo-alert-1', message: 'foo message 1'},
  41. {className: 'foo-alert-2', message: 'foo message 2'},
  42. ]}
  43. />,
  44. );
  45. expect(wrapper.find(Alert).length).toEqual(2);
  46. });
  47. });
  48. });