modal.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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', () => {
  60. render(
  61. <ProjectOwnershipModal
  62. issueId={issueId}
  63. organization={org}
  64. project={project}
  65. eventData={event}
  66. onCancel={() => {}}
  67. />
  68. );
  69. // Rule builder
  70. expect(screen.getByLabelText('Rule pattern')).toBeInTheDocument();
  71. expect(screen.getByText(/Match against Issue Data/)).toBeInTheDocument();
  72. // First in-app (default reverse order) frame is suggested
  73. expect(screen.getByText('raven/base.py')).toBeInTheDocument();
  74. expect(screen.getByText('https://example.com/path')).toBeInTheDocument();
  75. });
  76. it('renders streamline-targeting-context suggestions', () => {
  77. render(
  78. <ProjectOwnershipModal
  79. issueId={issueId}
  80. organization={{...org, features: ['streamline-targeting-context']}}
  81. project={project}
  82. eventData={event}
  83. onCancel={() => {}}
  84. />
  85. );
  86. // Description
  87. expect(screen.getByText(/Assign issues based on custom rules/)).toBeInTheDocument();
  88. // Suggestions
  89. expect(
  90. screen.getByText(/Here’s some suggestions based on this issue/)
  91. ).toBeInTheDocument();
  92. expect(
  93. screen.getByText(`path:raven/base.py ${user.email}`, {exact: false})
  94. ).toBeInTheDocument();
  95. expect(
  96. screen.getByText(`url:*/path ${user.email}`, {exact: false})
  97. ).toBeInTheDocument();
  98. // Rule builder hidden TODO: remove when streamline-targeting-context is GA
  99. expect(screen.queryByLabelText('Rule pattern')).not.toBeInTheDocument();
  100. });
  101. it('can cancel', async () => {
  102. const onCancel = jest.fn();
  103. render(
  104. <ProjectOwnershipModal
  105. issueId={issueId}
  106. organization={org}
  107. project={project}
  108. eventData={event}
  109. onCancel={onCancel}
  110. />
  111. );
  112. // Cancel
  113. await userEvent.click(screen.getByText('Cancel'));
  114. expect(onCancel).toHaveBeenCalled();
  115. });
  116. });