externalIssueActions.spec.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import ExternalIssueActions from 'sentry/components/group/externalIssueActions';
  8. describe('ExternalIssueActions', function () {
  9. const group = TestStubs.Group();
  10. afterEach(() => {
  11. MockApiClient.clearMockResponses();
  12. });
  13. describe('with no external issues linked', function () {
  14. const integration = TestStubs.GitHubIntegration({externalIssues: []});
  15. const configurations = [integration];
  16. it('renders', function () {
  17. const {container} = render(
  18. <ExternalIssueActions
  19. key="github"
  20. group={group}
  21. configurations={configurations}
  22. onChange={() => {}}
  23. />
  24. );
  25. expect(container).toSnapshot();
  26. // renders GitHub Issue when no issues currently linked
  27. expect(screen.getByText('GitHub Issue')).toBeInTheDocument();
  28. });
  29. it('opens hovercard', async function () {
  30. render(
  31. <ExternalIssueActions
  32. key="github"
  33. group={group}
  34. configurations={configurations}
  35. onChange={() => {}}
  36. />
  37. );
  38. userEvent.hover(screen.getByText('GitHub Issue'));
  39. expect(await screen.findByText('GitHub Integration')).toBeInTheDocument();
  40. expect(screen.getByText('github.com/test-integration')).toBeInTheDocument();
  41. });
  42. it('opens modal', async function () {
  43. const integrationConfigMock = MockApiClient.addMockResponse({
  44. url: '/groups/1/integrations/1/',
  45. body: {createIssueConfig: []},
  46. });
  47. render(
  48. <ExternalIssueActions
  49. key="github"
  50. group={group}
  51. configurations={configurations}
  52. onChange={() => {}}
  53. />
  54. );
  55. renderGlobalModal();
  56. userEvent.click(screen.getByRole('button', {name: 'Add'}));
  57. expect(await screen.findByText('Create Issue')).toBeInTheDocument();
  58. expect(integrationConfigMock).toHaveBeenCalledTimes(1);
  59. });
  60. });
  61. describe('with an external issue linked', function () {
  62. const externalIssues = [
  63. {
  64. id: 100,
  65. url: 'https://github.com/MeredithAnya/testing/issues/2',
  66. key: 'getsentry/sentry#2',
  67. },
  68. ];
  69. const integration = TestStubs.GitHubIntegration({externalIssues});
  70. const configurations = [integration];
  71. it('renders', function () {
  72. render(
  73. <ExternalIssueActions
  74. key="github"
  75. group={group}
  76. configurations={configurations}
  77. onChange={() => {}}
  78. />
  79. );
  80. expect(screen.getByText('getsentry/sentry#2')).toBeInTheDocument();
  81. });
  82. it('deletes when clicking x', function () {
  83. const mockDelete = MockApiClient.addMockResponse({
  84. url: '/groups/1/integrations/1/?externalIssue=100',
  85. method: 'DELETE',
  86. });
  87. render(
  88. <ExternalIssueActions
  89. key="github"
  90. group={group}
  91. configurations={configurations}
  92. onChange={() => {}}
  93. />
  94. );
  95. userEvent.click(screen.getByRole('button', {name: 'Close'}));
  96. expect(mockDelete).toHaveBeenCalledTimes(1);
  97. });
  98. });
  99. });