pullRequestLink.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import PullRequestLink from 'sentry/components/pullRequestLink';
  3. describe('PullRequestLink', () => {
  4. it('renders no url on missing externalUrl', () => {
  5. const repository = TestStubs.Repository({provider: null});
  6. const pullRequest = TestStubs.PullRequest({
  7. repository,
  8. externalUrl: null,
  9. });
  10. render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
  11. expect(screen.queryByRole('link')).not.toBeInTheDocument();
  12. expect(screen.getByText('example/repo-name #3: Fix first issue')).toBeInTheDocument();
  13. });
  14. it('renders github links for integrations:github repositories', () => {
  15. const repository = TestStubs.Repository({
  16. provider: {
  17. id: 'integrations:github',
  18. },
  19. });
  20. const pullRequest = TestStubs.PullRequest({repository});
  21. render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
  22. expect(screen.getByTestId('pull-request-github')).toBeInTheDocument();
  23. expect(
  24. screen.getByRole('button', {name: 'example/repo-name #3: Fix first issue'})
  25. ).toBeInTheDocument();
  26. });
  27. it('renders github links for github repositories', () => {
  28. const repository = TestStubs.Repository({
  29. provider: {
  30. id: 'github',
  31. },
  32. });
  33. const pullRequest = TestStubs.PullRequest({repository});
  34. render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
  35. expect(screen.getByTestId('pull-request-github')).toBeInTheDocument();
  36. expect(
  37. screen.getByRole('button', {name: 'example/repo-name #3: Fix first issue'})
  38. ).toBeInTheDocument();
  39. });
  40. it('renders gitlab links for integrations:gitlab repositories', () => {
  41. const repository = TestStubs.Repository({
  42. provider: {
  43. id: 'integrations:gitlab',
  44. },
  45. });
  46. const pullRequest = TestStubs.PullRequest({repository});
  47. render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
  48. expect(screen.getByTestId('pull-request-gitlab')).toBeInTheDocument();
  49. expect(
  50. screen.getByRole('button', {name: 'example/repo-name #3: Fix first issue'})
  51. ).toBeInTheDocument();
  52. });
  53. it('renders github links for gitlab repositories', () => {
  54. const repository = TestStubs.Repository({
  55. provider: {
  56. id: 'gitlab',
  57. },
  58. });
  59. const pullRequest = TestStubs.PullRequest({repository});
  60. render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
  61. expect(screen.getByTestId('pull-request-gitlab')).toBeInTheDocument();
  62. expect(
  63. screen.getByRole('button', {name: 'example/repo-name #3: Fix first issue'})
  64. ).toBeInTheDocument();
  65. });
  66. });