index.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {GitHubIntegrationConfig} from 'sentry-fixture/integrationListDirectory';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import RouterContextFixture from 'sentry-fixture/routerContextFixture';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import {openModal} from 'sentry/actionCreators/modal';
  7. import ProjectOwnership from 'sentry/views/settings/project/projectOwnership';
  8. jest.mock('sentry/actionCreators/modal');
  9. describe('Project Ownership', () => {
  10. const {organization, project, routerProps} = initializeOrg();
  11. beforeEach(() => {
  12. MockApiClient.addMockResponse({
  13. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  14. method: 'GET',
  15. body: {
  16. fallthrough: false,
  17. autoAssignment: 'Auto Assign to Suspect Commits',
  18. codeownersAutoSync: false,
  19. },
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/organizations/${organization.slug}/code-mappings/?project=${project.id}`,
  23. method: 'GET',
  24. body: [],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: `/organizations/${organization.slug}/integrations/?features=codeowners`,
  28. method: 'GET',
  29. body: [GitHubIntegrationConfig()],
  30. });
  31. MockApiClient.addMockResponse({
  32. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  33. method: 'GET',
  34. body: [],
  35. });
  36. });
  37. afterEach(() => {
  38. MockApiClient.clearMockResponses();
  39. });
  40. describe('without codeowners', () => {
  41. it('renders', () => {
  42. render(
  43. <ProjectOwnership
  44. {...routerProps}
  45. params={{projectId: project.slug}}
  46. organization={organization}
  47. project={project}
  48. />
  49. );
  50. // Does not render codeowners for orgs without 'integrations-codeowners' feature
  51. expect(
  52. screen.queryByRole('button', {name: 'Add CODEOWNERS'})
  53. ).not.toBeInTheDocument();
  54. });
  55. it('renders allows users to edit ownership rules', () => {
  56. render(
  57. <ProjectOwnership
  58. {...routerProps}
  59. params={{projectId: project.slug}}
  60. organization={organization}
  61. project={project}
  62. />,
  63. {organization: Organization({access: ['project:read']})}
  64. );
  65. expect(screen.queryByRole('button', {name: 'Edit'})).toBeEnabled();
  66. expect(screen.getByTestId('project-permission-alert')).toBeInTheDocument();
  67. // eslint-disable-next-line jest-dom/prefer-in-document
  68. expect(screen.getAllByTestId('project-permission-alert')).toHaveLength(1);
  69. });
  70. });
  71. describe('with codeowners', () => {
  72. it('codeowners button opens modal', async () => {
  73. const org = Organization({
  74. features: ['integrations-codeowners'],
  75. access: ['org:integrations'],
  76. });
  77. render(
  78. <ProjectOwnership
  79. {...routerProps}
  80. params={{projectId: project.slug}}
  81. organization={org}
  82. project={project}
  83. />,
  84. {context: RouterContextFixture([{organization: org}])}
  85. );
  86. // Renders button
  87. expect(screen.getByRole('button', {name: 'Import CODEOWNERS'})).toBeInTheDocument();
  88. // Opens modal
  89. await userEvent.click(screen.getByRole('button', {name: 'Import CODEOWNERS'}));
  90. expect(openModal).toHaveBeenCalled();
  91. });
  92. });
  93. describe('issue owners settings', () => {
  94. it('should set autoAssignment with commit-context string', async () => {
  95. const updateOwnership = MockApiClient.addMockResponse({
  96. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  97. method: 'PUT',
  98. body: {
  99. fallthrough: false,
  100. autoAssignment: 'Assign To Issue Owner',
  101. codeownersAutoSync: false,
  102. },
  103. });
  104. render(
  105. <ProjectOwnership
  106. {...routerProps}
  107. params={{projectId: project.slug}}
  108. organization={organization}
  109. project={project}
  110. />
  111. );
  112. // Switch to Assign To Issue Owner
  113. await userEvent.click(screen.getByText('Auto-assign to suspect commits'));
  114. await userEvent.click(screen.getByText('Auto-assign to issue owner'));
  115. await waitFor(() => {
  116. expect(updateOwnership).toHaveBeenCalledWith(
  117. expect.anything(),
  118. expect.objectContaining({
  119. data: {
  120. autoAssignment: 'Auto Assign to Issue Owner',
  121. },
  122. })
  123. );
  124. });
  125. });
  126. it('should hide issue owners for issue-alert-fallback-targeting flag', () => {
  127. const org = {
  128. ...organization,
  129. features: ['issue-alert-fallback-targeting'],
  130. };
  131. render(
  132. <ProjectOwnership
  133. {...routerProps}
  134. params={{projectId: project.slug}}
  135. organization={org}
  136. project={project}
  137. />
  138. );
  139. expect(screen.getByText('Prioritize Auto Assignment')).toBeInTheDocument();
  140. expect(
  141. screen.queryByText('Send alert to project members if there’s no assigned owner')
  142. ).not.toBeInTheDocument();
  143. });
  144. });
  145. });