withPageFilters.spec.jsx 2.5 KB

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