groupCheckIns.spec.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {CheckInFixture} from 'sentry-fixture/checkIn';
  2. import {EventFixture} from 'sentry-fixture/event';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {ProjectFixture} from 'sentry-fixture/project';
  6. import {RouterFixture} from 'sentry-fixture/routerFixture';
  7. import {render, screen} from 'sentry-test/reactTestingLibrary';
  8. import GroupStore from 'sentry/stores/groupStore';
  9. import {IssueCategory, IssueType} from 'sentry/types/group';
  10. import GroupCheckIns from 'sentry/views/issueDetails/groupCheckIns';
  11. import {statusToText} from 'sentry/views/monitors/utils';
  12. describe('GroupCheckIns', () => {
  13. const monitorId = 'f75a223c-aae1-47e4-8f77-6c72243cb76e';
  14. const event = EventFixture({
  15. tags: [
  16. {
  17. key: 'monitor.id',
  18. value: monitorId,
  19. },
  20. ],
  21. });
  22. const project = ProjectFixture();
  23. const group = GroupFixture({
  24. issueCategory: IssueCategory.CRON,
  25. issueType: IssueType.MONITOR_CHECK_IN_FAILURE,
  26. project,
  27. });
  28. const organization = OrganizationFixture();
  29. const router = RouterFixture({params: {groupId: group.id}});
  30. beforeEach(() => {
  31. GroupStore.init();
  32. GroupStore.add([group]);
  33. MockApiClient.clearMockResponses();
  34. MockApiClient.addMockResponse({
  35. url: `/organizations/${organization.slug}/issues/${group.id}/`,
  36. body: group,
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/organizations/${organization.slug}/issues/${group.id}/events/recommended/`,
  40. body: event,
  41. });
  42. });
  43. it('renders the empty check-in table', async () => {
  44. MockApiClient.addMockResponse({
  45. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitorId}/checkins/`,
  46. body: [],
  47. });
  48. render(<GroupCheckIns />, {organization, router});
  49. expect(await screen.findByText('All Check-Ins')).toBeInTheDocument();
  50. for (const column of [
  51. 'Timestamp',
  52. 'Status',
  53. 'Duration',
  54. 'Environment',
  55. 'Monitor Config',
  56. 'ID',
  57. ]) {
  58. expect(screen.getByText(column)).toBeInTheDocument();
  59. }
  60. expect(screen.getByText('No matching check-ins found')).toBeInTheDocument();
  61. });
  62. it('renders the check-in table with data', async () => {
  63. const check = CheckInFixture();
  64. MockApiClient.addMockResponse({
  65. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitorId}/checkins/`,
  66. body: [check],
  67. });
  68. render(<GroupCheckIns />, {organization, router});
  69. expect(await screen.findByText('All Check-Ins')).toBeInTheDocument();
  70. expect(screen.queryByText('No matching check-ins found')).not.toBeInTheDocument();
  71. expect(screen.getByText('Showing 1-1 matching check-ins')).toBeInTheDocument();
  72. expect(screen.getByRole('button', {name: 'Previous Page'})).toBeInTheDocument();
  73. expect(screen.getByRole('button', {name: 'Next Page'})).toBeInTheDocument();
  74. expect(screen.getByRole('time')).toHaveTextContent(/Jan 1, 2025/);
  75. expect(screen.getByText(statusToText[check.status])).toBeInTheDocument();
  76. expect(screen.getByText(`${check.duration}ms`)).toBeInTheDocument();
  77. expect(screen.getByText(check.environment)).toBeInTheDocument();
  78. expect(screen.getByText(check.id)).toBeInTheDocument();
  79. });
  80. });