modal.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {EventEntryStacktraceFixture} from 'sentry-fixture/eventEntryStacktrace';
  3. import {MembersFixture} from 'sentry-fixture/members';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {ProjectFixture} from 'sentry-fixture/project';
  6. import {UserFixture} from 'sentry-fixture/user';
  7. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  8. import ConfigStore from 'sentry/stores/configStore';
  9. import ProjectOwnershipModal from './modal';
  10. describe('Project Ownership', () => {
  11. const org = OrganizationFixture();
  12. const project = ProjectFixture();
  13. const issueId = '1234';
  14. const stacktrace = EventEntryStacktraceFixture();
  15. const event = EventFixture({
  16. entries: [stacktrace],
  17. });
  18. const user = UserFixture();
  19. beforeEach(() => {
  20. ConfigStore.set('user', user);
  21. MockApiClient.addMockResponse({
  22. url: `/issues/${issueId}/tags/url/`,
  23. body: {
  24. key: 'url',
  25. name: 'URL',
  26. uniqueValues: 1,
  27. totalValues: 1,
  28. topValues: [
  29. {
  30. key: 'url',
  31. name: 'https://example.com/path',
  32. value: 'https://example.com/path',
  33. count: 1,
  34. lastSeen: '2022-08-27T03:24:53Z',
  35. firstSeen: '2022-08-27T03:24:53Z',
  36. },
  37. ],
  38. },
  39. });
  40. MockApiClient.addMockResponse({
  41. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  42. body: {
  43. fallthrough: false,
  44. autoAssignment: 'Auto Assign to Suspect Commits',
  45. codeownersAutoSync: false,
  46. raw: null,
  47. },
  48. });
  49. // Set one frame to in-app
  50. stacktrace.data.frames![0]!.inApp = true;
  51. MockApiClient.addMockResponse({
  52. url: `/organizations/${org.slug}/members/`,
  53. body: MembersFixture(),
  54. });
  55. });
  56. afterEach(() => {
  57. MockApiClient.clearMockResponses();
  58. });
  59. it('renders stacktrace suggestions', async () => {
  60. render(
  61. <ProjectOwnershipModal
  62. issueId={issueId}
  63. organization={org}
  64. project={project}
  65. eventData={event}
  66. onCancel={() => {}}
  67. />
  68. );
  69. // Description
  70. expect(
  71. await screen.findByText(/Assign issues based on custom rules/)
  72. ).toBeInTheDocument();
  73. // Suggestions
  74. expect(
  75. screen.getByText(/Here’s some suggestions based on this issue/)
  76. ).toBeInTheDocument();
  77. expect(
  78. screen.getByText(`path:raven/base.py ${user.email}`, {exact: false})
  79. ).toBeInTheDocument();
  80. expect(
  81. screen.getByText(`url:*/path ${user.email}`, {exact: false})
  82. ).toBeInTheDocument();
  83. });
  84. it('can cancel', async () => {
  85. const onCancel = jest.fn();
  86. render(
  87. <ProjectOwnershipModal
  88. issueId={issueId}
  89. organization={org}
  90. project={project}
  91. eventData={event}
  92. onCancel={onCancel}
  93. />
  94. );
  95. // Cancel
  96. await userEvent.click(await screen.findByText('Cancel'));
  97. expect(onCancel).toHaveBeenCalled();
  98. });
  99. it('still renders if 404 error occurs', async () => {
  100. MockApiClient.addMockResponse({
  101. url: `/issues/${issueId}/tags/url/`,
  102. statusCode: 404,
  103. });
  104. render(
  105. <ProjectOwnershipModal
  106. issueId={issueId}
  107. organization={org}
  108. project={project}
  109. eventData={event}
  110. onCancel={() => {}}
  111. />
  112. );
  113. expect(
  114. await screen.findByText(/Assign issues based on custom rules/)
  115. ).toBeInTheDocument();
  116. expect(
  117. screen.getByText(/Here’s some suggestions based on this issue/)
  118. ).toBeInTheDocument();
  119. });
  120. it('does not render if any other error status occurs', async () => {
  121. MockApiClient.addMockResponse({
  122. url: `/issues/${issueId}/tags/url/`,
  123. statusCode: 401,
  124. });
  125. render(
  126. <ProjectOwnershipModal
  127. issueId={issueId}
  128. organization={org}
  129. project={project}
  130. eventData={event}
  131. onCancel={() => {}}
  132. />
  133. );
  134. expect(
  135. await screen.findByText('There was an error loading data.')
  136. ).toBeInTheDocument();
  137. });
  138. });