index.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {GitHubIntegrationConfigFixture} from 'sentry-fixture/integrationListDirectory';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {openModal} from 'sentry/actionCreators/modal';
  6. import ProjectOwnership from 'sentry/views/settings/project/projectOwnership';
  7. jest.mock('sentry/actionCreators/modal');
  8. describe('Project Ownership', () => {
  9. const {organization, project, routerProps} = initializeOrg();
  10. beforeEach(() => {
  11. MockApiClient.addMockResponse({
  12. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  13. method: 'GET',
  14. body: {
  15. fallthrough: false,
  16. autoAssignment: 'Auto Assign to Suspect Commits',
  17. codeownersAutoSync: false,
  18. },
  19. });
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/code-mappings/?project=${project.id}`,
  22. method: 'GET',
  23. body: [],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: `/organizations/${organization.slug}/integrations/?features=codeowners`,
  27. method: 'GET',
  28. body: [GitHubIntegrationConfigFixture()],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  32. method: 'GET',
  33. body: [],
  34. });
  35. });
  36. afterEach(() => {
  37. MockApiClient.clearMockResponses();
  38. });
  39. describe('without codeowners', () => {
  40. it('renders', async () => {
  41. render(<ProjectOwnership {...routerProps} project={project} />);
  42. expect(await screen.findByText('No ownership rules found')).toBeInTheDocument();
  43. // Does not render codeowners for orgs without 'integrations-codeowners' feature
  44. expect(
  45. screen.queryByRole('button', {name: 'Add CODEOWNERS'})
  46. ).not.toBeInTheDocument();
  47. });
  48. it('renders allows users to edit ownership rules', async () => {
  49. render(<ProjectOwnership {...routerProps} project={project} />, {
  50. organization: OrganizationFixture({access: ['project:read']}),
  51. });
  52. expect(await screen.findByTestId('project-permission-alert')).toBeInTheDocument();
  53. expect(screen.queryByRole('button', {name: 'Edit Rules'})).toBeEnabled();
  54. // eslint-disable-next-line jest-dom/prefer-in-document
  55. expect(screen.getAllByTestId('project-permission-alert')).toHaveLength(1);
  56. });
  57. });
  58. describe('with codeowners', () => {
  59. it('codeowners button opens modal', async () => {
  60. const org = OrganizationFixture({
  61. features: ['integrations-codeowners'],
  62. access: ['org:integrations'],
  63. });
  64. render(<ProjectOwnership {...routerProps} project={project} />, {
  65. organization: org,
  66. });
  67. // Renders button
  68. expect(
  69. await screen.findByRole('button', {name: 'Import CODEOWNERS'})
  70. ).toBeInTheDocument();
  71. // Opens modal
  72. await userEvent.click(screen.getByRole('button', {name: 'Import CODEOWNERS'}));
  73. expect(openModal).toHaveBeenCalled();
  74. });
  75. });
  76. describe('issue owners settings', () => {
  77. it('should set autoAssignment with commit-context string', async () => {
  78. const updateOwnership = MockApiClient.addMockResponse({
  79. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  80. method: 'PUT',
  81. body: {
  82. fallthrough: false,
  83. autoAssignment: 'Assign To Issue Owner',
  84. codeownersAutoSync: false,
  85. },
  86. });
  87. render(<ProjectOwnership {...routerProps} project={project} />);
  88. // Switch to Assign To Issue Owner
  89. await userEvent.click(await screen.findByText('Auto-assign to suspect commits'));
  90. await userEvent.click(screen.getByText('Auto-assign to issue owner'));
  91. await waitFor(() => {
  92. expect(updateOwnership).toHaveBeenCalledWith(
  93. expect.anything(),
  94. expect.objectContaining({
  95. data: {
  96. autoAssignment: 'Auto Assign to Issue Owner',
  97. },
  98. })
  99. );
  100. });
  101. });
  102. });
  103. });