index.spec.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: {
  27. data: [
  28. {
  29. type: 'same_root_cause',
  30. data: [group1, group2],
  31. },
  32. ],
  33. },
  34. });
  35. issuesInfoMock = MockApiClient.addMockResponse({
  36. url: orgIssuesEndpoint,
  37. body: [
  38. {
  39. id: group1,
  40. shortId: `EARTH-${group1}`,
  41. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  42. type: 'error',
  43. metadata: {
  44. type: errorType,
  45. },
  46. issueCategory: 'error',
  47. lastSeen: '2024-03-15T20:15:30Z',
  48. },
  49. {
  50. id: group2,
  51. shortId: `EARTH-${group2}`,
  52. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  53. type: 'error',
  54. metadata: {
  55. type: errorType,
  56. },
  57. issueCategory: 'error',
  58. lastSeen: '2024-03-16T20:15:30Z',
  59. },
  60. ],
  61. });
  62. });
  63. afterEach(() => {
  64. MockApiClient.clearMockResponses();
  65. jest.clearAllMocks();
  66. });
  67. it('renders with mocked data', async function () {
  68. render(
  69. <GroupRelatedIssues
  70. params={params}
  71. location={router.location}
  72. router={router}
  73. routeParams={router.params}
  74. routes={router.routes}
  75. route={{}}
  76. />
  77. );
  78. // Wait for the issues showing up on the table
  79. expect(await screen.findByText(`EARTH-${group1}`)).toBeInTheDocument();
  80. expect(await screen.findByText(`EARTH-${group2}`)).toBeInTheDocument();
  81. expect(relatedIssuesMock).toHaveBeenCalled();
  82. expect(issuesInfoMock).toHaveBeenCalled();
  83. });
  84. });