jobTickTooltip.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  2. import {JobTickTooltip} from 'sentry/views/monitors/components/overviewTimeline/jobTickTooltip';
  3. type StatusCounts = [ok: number, missed: number, timeout: number, error: number];
  4. export function generateEnvMapping(name: string, counts: StatusCounts) {
  5. const [ok, missed, timeout, error] = counts;
  6. return {
  7. [name]: {ok, missed, timeout, error},
  8. };
  9. }
  10. describe('JobTickTooltip', function () {
  11. it('renders tooltip representing single job run', function () {
  12. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  13. const endTs = startTs;
  14. const envMapping = generateEnvMapping('prod', [0, 1, 0, 0]);
  15. const jobTick = {
  16. startTs,
  17. envMapping,
  18. roundedLeft: false,
  19. roundedRight: false,
  20. endTs,
  21. width: 4,
  22. };
  23. render(<JobTickTooltip jobTick={jobTick} timeWindow="1h" forceVisible />);
  24. // Skip the header row
  25. const statusRow = screen.getAllByRole('row')[1];
  26. expect(within(statusRow).getByText('Missed')).toBeInTheDocument();
  27. expect(within(statusRow).getByText('prod')).toBeInTheDocument();
  28. expect(within(statusRow).getByText('1')).toBeInTheDocument();
  29. });
  30. it('renders tooltip representing multiple job runs 1 env', function () {
  31. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  32. const endTs = startTs;
  33. const envMapping = generateEnvMapping('prod', [1, 1, 1, 1]);
  34. const jobTick = {
  35. startTs,
  36. envMapping,
  37. roundedLeft: false,
  38. roundedRight: false,
  39. endTs,
  40. width: 4,
  41. };
  42. render(<JobTickTooltip jobTick={jobTick} timeWindow="1h" forceVisible />);
  43. const okayRow = screen.getAllByRole('row')[1];
  44. expect(within(okayRow).getByText('Okay')).toBeInTheDocument();
  45. expect(within(okayRow).getByText('prod')).toBeInTheDocument();
  46. expect(within(okayRow).getByText('1')).toBeInTheDocument();
  47. const missedRow = screen.getAllByRole('row')[2];
  48. expect(within(missedRow).getByText('Missed')).toBeInTheDocument();
  49. expect(within(missedRow).getByText('prod')).toBeInTheDocument();
  50. expect(within(missedRow).getByText('1')).toBeInTheDocument();
  51. const timeoutRow = screen.getAllByRole('row')[3];
  52. expect(within(timeoutRow).getByText('Timed Out')).toBeInTheDocument();
  53. expect(within(timeoutRow).getByText('prod')).toBeInTheDocument();
  54. expect(within(timeoutRow).getByText('1')).toBeInTheDocument();
  55. const errorRow = screen.getAllByRole('row')[4];
  56. expect(within(errorRow).getByText('Failed')).toBeInTheDocument();
  57. expect(within(errorRow).getByText('prod')).toBeInTheDocument();
  58. expect(within(errorRow).getByText('1')).toBeInTheDocument();
  59. });
  60. it('renders tooltip representing multiple job runs multiple envs', function () {
  61. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  62. const endTs = startTs;
  63. const prodEnvMapping = generateEnvMapping('prod', [0, 1, 0, 0]);
  64. const devEnvMapping = generateEnvMapping('dev', [1, 2, 1, 0]);
  65. const envMapping = {...prodEnvMapping, ...devEnvMapping};
  66. const jobTick = {
  67. startTs,
  68. envMapping,
  69. roundedLeft: false,
  70. roundedRight: false,
  71. endTs,
  72. width: 4,
  73. };
  74. render(<JobTickTooltip jobTick={jobTick} timeWindow="1h" forceVisible />);
  75. const missedProdRow = screen.getAllByRole('row')[1];
  76. expect(within(missedProdRow).getByText('Missed')).toBeInTheDocument();
  77. expect(within(missedProdRow).getByText('prod')).toBeInTheDocument();
  78. expect(within(missedProdRow).getByText('1')).toBeInTheDocument();
  79. const okDevRow = screen.getAllByRole('row')[2];
  80. expect(within(okDevRow).getByText('Okay')).toBeInTheDocument();
  81. expect(within(okDevRow).getByText('dev')).toBeInTheDocument();
  82. expect(within(okDevRow).getByText('1')).toBeInTheDocument();
  83. const missedDevRow = screen.getAllByRole('row')[3];
  84. expect(within(missedDevRow).getByText('Missed')).toBeInTheDocument();
  85. expect(within(missedDevRow).getByText('dev')).toBeInTheDocument();
  86. expect(within(missedDevRow).getByText('2')).toBeInTheDocument();
  87. const timeoutDevRow = screen.getAllByRole('row')[4];
  88. expect(within(timeoutDevRow).getByText('Timed Out')).toBeInTheDocument();
  89. expect(within(timeoutDevRow).getByText('dev')).toBeInTheDocument();
  90. expect(within(timeoutDevRow).getByText('1')).toBeInTheDocument();
  91. });
  92. });