flash_alerts.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import {Message} from 'semantic-ui-react';
  3. import FlashAlerts, {Alert} from 'packs/react-app/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. chaiExpect(wrapper).to.have.state('visible', true);
  10. });
  11. });
  12. describe('onDismiss()', () => {
  13. it('alters state', () => {
  14. const wrapper = shallow(<Alert />);
  15. wrapper.instance().onDismiss();
  16. chaiExpect(wrapper).to.have.state('visible', false);
  17. });
  18. });
  19. describe('render()', () => {
  20. describe('should be visible', () => {
  21. it('renders the alert', () => {
  22. const wrapper = mount(<Alert klass="foo-alert" />);
  23. expect(wrapper).toMatchSnapshot();
  24. expect(wrapper.find(Message).length).toEqual(1);
  25. });
  26. });
  27. describe('should be hidden', () => {
  28. const wrapper = mount(<Alert klass="foo-alert" />);
  29. wrapper.setState({visible: false});
  30. expect(wrapper).toMatchSnapshot();
  31. expect(wrapper.find(Message).length).toEqual(0);
  32. });
  33. });
  34. });
  35. describe('<FlashAlerts />', () => {
  36. describe('render()', () => {
  37. it('renders child alerts', () => {
  38. const wrapper = mount(
  39. <FlashAlerts
  40. alerts={[
  41. {klass: 'foo-alert-1', message: 'foo message 1'},
  42. {klass: 'foo-alert-2', message: 'foo message 2'},
  43. ]}
  44. />,
  45. );
  46. expect(wrapper.find(Alert).length).toEqual(2);
  47. });
  48. });
  49. });