withGlobalSelection.spec.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const Container = withGlobalSelection(MyComponent);
  12. const 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. let selection;
  20. const MyComponent = () => null;
  21. const Container = withGlobalSelection(MyComponent);
  22. const wrapper = mount(<Container />);
  23. selection = wrapper.find('MyComponent').prop('selection');
  24. expect(selection.datetime.period).toEqual(null);
  25. expect(selection.datetime.start).toEqual(null);
  26. expect(selection.datetime.end).toEqual(null);
  27. GlobalSelectionStore.updateDateTime({
  28. period: '7d',
  29. start: null,
  30. end: null,
  31. });
  32. wrapper.update();
  33. selection = wrapper.find('MyComponent').prop('selection');
  34. expect(selection.datetime.period).toEqual('7d');
  35. expect(selection.datetime.start).toEqual(null);
  36. expect(selection.datetime.end).toEqual(null);
  37. GlobalSelectionStore.updateDateTime({
  38. period: null,
  39. start: '2018-08-08T00:00:00',
  40. end: '2018-08-08T00:00:00',
  41. });
  42. wrapper.update();
  43. selection = wrapper.find('MyComponent').prop('selection');
  44. expect(selection.datetime.period).toEqual(null);
  45. expect(selection.datetime.start).toEqual('2018-08-08T00:00:00');
  46. expect(selection.datetime.end).toEqual('2018-08-08T00:00:00');
  47. });
  48. it('handles environments', function() {
  49. const MyComponent = () => null;
  50. const Container = withGlobalSelection(MyComponent);
  51. const wrapper = mount(<Container />);
  52. expect(wrapper.find('MyComponent').prop('selection').environments).toEqual([]);
  53. GlobalSelectionStore.updateEnvironments(['beta', 'alpha']);
  54. wrapper.update();
  55. expect(wrapper.find('MyComponent').prop('selection').environments).toEqual([
  56. 'beta',
  57. 'alpha',
  58. ]);
  59. });
  60. });