index.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {GroupRelatedIssues} from 'sentry/views/issueDetails/groupRelatedIssues';
  4. describe('Related Issues View', function () {
  5. let sameRootIssuesMock: jest.Mock;
  6. let traceIssuesMock: jest.Mock;
  7. let issuesMock: jest.Mock;
  8. const organization = OrganizationFixture();
  9. const orgSlug = organization.slug;
  10. const groupId = '12345678';
  11. const group1 = '15';
  12. const group2 = '20';
  13. // query=issue.id:[15,20] -> query=issue.id%3A%5B15%2C20%5D
  14. const orgIssuesEndpoint = `/organizations/${orgSlug}/issues/?query=issue.id%3A%5B${group1}%2C${group2}%5D`;
  15. const params = {groupId: groupId};
  16. const errorType = 'RuntimeError';
  17. const onlySameRootData = {
  18. type: 'same_root_cause',
  19. data: [group1, group2],
  20. };
  21. const onlyTraceConnectedData = {
  22. type: 'trace_connected',
  23. data: [group1, group2],
  24. meta: {
  25. event_id: 'abcd',
  26. trace_id: '1234',
  27. },
  28. };
  29. const issuesData = [
  30. {
  31. id: group1,
  32. shortId: `EARTH-${group1}`,
  33. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  34. type: 'error',
  35. metadata: {
  36. type: errorType,
  37. },
  38. issueCategory: 'error',
  39. lastSeen: '2024-03-15T20:15:30Z',
  40. },
  41. {
  42. id: group2,
  43. shortId: `EARTH-${group2}`,
  44. project: {id: '3', name: 'Earth', slug: 'earth', platform: null},
  45. type: 'error',
  46. metadata: {
  47. type: errorType,
  48. },
  49. issueCategory: 'error',
  50. lastSeen: '2024-03-16T20:15:30Z',
  51. },
  52. ];
  53. beforeEach(function () {
  54. // GroupList calls this but we don't need it for this test
  55. MockApiClient.addMockResponse({
  56. url: `/organizations/${orgSlug}/users/`,
  57. body: {},
  58. });
  59. });
  60. afterEach(() => {
  61. MockApiClient.clearMockResponses();
  62. jest.clearAllMocks();
  63. });
  64. it('renders with same root issues', async function () {
  65. sameRootIssuesMock = MockApiClient.addMockResponse({
  66. url: `/issues/${groupId}/related-issues/?type=same_root_cause`,
  67. body: onlySameRootData,
  68. });
  69. MockApiClient.addMockResponse({
  70. url: `/issues/${groupId}/related-issues/?type=trace_connected`,
  71. body: [],
  72. });
  73. issuesMock = MockApiClient.addMockResponse({
  74. url: orgIssuesEndpoint,
  75. body: issuesData,
  76. });
  77. render(<GroupRelatedIssues params={params} />);
  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(sameRootIssuesMock).toHaveBeenCalled();
  82. expect(issuesMock).toHaveBeenCalled();
  83. const linkButton = screen.getByRole('button', {name: /open in issues/i});
  84. expect(linkButton).toHaveAttribute(
  85. 'href',
  86. // Opening in Issues needs to include the group we are currently viewing
  87. `/organizations/org-slug/issues/?project=-1&query=issue.id:[${groupId},${group1},${group2}]`
  88. );
  89. });
  90. it('renders with trace connected issues', async function () {
  91. MockApiClient.addMockResponse({
  92. url: `/issues/${groupId}/related-issues/?type=same_root_cause`,
  93. body: [],
  94. });
  95. traceIssuesMock = MockApiClient.addMockResponse({
  96. url: `/issues/${groupId}/related-issues/?type=trace_connected`,
  97. body: onlyTraceConnectedData,
  98. });
  99. issuesMock = MockApiClient.addMockResponse({
  100. url: orgIssuesEndpoint,
  101. body: issuesData,
  102. });
  103. render(<GroupRelatedIssues params={params} />);
  104. // Wait for the issues showing up on the table
  105. expect(await screen.findByText(`EARTH-${group1}`)).toBeInTheDocument();
  106. expect(await screen.findByText(`EARTH-${group2}`)).toBeInTheDocument();
  107. expect(traceIssuesMock).toHaveBeenCalled();
  108. expect(issuesMock).toHaveBeenCalled();
  109. const linkElement = screen.getByRole('link', {name: /this trace/i});
  110. expect(linkElement).toHaveAttribute(
  111. 'href',
  112. '/organizations/org-slug/performance/trace/1234/?node=error-abcd'
  113. );
  114. const linkButton = screen.getByRole('button', {name: /open in issues/i});
  115. // The Issue search supports using `trace` as a parameter
  116. expect(linkButton).toHaveAttribute(
  117. 'href',
  118. `/organizations/org-slug/issues/?project=-1&query=trace:1234`
  119. );
  120. });
  121. });