checkInTooltip.spec.tsx 5.0 KB

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