useChartInterval.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {act, render} from 'sentry-test/reactTestingLibrary';
  2. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  3. import {useChartInterval} from './useChartInterval';
  4. describe('useChartInterval', function () {
  5. beforeEach(() => {
  6. PageFiltersStore.reset();
  7. PageFiltersStore.init();
  8. });
  9. it('allows changing chart interval', async function () {
  10. let chartInterval, setChartInterval, intervalOptions;
  11. function TestPage() {
  12. [chartInterval, setChartInterval, intervalOptions] = useChartInterval();
  13. return null;
  14. }
  15. render(<TestPage />, {disableRouterMocks: true});
  16. expect(intervalOptions).toEqual([
  17. {value: '1h', label: '1 hour'},
  18. {value: '4h', label: '4 hours'},
  19. {value: '1d', label: '1 day'},
  20. {value: '1w', label: '1 week'},
  21. ]);
  22. expect(chartInterval).toEqual('1h'); // default
  23. await act(() => setChartInterval('1d'));
  24. expect(chartInterval).toEqual('1d');
  25. // Update page filters to change interval options
  26. await act(() =>
  27. PageFiltersStore.updateDateTime({
  28. period: '1h',
  29. start: null,
  30. end: null,
  31. utc: true,
  32. })
  33. );
  34. expect(intervalOptions).toEqual([
  35. {value: '1m', label: '1 minute'},
  36. {value: '5m', label: '5 minutes'},
  37. {value: '15m', label: '15 minutes'},
  38. ]);
  39. await act(() => {
  40. setChartInterval('1m');
  41. });
  42. expect(chartInterval).toEqual('1m');
  43. });
  44. });