jobTickTooltip.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. timeMarkerInterval: 10,
  24. dateTimeProps: {timeOnly: true},
  25. };
  26. describe('JobTickTooltip', function () {
  27. it('renders tooltip representing single job run', async function () {
  28. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  29. const endTs = startTs;
  30. const envMapping = generateEnvMapping('prod', [0, 0, 1, 0, 0]);
  31. const jobTick = {
  32. startTs,
  33. envMapping,
  34. roundedLeft: false,
  35. roundedRight: false,
  36. endTs,
  37. width: 4,
  38. };
  39. render(
  40. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  41. );
  42. // Skip the header row
  43. const statusRow = (await screen.findAllByRole('row'))[1];
  44. expect(within(statusRow).getByText('Missed')).toBeInTheDocument();
  45. expect(within(statusRow).getByText('prod')).toBeInTheDocument();
  46. expect(within(statusRow).getByText('1')).toBeInTheDocument();
  47. });
  48. it('renders tooltip representing multiple job runs 1 env', async function () {
  49. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  50. const endTs = startTs;
  51. const envMapping = generateEnvMapping('prod', [0, 1, 1, 1, 1]);
  52. const jobTick = {
  53. startTs,
  54. envMapping,
  55. roundedLeft: false,
  56. roundedRight: false,
  57. endTs,
  58. width: 4,
  59. };
  60. render(
  61. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  62. );
  63. const okayRow = (await screen.findAllByRole('row'))[1];
  64. expect(within(okayRow).getByText('Okay')).toBeInTheDocument();
  65. expect(within(okayRow).getByText('prod')).toBeInTheDocument();
  66. expect(within(okayRow).getByText('1')).toBeInTheDocument();
  67. const missedRow = screen.getAllByRole('row')[2];
  68. expect(within(missedRow).getByText('Missed')).toBeInTheDocument();
  69. expect(within(missedRow).getByText('prod')).toBeInTheDocument();
  70. expect(within(missedRow).getByText('1')).toBeInTheDocument();
  71. const timeoutRow = screen.getAllByRole('row')[3];
  72. expect(within(timeoutRow).getByText('Timed Out')).toBeInTheDocument();
  73. expect(within(timeoutRow).getByText('prod')).toBeInTheDocument();
  74. expect(within(timeoutRow).getByText('1')).toBeInTheDocument();
  75. const errorRow = screen.getAllByRole('row')[4];
  76. expect(within(errorRow).getByText('Failed')).toBeInTheDocument();
  77. expect(within(errorRow).getByText('prod')).toBeInTheDocument();
  78. expect(within(errorRow).getByText('1')).toBeInTheDocument();
  79. });
  80. it('renders tooltip representing multiple job runs multiple envs', async function () {
  81. const startTs = new Date('2023-06-15T11:00:00Z').valueOf();
  82. const endTs = startTs;
  83. const prodEnvMapping = generateEnvMapping('prod', [0, 0, 1, 0, 0]);
  84. const devEnvMapping = generateEnvMapping('dev', [0, 1, 2, 1, 0]);
  85. const envMapping = {...prodEnvMapping, ...devEnvMapping};
  86. const jobTick = {
  87. startTs,
  88. envMapping,
  89. roundedLeft: false,
  90. roundedRight: false,
  91. endTs,
  92. width: 4,
  93. };
  94. render(
  95. <JobTickTooltip jobTick={jobTick} timeWindowConfig={tickConfig} forceVisible />
  96. );
  97. const missedProdRow = (await screen.findAllByRole('row'))[1];
  98. expect(within(missedProdRow).getByText('Missed')).toBeInTheDocument();
  99. expect(within(missedProdRow).getByText('prod')).toBeInTheDocument();
  100. expect(within(missedProdRow).getByText('1')).toBeInTheDocument();
  101. const okDevRow = screen.getAllByRole('row')[2];
  102. expect(within(okDevRow).getByText('Okay')).toBeInTheDocument();
  103. expect(within(okDevRow).getByText('dev')).toBeInTheDocument();
  104. expect(within(okDevRow).getByText('1')).toBeInTheDocument();
  105. const missedDevRow = screen.getAllByRole('row')[3];
  106. expect(within(missedDevRow).getByText('Missed')).toBeInTheDocument();
  107. expect(within(missedDevRow).getByText('dev')).toBeInTheDocument();
  108. expect(within(missedDevRow).getByText('2')).toBeInTheDocument();
  109. const timeoutDevRow = screen.getAllByRole('row')[4];
  110. expect(within(timeoutDevRow).getByText('Timed Out')).toBeInTheDocument();
  111. expect(within(timeoutDevRow).getByText('dev')).toBeInTheDocument();
  112. expect(within(timeoutDevRow).getByText('1')).toBeInTheDocument();
  113. });
  114. });