index.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {openModal} from 'sentry/actionCreators/modal';
  3. import ProjectOwnership from 'sentry/views/settings/project/projectOwnership';
  4. jest.mock('sentry/actionCreators/modal');
  5. describe('Project Ownership', () => {
  6. let org = TestStubs.Organization();
  7. const project = TestStubs.ProjectDetails();
  8. beforeEach(() => {
  9. MockApiClient.addMockResponse({
  10. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  11. method: 'GET',
  12. body: {
  13. fallthrough: false,
  14. autoAssignment: 'Auto Assign to Suspect Commits',
  15. codeownersAutoSync: false,
  16. },
  17. });
  18. MockApiClient.addMockResponse({
  19. url: `/organizations/${org.slug}/code-mappings/`,
  20. query: {project: project.id},
  21. method: 'GET',
  22. body: [],
  23. });
  24. MockApiClient.addMockResponse({
  25. url: `/organizations/${org.slug}/integrations/`,
  26. query: {features: 'codeowners'},
  27. method: 'GET',
  28. body: [TestStubs.GitHubIntegrationConfig()],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: `/projects/${org.slug}/${project.slug}/codeowners/`,
  32. features: {expand: 'codeMapping'},
  33. method: 'GET',
  34. body: [],
  35. });
  36. });
  37. afterEach(() => {
  38. MockApiClient.clearMockResponses();
  39. });
  40. describe('without codeowners', () => {
  41. it('renders', () => {
  42. const wrapper = render(
  43. <ProjectOwnership
  44. params={{orgId: org.slug, projectId: project.slug}}
  45. organization={org}
  46. project={project}
  47. />
  48. );
  49. expect(wrapper.container).toSnapshot();
  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. });
  56. describe('with codeowners', () => {
  57. it('codeowners button opens modal', () => {
  58. org = TestStubs.Organization({
  59. features: ['integrations-codeowners'],
  60. access: ['org:integrations'],
  61. });
  62. render(
  63. <ProjectOwnership
  64. params={{orgId: org.slug, projectId: project.slug}}
  65. organization={org}
  66. project={project}
  67. />,
  68. {context: TestStubs.routerContext([{organization: org}])}
  69. );
  70. // Renders button
  71. expect(screen.getByRole('button', {name: 'Add CODEOWNERS'})).toBeInTheDocument();
  72. // Opens modal
  73. userEvent.click(screen.getByRole('button', {name: 'Add CODEOWNERS'}));
  74. expect(openModal).toHaveBeenCalled();
  75. });
  76. });
  77. describe('issue owners settings', () => {
  78. it('should set autoAssignment with commit-context string', async () => {
  79. const updateOwnership = MockApiClient.addMockResponse({
  80. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  81. method: 'PUT',
  82. body: {
  83. fallthrough: false,
  84. autoAssignment: 'Assign To Issue Owner',
  85. codeownersAutoSync: false,
  86. },
  87. });
  88. render(
  89. <ProjectOwnership
  90. params={{orgId: org.slug, projectId: project.slug}}
  91. organization={org}
  92. project={project}
  93. />
  94. );
  95. // Switch to Assign To Issue Owner
  96. userEvent.click(screen.getByText('Auto-assign to suspect commits'));
  97. userEvent.click(screen.getByText('Auto-assign to issue owner'));
  98. await waitFor(() => {
  99. expect(updateOwnership).toHaveBeenCalledWith(
  100. expect.anything(),
  101. expect.objectContaining({
  102. data: {
  103. autoAssignment: 'Auto Assign to Issue Owner',
  104. },
  105. })
  106. );
  107. });
  108. });
  109. });
  110. });