useVisualizes.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. {
  14. chartType: ChartType.LINE,
  15. label: 'A',
  16. yAxes: ['count(span.duration)'],
  17. },
  18. ]); // default
  19. act(() => setVisualizes([{yAxes: ['p75(span.duration)'], chartType: ChartType.BAR}]));
  20. expect(visualizes).toEqual([
  21. {
  22. chartType: ChartType.BAR,
  23. label: 'A',
  24. yAxes: ['p75(span.duration)'],
  25. },
  26. ]);
  27. act(() => setVisualizes([]));
  28. expect(visualizes).toEqual([
  29. {
  30. chartType: ChartType.LINE,
  31. label: 'A',
  32. yAxes: ['count(span.duration)'],
  33. },
  34. ]); // default
  35. act(() => setVisualizes([{yAxes: ['count(span.duration)']}]));
  36. expect(visualizes).toEqual([
  37. {
  38. chartType: ChartType.LINE,
  39. label: 'A',
  40. yAxes: ['count(span.duration)'],
  41. },
  42. ]); // default
  43. act(() =>
  44. setVisualizes([
  45. {
  46. yAxes: ['count(span.duration)', 'p75(span.duration)'],
  47. chartType: ChartType.LINE,
  48. },
  49. ])
  50. );
  51. expect(visualizes).toEqual([
  52. {
  53. chartType: ChartType.LINE,
  54. label: 'A',
  55. yAxes: ['count(span.duration)', 'p75(span.duration)'],
  56. },
  57. ]);
  58. act(() =>
  59. setVisualizes([
  60. {
  61. chartType: ChartType.BAR,
  62. label: 'A',
  63. yAxes: ['count(span.duration)', 'p75(span.duration)'],
  64. },
  65. {
  66. chartType: ChartType.AREA,
  67. label: 'B',
  68. yAxes: ['count(span.duration)'],
  69. },
  70. ])
  71. );
  72. expect(visualizes).toEqual([
  73. {
  74. chartType: ChartType.BAR,
  75. label: 'A',
  76. yAxes: ['count(span.duration)', 'p75(span.duration)'],
  77. },
  78. {
  79. chartType: ChartType.AREA,
  80. label: 'B',
  81. yAxes: ['count(span.duration)'],
  82. },
  83. ]);
  84. });
  85. });