pullRequestLink.spec.jsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import PullRequestLink from 'sentry/components/pullRequestLink';
  3. describe('PullRequestLink', function () {
  4. it('renders no url on missing externalUrl', function () {
  5. const repository = TestStubs.Repository({provider: null});
  6. const pullRequest = TestStubs.PullRequest({
  7. repository,
  8. externalUrl: null,
  9. });
  10. const wrapper = mountWithTheme(
  11. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  12. );
  13. expect(wrapper.find('a')).toHaveLength(0);
  14. expect(wrapper.find('span').text()).toEqual('example/repo-name #3: Fix first issue');
  15. });
  16. it('renders github links for integrations:github repositories', function () {
  17. const repository = TestStubs.Repository({
  18. provider: {
  19. id: 'integrations:github',
  20. },
  21. });
  22. const pullRequest = TestStubs.PullRequest({repository});
  23. const wrapper = mountWithTheme(
  24. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  25. );
  26. const icon = wrapper.find('IconGithub').hostNodes();
  27. expect(icon).toHaveLength(0);
  28. const link = wrapper.find('a');
  29. expect(link).toHaveLength(1);
  30. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  31. });
  32. it('renders github links for github repositories', function () {
  33. const repository = TestStubs.Repository({
  34. provider: {
  35. id: 'github',
  36. },
  37. });
  38. const pullRequest = TestStubs.PullRequest({repository});
  39. const wrapper = mountWithTheme(
  40. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  41. );
  42. const icon = wrapper.find('IconGithub').hostNodes();
  43. expect(icon).toHaveLength(0);
  44. const link = wrapper.find('a');
  45. expect(link).toHaveLength(1);
  46. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  47. });
  48. it('renders gitlab links for integrations:gitlab repositories', function () {
  49. const repository = TestStubs.Repository({
  50. provider: {
  51. id: 'integrations:gitlab',
  52. },
  53. });
  54. const pullRequest = TestStubs.PullRequest({repository});
  55. const wrapper = mountWithTheme(
  56. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  57. );
  58. const icon = wrapper.find('IconGitlab').hostNodes();
  59. expect(icon).toHaveLength(0);
  60. const link = wrapper.find('a');
  61. expect(link).toHaveLength(1);
  62. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  63. });
  64. it('renders github links for gitlab repositories', function () {
  65. const repository = TestStubs.Repository({
  66. provider: {
  67. id: 'gitlab',
  68. },
  69. });
  70. const pullRequest = TestStubs.PullRequest({repository});
  71. const wrapper = mountWithTheme(
  72. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  73. );
  74. const icon = wrapper.find('IconGitlab').hostNodes();
  75. expect(icon).toHaveLength(0);
  76. const link = wrapper.find('a');
  77. expect(link).toHaveLength(1);
  78. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  79. });
  80. });