checkInTooltip.spec.tsx 4.9 KB

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