withGlobalSelection.spec.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import GlobalSelectionStore from 'app/stores/globalSelectionStore';
  4. import withGlobalSelection from 'app/utils/withGlobalSelection';
  5. describe('withGlobalSelection HoC', function() {
  6. beforeEach(() => {
  7. GlobalSelectionStore.init();
  8. });
  9. it('handles projects', function() {
  10. const MyComponent = () => null;
  11. let Container = withGlobalSelection(MyComponent);
  12. let wrapper = mount(<Container />);
  13. expect(wrapper.find('MyComponent').prop('selection').projects).toEqual([]);
  14. GlobalSelectionStore.updateProjects([1]);
  15. wrapper.update();
  16. expect(wrapper.find('MyComponent').prop('selection').projects).toEqual([1]);
  17. });
  18. it('handles datetime', function() {
  19. const MyComponent = () => null;
  20. let Container = withGlobalSelection(MyComponent);
  21. let wrapper = mount(<Container />);
  22. expect(wrapper.find('MyComponent').prop('selection').datetime.period).toEqual('14d');
  23. GlobalSelectionStore.updateDateTime({
  24. period: '7d',
  25. start: null,
  26. end: null,
  27. });
  28. wrapper.update();
  29. expect(wrapper.find('MyComponent').prop('selection').datetime.period).toEqual('7d');
  30. GlobalSelectionStore.updateDateTime({
  31. period: null,
  32. start: '2018-08-08T00:00:00',
  33. end: '2018-08-08T00:00:00',
  34. });
  35. });
  36. it('handles environments', function() {
  37. const MyComponent = () => null;
  38. let Container = withGlobalSelection(MyComponent);
  39. let wrapper = mount(<Container />);
  40. expect(wrapper.find('MyComponent').prop('selection').environments).toEqual([]);
  41. GlobalSelectionStore.updateEnvironments(['beta', 'alpha']);
  42. wrapper.update();
  43. expect(wrapper.find('MyComponent').prop('selection').environments).toEqual([
  44. 'beta',
  45. 'alpha',
  46. ]);
  47. });
  48. });