pullRequestLink.spec.jsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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('IconGithub').hostNodes();
  28. expect(icon).toHaveLength(0);
  29. const link = wrapper.find('a');
  30. expect(link).toHaveLength(1);
  31. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  32. });
  33. it('renders github links for github repositories', function () {
  34. const repository = TestStubs.Repository({
  35. provider: {
  36. id: 'github',
  37. },
  38. });
  39. const pullRequest = TestStubs.PullRequest({repository});
  40. const wrapper = mount(
  41. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  42. );
  43. const icon = wrapper.find('IconGithub').hostNodes();
  44. expect(icon).toHaveLength(0);
  45. const link = wrapper.find('a');
  46. expect(link).toHaveLength(1);
  47. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  48. });
  49. it('renders gitlab links for integrations:gitlab repositories', function () {
  50. const repository = TestStubs.Repository({
  51. provider: {
  52. id: 'integrations:gitlab',
  53. },
  54. });
  55. const pullRequest = TestStubs.PullRequest({repository});
  56. const wrapper = mount(
  57. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  58. );
  59. const icon = wrapper.find('IconGitlab').hostNodes();
  60. expect(icon).toHaveLength(0);
  61. const link = wrapper.find('a');
  62. expect(link).toHaveLength(1);
  63. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  64. });
  65. it('renders github links for gitlab repositories', function () {
  66. const repository = TestStubs.Repository({
  67. provider: {
  68. id: 'gitlab',
  69. },
  70. });
  71. const pullRequest = TestStubs.PullRequest({repository});
  72. const wrapper = mount(
  73. <PullRequestLink repository={repository} pullRequest={pullRequest} />
  74. );
  75. const icon = wrapper.find('IconGitlab').hostNodes();
  76. expect(icon).toHaveLength(0);
  77. const link = wrapper.find('a');
  78. expect(link).toHaveLength(1);
  79. expect(link.text().trim()).toEqual('example/repo-name #3: Fix first issue');
  80. });
  81. });