modal.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // Description
  70. expect(screen.getByText(/Assign issues based on custom rules/)).toBeInTheDocument();
  71. // Suggestions
  72. expect(
  73. screen.getByText(/Here’s some suggestions based on this issue/)
  74. ).toBeInTheDocument();
  75. expect(
  76. screen.getByText(`path:raven/base.py ${user.email}`, {exact: false})
  77. ).toBeInTheDocument();
  78. expect(
  79. screen.getByText(`url:*/path ${user.email}`, {exact: false})
  80. ).toBeInTheDocument();
  81. });
  82. it('can cancel', async () => {
  83. const onCancel = jest.fn();
  84. render(
  85. <ProjectOwnershipModal
  86. issueId={issueId}
  87. organization={org}
  88. project={project}
  89. eventData={event}
  90. onCancel={onCancel}
  91. />
  92. );
  93. // Cancel
  94. await userEvent.click(screen.getByText('Cancel'));
  95. expect(onCancel).toHaveBeenCalled();
  96. });
  97. });