index.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {RouterFixture} from 'sentry-fixture/routerFixture';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {GroupRelatedIssues} from 'sentry/views/issueDetails/groupRelatedIssues';
  5. describe('Related Issues View', function () {
  6. let relatedIssuesMock: jest.Mock;
  7. let issuesInfoMock: jest.Mock;
  8. const router = RouterFixture();
  9. const organization = OrganizationFixture();
  10. const orgSlug = organization.slug;
  11. const groupId = '12345678';
  12. const group1 = '15';
  13. const group2 = '20';
  14. // query=issue.id:[15,20] -> query=issue.id%3A%5B15%2C20%5D
  15. const orgIssuesEndpoint = `/organizations/${orgSlug}/issues/?query=issue.id%3A%5B${group1}%2C${group2}%5D`;
  16. const params = {groupId: groupId};
  17. const errorType = 'RuntimeError';
  18. beforeEach(function () {
  19. // GroupList calls this but we don't need it for this test
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/${orgSlug}/users/`,
  22. body: {},
  23. });
  24. relatedIssuesMock = MockApiClient.addMockResponse({
  25. url: `/issues/${groupId}/related-issues/`,
  26. body: {same_root_cause: [group1, group2]},
  27. });
  28. issuesInfoMock = MockApiClient.addMockResponse({
  29. url: orgIssuesEndpoint,
  30. body: [
  31. {
  32. id: group1,
  33. shortId: `EARTH-${group1}`,
  34. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  35. type: 'error',
  36. metadata: {
  37. type: errorType,
  38. },
  39. issueCategory: 'error',
  40. lastSeen: '2024-03-15T20:15:30Z',
  41. },
  42. {
  43. id: group2,
  44. shortId: `EARTH-${group2}`,
  45. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  46. type: 'error',
  47. metadata: {
  48. type: errorType,
  49. },
  50. issueCategory: 'error',
  51. lastSeen: '2024-03-16T20:15:30Z',
  52. },
  53. ],
  54. });
  55. });
  56. afterEach(() => {
  57. MockApiClient.clearMockResponses();
  58. jest.clearAllMocks();
  59. });
  60. it('renders with mocked data', async function () {
  61. render(
  62. <GroupRelatedIssues
  63. params={params}
  64. location={router.location}
  65. router={router}
  66. routeParams={router.params}
  67. routes={router.routes}
  68. route={{}}
  69. />
  70. );
  71. // Wait for the issues showing up on the table
  72. expect(await screen.findByText(`EARTH-${group1}`)).toBeInTheDocument();
  73. expect(await screen.findByText(`EARTH-${group2}`)).toBeInTheDocument();
  74. expect(relatedIssuesMock).toHaveBeenCalled();
  75. expect(issuesInfoMock).toHaveBeenCalled();
  76. });
  77. });