useVisualizes.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {act, render} from 'sentry-test/reactTestingLibrary';
  2. import {useVisualizes} from 'sentry/views/explore/hooks/useVisualizes';
  3. import {ChartType} from 'sentry/views/insights/common/components/chart';
  4. describe('useVisualizes', function () {
  5. it('allows changing visualizes function', function () {
  6. let visualizes, setVisualizes;
  7. function TestPage() {
  8. [visualizes, setVisualizes] = useVisualizes();
  9. return null;
  10. }
  11. render(<TestPage />, {disableRouterMocks: true});
  12. expect(visualizes).toEqual([
  13. {yAxes: ['count(span.duration)'], chartType: ChartType.LINE},
  14. ]); // default
  15. act(() => setVisualizes([{yAxes: ['p75(span.duration)'], chartType: ChartType.BAR}]));
  16. expect(visualizes).toEqual([
  17. {yAxes: ['p75(span.duration)'], chartType: ChartType.BAR},
  18. ]);
  19. act(() => setVisualizes([]));
  20. expect(visualizes).toEqual([
  21. {yAxes: ['count(span.duration)'], chartType: ChartType.LINE},
  22. ]); // default
  23. act(() => setVisualizes([{yAxes: ['count(span.duration)']}]));
  24. expect(visualizes).toEqual([
  25. {yAxes: ['count(span.duration)'], chartType: ChartType.LINE},
  26. ]); // default
  27. act(() =>
  28. setVisualizes([
  29. {
  30. yAxes: ['count(span.duration)', 'p75(span.duration)'],
  31. chartType: ChartType.LINE,
  32. },
  33. ])
  34. );
  35. expect(visualizes).toEqual([
  36. {yAxes: ['count(span.duration)', 'p75(span.duration)'], chartType: ChartType.LINE},
  37. ]);
  38. act(() =>
  39. setVisualizes([
  40. {yAxes: ['count(span.duration)', 'p75(span.duration)'], chartType: ChartType.BAR},
  41. {yAxes: ['count(span.duration)'], chartType: ChartType.AREA},
  42. ])
  43. );
  44. expect(visualizes).toEqual([
  45. {yAxes: ['count(span.duration)', 'p75(span.duration)'], chartType: ChartType.BAR},
  46. {yAxes: ['count(span.duration)'], chartType: ChartType.AREA},
  47. ]);
  48. });
  49. });