jobTickTooltip.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  2. import {getFormat} from 'sentry/utils/dates';
  3. import {JobTickTooltip} from 'sentry/views/monitors/components/overviewTimeline/jobTickTooltip';
  4. import type {TimeWindowConfig} from 'sentry/views/monitors/components/overviewTimeline/types';
  5. type StatusCounts = [
  6. in_progress: number,
  7. ok: number,
  8. missed: number,
  9. timeout: number,
  10. error: number,
  11. ];
  12. export function generateEnvMapping(name: string, counts: StatusCounts) {
  13. const [in_progress, ok, missed, timeout, error] = counts;
  14. return {
  15. [name]: {in_progress, ok, missed, timeout, error},
  16. };
  17. }
  18. const tickConfig: TimeWindowConfig = {
  19. start: new Date('2023-06-15T11:00:00Z'),
  20. end: new Date('2023-06-15T12:00:00Z'),
  21. dateLabelFormat: getFormat({timeOnly: true, seconds: true}),
  22. elapsedMinutes: 60,
  23. markerInterval: 10,
  24. minimumMarkerInterval: 10,
  25. dateTimeProps: {timeOnly: true},
  26. };
  27. describe('JobTickTooltip', function () {
  28. it('renders tooltip representing single job run', async function () {
  29. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  30. const endTs = startTs;
  31. const envMapping = generateEnvMapping('prod', [0, 0, 1, 0, 0]);
  32. const jobTick = {
  33. startTs,
  34. envMapping,
  35. roundedLeft: false,
  36. roundedRight: false,
  37. endTs,
  38. width: 4,
  39. };
  40. render(
  41. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  42. );
  43. // Skip the header row
  44. const statusRow = (await screen.findAllByRole('row'))[1];
  45. expect(within(statusRow).getByText('Missed')).toBeInTheDocument();
  46. expect(within(statusRow).getByText('prod')).toBeInTheDocument();
  47. expect(within(statusRow).getByText('1')).toBeInTheDocument();
  48. });
  49. it('renders tooltip representing multiple job runs 1 env', async function () {
  50. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  51. const endTs = startTs;
  52. const envMapping = generateEnvMapping('prod', [0, 1, 1, 1, 1]);
  53. const jobTick = {
  54. startTs,
  55. envMapping,
  56. roundedLeft: false,
  57. roundedRight: false,
  58. endTs,
  59. width: 4,
  60. };
  61. render(
  62. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  63. );
  64. const okayRow = (await screen.findAllByRole('row'))[1];
  65. expect(within(okayRow).getByText('Okay')).toBeInTheDocument();
  66. expect(within(okayRow).getByText('prod')).toBeInTheDocument();
  67. expect(within(okayRow).getByText('1')).toBeInTheDocument();
  68. const missedRow = screen.getAllByRole('row')[2];
  69. expect(within(missedRow).getByText('Missed')).toBeInTheDocument();
  70. expect(within(missedRow).getByText('prod')).toBeInTheDocument();
  71. expect(within(missedRow).getByText('1')).toBeInTheDocument();
  72. const timeoutRow = screen.getAllByRole('row')[3];
  73. expect(within(timeoutRow).getByText('Timed Out')).toBeInTheDocument();
  74. expect(within(timeoutRow).getByText('prod')).toBeInTheDocument();
  75. expect(within(timeoutRow).getByText('1')).toBeInTheDocument();
  76. const errorRow = screen.getAllByRole('row')[4];
  77. expect(within(errorRow).getByText('Failed')).toBeInTheDocument();
  78. expect(within(errorRow).getByText('prod')).toBeInTheDocument();
  79. expect(within(errorRow).getByText('1')).toBeInTheDocument();
  80. });
  81. it('renders tooltip representing multiple job runs multiple envs', async function () {
  82. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  83. const endTs = startTs;
  84. const prodEnvMapping = generateEnvMapping('prod', [0, 0, 1, 0, 0]);
  85. const devEnvMapping = generateEnvMapping('dev', [0, 1, 2, 1, 0]);
  86. const envMapping = {...prodEnvMapping, ...devEnvMapping};
  87. const jobTick = {
  88. startTs,
  89. envMapping,
  90. roundedLeft: false,
  91. roundedRight: false,
  92. endTs,
  93. width: 4,
  94. };
  95. render(
  96. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  97. );
  98. const missedProdRow = (await screen.findAllByRole('row'))[1];
  99. expect(within(missedProdRow).getByText('Missed')).toBeInTheDocument();
  100. expect(within(missedProdRow).getByText('prod')).toBeInTheDocument();
  101. expect(within(missedProdRow).getByText('1')).toBeInTheDocument();
  102. const okDevRow = screen.getAllByRole('row')[2];
  103. expect(within(okDevRow).getByText('Okay')).toBeInTheDocument();
  104. expect(within(okDevRow).getByText('dev')).toBeInTheDocument();
  105. expect(within(okDevRow).getByText('1')).toBeInTheDocument();
  106. const missedDevRow = screen.getAllByRole('row')[3];
  107. expect(within(missedDevRow).getByText('Missed')).toBeInTheDocument();
  108. expect(within(missedDevRow).getByText('dev')).toBeInTheDocument();
  109. expect(within(missedDevRow).getByText('2')).toBeInTheDocument();
  110. const timeoutDevRow = screen.getAllByRole('row')[4];
  111. expect(within(timeoutDevRow).getByText('Timed Out')).toBeInTheDocument();
  112. expect(within(timeoutDevRow).getByText('dev')).toBeInTheDocument();
  113. expect(within(timeoutDevRow).getByText('1')).toBeInTheDocument();
  114. });
  115. });