jobTickTooltip.spec.tsx 4.7 KB

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