pullRequestLink.spec.jsx 3.2 KB

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