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. expect(screen.getAllByTestId('project-permission-alert')).toHaveLength(1);
  55. });
  56. });
  57. describe('with codeowners', () => {
  58. it('codeowners button opens modal', async () => {
  59. const org = OrganizationFixture({
  60. features: ['integrations-codeowners'],
  61. access: ['org:integrations'],
  62. });
  63. render(<ProjectOwnership {...routerProps} project={project} />, {
  64. organization: org,
  65. });
  66. // Renders button
  67. expect(
  68. await screen.findByRole('button', {name: 'Import CODEOWNERS'})
  69. ).toBeInTheDocument();
  70. // Opens modal
  71. await userEvent.click(screen.getByRole('button', {name: 'Import CODEOWNERS'}));
  72. expect(openModal).toHaveBeenCalled();
  73. });
  74. });
  75. describe('issue owners settings', () => {
  76. it('should set autoAssignment with commit-context string', async () => {
  77. const updateOwnership = MockApiClient.addMockResponse({
  78. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  79. method: 'PUT',
  80. body: {
  81. fallthrough: false,
  82. autoAssignment: 'Assign To Issue Owner',
  83. codeownersAutoSync: false,
  84. },
  85. });
  86. render(<ProjectOwnership {...routerProps} project={project} />);
  87. // Switch to Assign To Issue Owner
  88. await userEvent.click(await screen.findByText('Auto-assign to suspect commits'));
  89. await userEvent.click(screen.getByText('Auto-assign to issue owner'));
  90. await waitFor(() => {
  91. expect(updateOwnership).toHaveBeenCalledWith(
  92. expect.anything(),
  93. expect.objectContaining({
  94. data: {
  95. autoAssignment: 'Auto Assign to Issue Owner',
  96. },
  97. })
  98. );
  99. });
  100. });
  101. });
  102. });