withGlobalSelection.spec.jsx 2.3 KB

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