modal.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {Event as EventFixture} from 'sentry-fixture/event';
  2. import {EventEntryStacktrace} from 'sentry-fixture/eventEntryStacktrace';
  3. import {Members} from 'sentry-fixture/members';
  4. import {Organization} from 'sentry-fixture/organization';
  5. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import ProjectOwnershipModal from './modal';
  8. describe('Project Ownership', () => {
  9. const org = Organization();
  10. const project = TestStubs.Project();
  11. const issueId = '1234';
  12. const stacktrace = EventEntryStacktrace();
  13. const event = EventFixture({
  14. entries: [stacktrace],
  15. });
  16. const user = TestStubs.User();
  17. beforeEach(() => {
  18. ConfigStore.set('user', user);
  19. MockApiClient.addMockResponse({
  20. url: `/issues/${issueId}/tags/url/`,
  21. body: {
  22. key: 'url',
  23. name: 'URL',
  24. uniqueValues: 1,
  25. totalValues: 1,
  26. topValues: [
  27. {
  28. key: 'url',
  29. name: 'https://example.com/path',
  30. value: 'https://example.com/path',
  31. count: 1,
  32. lastSeen: '2022-08-27T03:24:53Z',
  33. firstSeen: '2022-08-27T03:24:53Z',
  34. },
  35. ],
  36. },
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  40. body: {
  41. fallthrough: false,
  42. autoAssignment: 'Auto Assign to Suspect Commits',
  43. codeownersAutoSync: false,
  44. raw: null,
  45. },
  46. });
  47. // Set one frame to in-app
  48. stacktrace.data.frames![0].inApp = true;
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${org.slug}/members/`,
  51. body: Members(),
  52. });
  53. });
  54. afterEach(() => {
  55. MockApiClient.clearMockResponses();
  56. });
  57. it('renders stacktrace suggestions', () => {
  58. render(
  59. <ProjectOwnershipModal
  60. issueId={issueId}
  61. organization={org}
  62. project={project}
  63. eventData={event}
  64. onCancel={() => {}}
  65. />
  66. );
  67. // Rule builder
  68. expect(screen.getByLabelText('Rule pattern')).toBeInTheDocument();
  69. expect(screen.getByText(/Match against Issue Data/)).toBeInTheDocument();
  70. // First in-app (default reverse order) frame is suggested
  71. expect(screen.getByText('raven/base.py')).toBeInTheDocument();
  72. expect(screen.getByText('https://example.com/path')).toBeInTheDocument();
  73. });
  74. it('renders streamline-targeting-context suggestions', () => {
  75. render(
  76. <ProjectOwnershipModal
  77. issueId={issueId}
  78. organization={{...org, features: ['streamline-targeting-context']}}
  79. project={project}
  80. eventData={event}
  81. onCancel={() => {}}
  82. />
  83. );
  84. // Description
  85. expect(screen.getByText(/Assign issues based on custom rules/)).toBeInTheDocument();
  86. // Suggestions
  87. expect(
  88. screen.getByText(/Here’s some suggestions based on this issue/)
  89. ).toBeInTheDocument();
  90. expect(
  91. screen.getByText(`path:raven/base.py ${user.email}`, {exact: false})
  92. ).toBeInTheDocument();
  93. expect(
  94. screen.getByText(`url:*/path ${user.email}`, {exact: false})
  95. ).toBeInTheDocument();
  96. // Rule builder hidden TODO: remove when streamline-targeting-context is GA
  97. expect(screen.queryByLabelText('Rule pattern')).not.toBeInTheDocument();
  98. });
  99. it('can cancel', async () => {
  100. const onCancel = jest.fn();
  101. render(
  102. <ProjectOwnershipModal
  103. issueId={issueId}
  104. organization={org}
  105. project={project}
  106. eventData={event}
  107. onCancel={onCancel}
  108. />
  109. );
  110. // Cancel
  111. await userEvent.click(screen.getByText('Cancel'));
  112. expect(onCancel).toHaveBeenCalled();
  113. });
  114. });