jobTickTooltip.spec.tsx 4.8 KB

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