projectOwnership.spec.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: {projectId: 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. TestStubs.routerContext()
  47. );
  48. expect(wrapper).toSnapshot();
  49. // only rendered when `integrations-codeowners` feature flag enabled
  50. expect(wrapper.find('CodeOwnerButton').exists()).toBe(false);
  51. });
  52. });
  53. describe('codeowner action button', function () {
  54. it('renders button', function () {
  55. org = TestStubs.Organization({
  56. features: ['integrations-codeowners'],
  57. access: ['org:integrations'],
  58. });
  59. const wrapper = mountWithTheme(
  60. <ProjectOwnership
  61. params={{orgId: org.slug, projectId: project.slug}}
  62. organization={org}
  63. project={project}
  64. />,
  65. TestStubs.routerContext([{organization: org}])
  66. );
  67. expect(wrapper.find('CodeOwnerButton').exists()).toBe(true);
  68. });
  69. it('clicking button opens modal', async function () {
  70. org = TestStubs.Organization({
  71. features: ['integrations-codeowners'],
  72. access: ['org:integrations'],
  73. });
  74. const wrapper = mountWithTheme(
  75. <ProjectOwnership
  76. params={{orgId: org.slug, projectId: project.slug}}
  77. organization={org}
  78. project={project}
  79. />,
  80. TestStubs.routerContext([{organization: org}])
  81. );
  82. wrapper.find('[data-test-id="add-codeowner-button"] button').simulate('click');
  83. expect(openModal).toHaveBeenCalled();
  84. });
  85. it('render request to add if no permissions', function () {
  86. org = TestStubs.Organization({features: ['integrations-codeowners'], access: []});
  87. const wrapper = mountWithTheme(
  88. <ProjectOwnership
  89. params={{orgId: org.slug, projectId: project.slug}}
  90. organization={org}
  91. project={project}
  92. />,
  93. TestStubs.routerContext([{organization: org}])
  94. );
  95. expect(
  96. wrapper.find('[data-test-id="add-codeowner-request-button"] button').exists()
  97. ).toBe(true);
  98. });
  99. });
  100. });