alertStore.spec.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import AlertStore from 'app/stores/alertStore';
  2. jest.mock('app/utils/localStorage');
  3. describe('AlertStore', function() {
  4. beforeEach(function() {
  5. AlertStore.alerts = [];
  6. AlertStore.count = 0;
  7. });
  8. describe('onAddAlert()', function() {
  9. it('should add a new alert with incrementing key', function() {
  10. AlertStore.onAddAlert({
  11. message: 'Bzzzzzzp *crash*',
  12. type: 'error',
  13. });
  14. AlertStore.onAddAlert({
  15. message: 'Everything is super',
  16. type: 'info',
  17. });
  18. expect(AlertStore.alerts).toHaveLength(2);
  19. expect(AlertStore.alerts[0].key).toEqual(0);
  20. expect(AlertStore.alerts[1].key).toEqual(1);
  21. });
  22. });
  23. describe('onCloseAlert()', function() {
  24. it('should remove alert', function() {
  25. AlertStore.alerts = [
  26. {key: 1, message: 'foo', type: 'error'},
  27. {key: 2, message: 'bar', type: 'error'},
  28. {key: 3, message: 'baz', type: 'error'},
  29. ];
  30. AlertStore.onCloseAlert(AlertStore.alerts[1]);
  31. expect(AlertStore.alerts).toHaveLength(2);
  32. expect(AlertStore.alerts[0].key).toEqual(1);
  33. expect(AlertStore.alerts[1].key).toEqual(3);
  34. });
  35. it('should persist removal of persistent alerts', function() {
  36. let alert = {key: 1, id: 'test', message: 'foo', type: 'error'};
  37. AlertStore.onCloseAlert(alert);
  38. AlertStore.onAddAlert(alert);
  39. expect(AlertStore.alerts).toHaveLength(0);
  40. });
  41. });
  42. });