123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import type {AutofixRepository} from 'sentry/components/events/autofix/types';
- import {SolutionsHubNotices} from 'sentry/views/issueDetails/streamline/sidebar/solutionsHubNotices';
- describe('SolutionsHubNotices', function () {
- // Helper function to create repository objects
- const createRepository = (
- overrides: Partial<AutofixRepository> = {}
- ): AutofixRepository => ({
- default_branch: 'main',
- external_id: 'repo-123',
- integration_id: '123',
- name: 'org/repo',
- provider: 'github',
- url: 'https://github.com/org/repo',
- is_readable: true,
- ...overrides,
- });
- it('renders nothing when all repositories are readable', function () {
- const repositories = [createRepository(), createRepository({name: 'org/repo2'})];
- const {container} = render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(container).toBeEmptyDOMElement();
- });
- it('renders GitHub integration setup card when hasGithubIntegration is false', function () {
- render(
- <SolutionsHubNotices
- autofixRepositories={[createRepository()]}
- hasGithubIntegration={false}
- />
- );
- expect(screen.getByText('Set Up the GitHub Integration')).toBeInTheDocument();
- // Test for text fragments with formatting
- expect(screen.getByText(/Autofix is/, {exact: false})).toBeInTheDocument();
- expect(screen.getByText('a lot better')).toBeInTheDocument();
- expect(
- screen.getByText(/when it has your codebase as context/, {exact: false})
- ).toBeInTheDocument();
- // Test for text with links
- expect(screen.getByText(/Set up the/, {exact: false})).toBeInTheDocument();
- expect(screen.getByText('GitHub Integration', {selector: 'a'})).toBeInTheDocument();
- expect(
- screen.getByText(/to allow Autofix to go deeper/, {exact: false})
- ).toBeInTheDocument();
- expect(screen.getByText('Set Up Now')).toBeInTheDocument();
- expect(screen.getByRole('img', {name: 'Install'})).toBeInTheDocument();
- });
- it('renders warning for a single unreadable GitHub repository', function () {
- const repositories = [createRepository({is_readable: false})];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(screen.getByText(/Autofix can't access the/)).toBeInTheDocument();
- expect(screen.getByText('org/repo')).toBeInTheDocument();
- expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
- expect(screen.getByText(/code mappings/)).toBeInTheDocument();
- });
- it('renders warning for a single unreadable non-GitHub repository', function () {
- const repositories = [
- createRepository({is_readable: false, provider: 'gitlab', name: 'org/gitlab-repo'}),
- ];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(screen.getByText(/Autofix can't access the/)).toBeInTheDocument();
- expect(screen.getByText('org/gitlab-repo')).toBeInTheDocument();
- expect(
- screen.getByText(/It currently only supports GitHub repositories/)
- ).toBeInTheDocument();
- });
- it('renders warning for multiple unreadable repositories (all GitHub)', function () {
- const repositories = [
- createRepository({is_readable: false, name: 'org/repo1'}),
- createRepository({is_readable: false, name: 'org/repo2'}),
- ];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(
- screen.getByText(/Autofix can't access these repositories:/)
- ).toBeInTheDocument();
- expect(screen.getByText('org/repo1, org/repo2')).toBeInTheDocument();
- expect(screen.getByText(/For best performance, enable the/)).toBeInTheDocument();
- expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
- expect(screen.getByText(/code mappings/)).toBeInTheDocument();
- });
- it('renders warning for multiple unreadable repositories (all non-GitHub)', function () {
- const repositories = [
- createRepository({
- is_readable: false,
- provider: 'gitlab',
- name: 'org/gitlab-repo1',
- }),
- createRepository({
- is_readable: false,
- provider: 'bitbucket',
- name: 'org/bitbucket-repo2',
- }),
- ];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(
- screen.getByText(/Autofix can't access these repositories:/)
- ).toBeInTheDocument();
- expect(screen.getByText('org/gitlab-repo1, org/bitbucket-repo2')).toBeInTheDocument();
- expect(
- screen.getByText(/Autofix currently only supports GitHub repositories/)
- ).toBeInTheDocument();
- });
- it('renders warning for multiple unreadable repositories (mixed GitHub and non-GitHub)', function () {
- const repositories = [
- createRepository({is_readable: false, name: 'org/github-repo'}),
- createRepository({
- is_readable: false,
- provider: 'gitlab',
- name: 'org/gitlab-repo',
- }),
- ];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- expect(
- screen.getByText(/Autofix can't access these repositories:/)
- ).toBeInTheDocument();
- expect(screen.getByText('org/github-repo, org/gitlab-repo')).toBeInTheDocument();
- expect(screen.getByText(/For best performance, enable the/)).toBeInTheDocument();
- expect(screen.getByText(/GitHub integration/)).toBeInTheDocument();
- expect(screen.getByText(/code mappings/)).toBeInTheDocument();
- expect(
- screen.getByText(/Autofix currently only supports GitHub repositories/)
- ).toBeInTheDocument();
- });
- it('renders warning for unreadable repositories along with GitHub setup card when no GitHub integration', function () {
- const repositories = [
- createRepository({is_readable: false, name: 'org/repo1'}),
- createRepository({is_readable: false, name: 'org/repo2'}),
- ];
- render(
- <SolutionsHubNotices
- autofixRepositories={repositories}
- hasGithubIntegration={false}
- />
- );
- // GitHub setup card
- expect(screen.getByText('Set Up the GitHub Integration')).toBeInTheDocument();
- expect(screen.getByText('Set Up Now')).toBeInTheDocument();
- // Unreadable repos warning
- expect(
- screen.getByText(/Autofix can't access these repositories:/)
- ).toBeInTheDocument();
- expect(screen.getByText('org/repo1, org/repo2')).toBeInTheDocument();
- });
- it('renders correct integration links based on integration_id', function () {
- const repositories = [
- createRepository({
- is_readable: false,
- integration_id: '456',
- name: 'org/repo1',
- }),
- ];
- render(
- <SolutionsHubNotices autofixRepositories={repositories} hasGithubIntegration />
- );
- const integrationLink = screen.getByText('GitHub integration');
- expect(integrationLink).toHaveAttribute(
- 'href',
- '/settings/org-slug/integrations/github/456'
- );
- const codeMappingsLink = screen.getByText('code mappings');
- expect(codeMappingsLink).toHaveAttribute(
- 'href',
- '/settings/org-slug/integrations/github/456/?tab=codeMappings'
- );
- });
- it('combines multiple notices when necessary', function () {
- const repositories = [
- createRepository({is_readable: false, name: 'org/repo1'}),
- createRepository({is_readable: false, name: 'org/repo2'}),
- ];
- render(
- <SolutionsHubNotices
- autofixRepositories={repositories}
- hasGithubIntegration={false}
- />
- );
- // Should have both the GitHub setup card and the unreadable repos warning
- const setupCard = screen.getByText('Set Up the GitHub Integration').closest('div');
- const warningAlert = screen
- .getByText(/Autofix can't access these repositories:/)
- .closest('div');
- expect(setupCard).toBeInTheDocument();
- expect(warningAlert).toBeInTheDocument();
- expect(setupCard).not.toBe(warningAlert);
- });
- });
|