groupUptimeChecks.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {RouterFixture} from 'sentry-fixture/routerFixture';
  6. import {UptimeCheckFixture} from 'sentry-fixture/uptimeCheck';
  7. import {render, screen} from 'sentry-test/reactTestingLibrary';
  8. import GroupStore from 'sentry/stores/groupStore';
  9. import ProjectsStore from 'sentry/stores/projectsStore';
  10. import {IssueCategory, IssueType} from 'sentry/types/group';
  11. import {getShortEventId} from 'sentry/utils/events';
  12. import {statusToText} from 'sentry/views/insights/uptime/timelineConfig';
  13. import GroupUptimeChecks from 'sentry/views/issueDetails/groupUptimeChecks';
  14. describe('GroupUptimeChecks', () => {
  15. const uptimeRuleId = '123';
  16. const event = EventFixture({
  17. tags: [
  18. {
  19. key: 'uptime_rule',
  20. value: uptimeRuleId,
  21. },
  22. ],
  23. });
  24. const group = GroupFixture({
  25. issueCategory: IssueCategory.UPTIME,
  26. issueType: IssueType.UPTIME_DOMAIN_FAILURE,
  27. });
  28. const organization = OrganizationFixture();
  29. const project = ProjectFixture();
  30. const router = RouterFixture({
  31. params: {groupId: group.id},
  32. });
  33. beforeEach(() => {
  34. GroupStore.init();
  35. GroupStore.add([group]);
  36. ProjectsStore.init();
  37. ProjectsStore.loadInitialData([project]);
  38. MockApiClient.clearMockResponses();
  39. MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/issues/${group.id}/`,
  41. body: group,
  42. });
  43. MockApiClient.addMockResponse({
  44. url: `/organizations/${organization.slug}/issues/${group.id}/events/recommended/`,
  45. body: event,
  46. });
  47. });
  48. it('renders the empty uptime check table', async () => {
  49. MockApiClient.addMockResponse({
  50. url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRuleId}/checks/`,
  51. body: [],
  52. });
  53. render(<GroupUptimeChecks />, {organization, router});
  54. expect(await screen.findByText('All Uptime Checks')).toBeInTheDocument();
  55. for (const column of ['Timestamp', 'Status', 'Duration', 'Trace', 'Region', 'ID']) {
  56. expect(screen.getByText(column)).toBeInTheDocument();
  57. }
  58. expect(screen.getByText('No matching uptime checks found')).toBeInTheDocument();
  59. });
  60. it('renders the uptime check table with data', async () => {
  61. const uptimeCheck = UptimeCheckFixture();
  62. MockApiClient.addMockResponse({
  63. url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRuleId}/checks/`,
  64. body: [uptimeCheck],
  65. });
  66. render(<GroupUptimeChecks />, {organization, router});
  67. expect(await screen.findByText('All Uptime Checks')).toBeInTheDocument();
  68. expect(screen.queryByText('No matching uptime checks found')).not.toBeInTheDocument();
  69. expect(screen.getByText('Showing 1-1 matching uptime checks')).toBeInTheDocument();
  70. expect(screen.getByRole('button', {name: 'Previous Page'})).toBeInTheDocument();
  71. expect(screen.getByRole('button', {name: 'Next Page'})).toBeInTheDocument();
  72. expect(screen.getByRole('time')).toHaveTextContent(/Jan 1, 2025/);
  73. expect(screen.getByText(statusToText[uptimeCheck.checkStatus])).toBeInTheDocument();
  74. expect(screen.getByText(`${uptimeCheck.durationMs}ms`)).toBeInTheDocument();
  75. expect(
  76. screen.getByRole('link', {name: getShortEventId(uptimeCheck.traceId)})
  77. ).toHaveAttribute('href', `/performance/trace/${uptimeCheck.traceId}/`);
  78. expect(screen.getByText(uptimeCheck.region)).toBeInTheDocument();
  79. expect(screen.getByText(uptimeCheck.uptimeCheckId)).toBeInTheDocument();
  80. });
  81. });