projectOwnership.spec.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {openModal} from 'sentry/actionCreators/modal';
  3. import {Client} from 'sentry/api';
  4. import ProjectOwnership from 'sentry/views/settings/project/projectOwnership';
  5. jest.mock('sentry/actionCreators/modal');
  6. describe('Project Ownership', function () {
  7. let org = TestStubs.Organization();
  8. const project = TestStubs.ProjectDetails();
  9. beforeEach(function () {
  10. Client.clearMockResponses();
  11. Client.addMockResponse({
  12. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  13. method: 'GET',
  14. body: {
  15. fallthrough: false,
  16. autoAssignment: false,
  17. },
  18. });
  19. Client.addMockResponse({
  20. url: `/organizations/${org.slug}/code-mappings/`,
  21. query: {project: project.id},
  22. method: 'GET',
  23. body: [],
  24. });
  25. Client.addMockResponse({
  26. url: `/organizations/${org.slug}/integrations/`,
  27. query: {features: 'codeowners'},
  28. method: 'GET',
  29. body: [TestStubs.GithubIntegrationConfig()],
  30. });
  31. Client.addMockResponse({
  32. url: `/projects/${org.slug}/${project.slug}/codeowners/`,
  33. features: {expand: 'codeMapping'},
  34. method: 'GET',
  35. body: [],
  36. });
  37. });
  38. describe('without codeowners', function () {
  39. it('renders', function () {
  40. const wrapper = mountWithTheme(
  41. <ProjectOwnership
  42. params={{orgId: org.slug, projectId: project.slug}}
  43. organization={org}
  44. project={project}
  45. />
  46. );
  47. expect(wrapper).toSnapshot();
  48. // only rendered when `integrations-codeowners` feature flag enabled
  49. expect(wrapper.find('CodeOwnerButton').exists()).toBe(false);
  50. });
  51. });
  52. describe('codeowner action button', function () {
  53. it('renders button', function () {
  54. org = TestStubs.Organization({
  55. features: ['integrations-codeowners'],
  56. access: ['org:integrations'],
  57. });
  58. const wrapper = mountWithTheme(
  59. <ProjectOwnership
  60. params={{orgId: org.slug, projectId: project.slug}}
  61. organization={org}
  62. project={project}
  63. />,
  64. TestStubs.routerContext([{organization: org}])
  65. );
  66. expect(wrapper.find('CodeOwnerButton').exists()).toBe(true);
  67. });
  68. it('clicking button opens modal', function () {
  69. org = TestStubs.Organization({
  70. features: ['integrations-codeowners'],
  71. access: ['org:integrations'],
  72. });
  73. const wrapper = mountWithTheme(
  74. <ProjectOwnership
  75. params={{orgId: org.slug, projectId: project.slug}}
  76. organization={org}
  77. project={project}
  78. />,
  79. TestStubs.routerContext([{organization: org}])
  80. );
  81. wrapper.find('[data-test-id="add-codeowner-button"] button').simulate('click');
  82. expect(openModal).toHaveBeenCalled();
  83. });
  84. it('render request to add if no permissions', function () {
  85. org = TestStubs.Organization({features: ['integrations-codeowners'], access: []});
  86. const wrapper = mountWithTheme(
  87. <ProjectOwnership
  88. params={{orgId: org.slug, projectId: project.slug}}
  89. organization={org}
  90. project={project}
  91. />,
  92. TestStubs.routerContext([{organization: org}])
  93. );
  94. expect(
  95. wrapper.find('[data-test-id="add-codeowner-request-button"] button').exists()
  96. ).toBe(true);
  97. });
  98. });
  99. });