solutionsHubNotices.spec.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import type {AutofixRepository} from 'sentry/components/events/autofix/types';
  3. import {SolutionsHubNotices} from 'sentry/views/issueDetails/streamline/sidebar/solutionsHubNotices';
  4. describe('SolutionsHubNotices', function () {
  5. // Helper function to create repository objects
  6. const createRepository = (
  7. overrides: Partial<AutofixRepository> = {}
  8. ): AutofixRepository => ({
  9. default_branch: 'main',
  10. external_id: 'repo-123',
  11. integration_id: '123',
  12. name: 'org/repo',
  13. provider: 'github',
  14. url: 'https://github.com/org/repo',
  15. is_readable: true,
  16. ...overrides,
  17. });
  18. it('renders nothing when all repositories are readable', function () {
  19. const repositories = [createRepository(), createRepository({name: 'org/repo2'})];
  20. const {container} = render(
  21. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  22. );
  23. expect(container).toBeEmptyDOMElement();
  24. });
  25. it('renders GitHub integration setup card when hasGithubIntegration is false', function () {
  26. render(
  27. <SolutionsHubNotices
  28. autofixRepositories={[createRepository()]}
  29. hasGithubIntegration={false}
  30. />
  31. );
  32. expect(screen.getByText('Set Up the GitHub Integration')).toBeInTheDocument();
  33. // Test for text fragments with formatting
  34. expect(screen.getByText(/Autofix is/, {exact: false})).toBeInTheDocument();
  35. expect(screen.getByText('a lot better')).toBeInTheDocument();
  36. expect(
  37. screen.getByText(/when it has your codebase as context/, {exact: false})
  38. ).toBeInTheDocument();
  39. // Test for text with links
  40. expect(screen.getByText(/Set up the/, {exact: false})).toBeInTheDocument();
  41. expect(screen.getByText('GitHub Integration', {selector: 'a'})).toBeInTheDocument();
  42. expect(
  43. screen.getByText(/to allow Autofix to go deeper/, {exact: false})
  44. ).toBeInTheDocument();
  45. expect(screen.getByText('Set Up Now')).toBeInTheDocument();
  46. expect(screen.getByRole('img', {name: 'Install'})).toBeInTheDocument();
  47. });
  48. it('renders warning for a single unreadable GitHub repository', function () {
  49. const repositories = [createRepository({is_readable: false})];
  50. render(
  51. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  52. );
  53. expect(screen.getByText(/Autofix can't access the/)).toBeInTheDocument();
  54. expect(screen.getByText('org/repo')).toBeInTheDocument();
  55. expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
  56. expect(screen.getByText(/code mappings/)).toBeInTheDocument();
  57. });
  58. it('renders warning for a single unreadable non-GitHub repository', function () {
  59. const repositories = [
  60. createRepository({is_readable: false, provider: 'gitlab', name: 'org/gitlab-repo'}),
  61. ];
  62. render(
  63. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  64. );
  65. expect(screen.getByText(/Autofix can't access the/)).toBeInTheDocument();
  66. expect(screen.getByText('org/gitlab-repo')).toBeInTheDocument();
  67. expect(
  68. screen.getByText(/It currently only supports GitHub repositories/)
  69. ).toBeInTheDocument();
  70. });
  71. it('renders warning for multiple unreadable repositories (all GitHub)', function () {
  72. const repositories = [
  73. createRepository({is_readable: false, name: 'org/repo1'}),
  74. createRepository({is_readable: false, name: 'org/repo2'}),
  75. ];
  76. render(
  77. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  78. );
  79. expect(
  80. screen.getByText(/Autofix can't access these repositories:/)
  81. ).toBeInTheDocument();
  82. expect(screen.getByText('org/repo1, org/repo2')).toBeInTheDocument();
  83. expect(screen.getByText(/For best performance, enable the/)).toBeInTheDocument();
  84. expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
  85. expect(screen.getByText(/code mappings/)).toBeInTheDocument();
  86. });
  87. it('renders warning for multiple unreadable repositories (all non-GitHub)', function () {
  88. const repositories = [
  89. createRepository({
  90. is_readable: false,
  91. provider: 'gitlab',
  92. name: 'org/gitlab-repo1',
  93. }),
  94. createRepository({
  95. is_readable: false,
  96. provider: 'bitbucket',
  97. name: 'org/bitbucket-repo2',
  98. }),
  99. ];
  100. render(
  101. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  102. );
  103. expect(
  104. screen.getByText(/Autofix can't access these repositories:/)
  105. ).toBeInTheDocument();
  106. expect(screen.getByText('org/gitlab-repo1, org/bitbucket-repo2')).toBeInTheDocument();
  107. expect(
  108. screen.getByText(/Autofix currently only supports GitHub repositories/)
  109. ).toBeInTheDocument();
  110. });
  111. it('renders warning for multiple unreadable repositories (mixed GitHub and non-GitHub)', function () {
  112. const repositories = [
  113. createRepository({is_readable: false, name: 'org/github-repo'}),
  114. createRepository({
  115. is_readable: false,
  116. provider: 'gitlab',
  117. name: 'org/gitlab-repo',
  118. }),
  119. ];
  120. render(
  121. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  122. );
  123. expect(
  124. screen.getByText(/Autofix can't access these repositories:/)
  125. ).toBeInTheDocument();
  126. expect(screen.getByText('org/github-repo, org/gitlab-repo')).toBeInTheDocument();
  127. expect(screen.getByText(/For best performance, enable the/)).toBeInTheDocument();
  128. expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
  129. expect(screen.getByText(/code mappings/)).toBeInTheDocument();
  130. expect(
  131. screen.getByText(/Autofix currently only supports GitHub repositories/)
  132. ).toBeInTheDocument();
  133. });
  134. it('renders warning for unreadable repositories along with GitHub setup card when no GitHub integration', function () {
  135. const repositories = [
  136. createRepository({is_readable: false, name: 'org/repo1'}),
  137. createRepository({is_readable: false, name: 'org/repo2'}),
  138. ];
  139. render(
  140. <SolutionsHubNotices
  141. autofixRepositories={repositories}
  142. hasGithubIntegration={false}
  143. />
  144. );
  145. // GitHub setup card
  146. expect(screen.getByText('Set Up the GitHub Integration')).toBeInTheDocument();
  147. expect(screen.getByText('Set Up Now')).toBeInTheDocument();
  148. // Unreadable repos warning
  149. expect(
  150. screen.getByText(/Autofix can't access these repositories:/)
  151. ).toBeInTheDocument();
  152. expect(screen.getByText('org/repo1, org/repo2')).toBeInTheDocument();
  153. });
  154. it('renders correct integration links based on integration_id', function () {
  155. const repositories = [
  156. createRepository({
  157. is_readable: false,
  158. integration_id: '456',
  159. name: 'org/repo1',
  160. }),
  161. ];
  162. render(
  163. <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
  164. );
  165. const integrationLink = screen.getByText('GitHub integration');
  166. expect(integrationLink).toHaveAttribute(
  167. 'href',
  168. '/settings/org-slug/integrations/github/456'
  169. );
  170. const codeMappingsLink = screen.getByText('code mappings');
  171. expect(codeMappingsLink).toHaveAttribute(
  172. 'href',
  173. '/settings/org-slug/integrations/github/456/?tab=codeMappings'
  174. );
  175. });
  176. it('combines multiple notices when necessary', function () {
  177. const repositories = [
  178. createRepository({is_readable: false, name: 'org/repo1'}),
  179. createRepository({is_readable: false, name: 'org/repo2'}),
  180. ];
  181. render(
  182. <SolutionsHubNotices
  183. autofixRepositories={repositories}
  184. hasGithubIntegration={false}
  185. />
  186. );
  187. // Should have both the GitHub setup card and the unreadable repos warning
  188. const setupCard = screen.getByText('Set Up the GitHub Integration').closest('div');
  189. const warningAlert = screen
  190. .getByText(/Autofix can't access these repositories:/)
  191. .closest('div');
  192. expect(setupCard).toBeInTheDocument();
  193. expect(warningAlert).toBeInTheDocument();
  194. expect(setupCard).not.toBe(warningAlert);
  195. });
  196. });