intervalSelector.spec.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import IntervalSelector from 'sentry/components/charts/intervalSelector';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {DisplayModes} from 'sentry/utils/discover/types';
  5. describe('IntervalSelector', function () {
  6. const project = TestStubs.Project();
  7. const eventView = EventView.fromSavedQuery({
  8. id: '',
  9. name: 'test query',
  10. version: 2,
  11. fields: ['transaction', 'count()'],
  12. projects: [project.id],
  13. });
  14. it('resets small interval', function () {
  15. let interval = '1s';
  16. eventView.interval = interval;
  17. eventView.statsPeriod = '90d';
  18. const intervalSelector = (
  19. <IntervalSelector
  20. eventView={eventView}
  21. displayMode={DisplayModes.DEFAULT}
  22. onIntervalChange={newInterval => (interval = newInterval)}
  23. />
  24. );
  25. render(intervalSelector);
  26. expect(interval).toEqual('4h');
  27. });
  28. it('resets large interval', function () {
  29. eventView.interval = '1h';
  30. eventView.statsPeriod = '1h';
  31. const intervalSelector = (
  32. <IntervalSelector
  33. eventView={eventView}
  34. displayMode={DisplayModes.DEFAULT}
  35. onIntervalChange={newInterval => (eventView.interval = newInterval)}
  36. />
  37. );
  38. render(intervalSelector);
  39. expect(eventView.interval).toEqual('1m');
  40. });
  41. it('leaves default interval alone', function () {
  42. eventView.interval = undefined;
  43. eventView.statsPeriod = '90d';
  44. let interval = 'not called';
  45. const intervalSelector = (
  46. <IntervalSelector
  47. eventView={eventView}
  48. displayMode={DisplayModes.DEFAULT}
  49. onIntervalChange={_newInterval => (interval = 'called')}
  50. />
  51. );
  52. render(intervalSelector);
  53. expect(interval).toEqual('not called');
  54. });
  55. });