integrationButton.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import type {IntegrationProvider} from 'sentry/types/integrations';
  6. import type {Organization} from 'sentry/types/organization';
  7. import IntegrationButton from 'sentry/views/settings/organizationIntegrations/integrationButton';
  8. import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
  9. describe('AddIntegrationButton', function () {
  10. let org: Organization,
  11. provider: IntegrationProvider,
  12. hasAccess: boolean,
  13. externalInstallText: string | undefined;
  14. const project = ProjectFixture();
  15. beforeEach(function () {
  16. provider = GitHubIntegrationProviderFixture();
  17. org = OrganizationFixture();
  18. hasAccess = true;
  19. externalInstallText = undefined;
  20. });
  21. const getComponent = () => (
  22. <IntegrationContext.Provider
  23. value={{
  24. provider: provider,
  25. type: 'first_party',
  26. installStatus: 'Not Installed',
  27. analyticsParams: {
  28. view: 'onboarding',
  29. already_installed: false,
  30. },
  31. modalParams: {project: project.id},
  32. }}
  33. >
  34. <IntegrationButton
  35. userHasAccess={hasAccess}
  36. onAddIntegration={jest.fn()}
  37. onExternalClick={jest.fn()}
  38. externalInstallText={externalInstallText}
  39. buttonProps={null}
  40. />
  41. </IntegrationContext.Provider>
  42. );
  43. it('Opens the setup dialog on click', async function () {
  44. const focus = jest.fn();
  45. const open = jest.fn().mockReturnValue({focus, close: jest.fn()});
  46. // any is needed here because getSentry has different types for global
  47. (global as any).open = open;
  48. render(getComponent());
  49. await userEvent.click(screen.getByText(/add installation/i));
  50. expect(open.mock.calls).toHaveLength(1);
  51. expect(focus.mock.calls).toHaveLength(1);
  52. expect(open.mock.calls[0][2]).toBe(
  53. 'scrollbars=yes,width=100,height=100,top=334,left=462'
  54. );
  55. });
  56. it('Renders request button when user does not have access', async function () {
  57. hasAccess = false;
  58. render(getComponent(), {organization: org});
  59. await userEvent.click(screen.getByText('Request Installation'));
  60. });
  61. it('Handles external installations with default button text', async function () {
  62. provider.canAdd = false;
  63. provider.metadata.aspects = {
  64. externalInstall: {
  65. url: 'https://teams.microsoft.com/l/app/',
  66. buttonText: 'Teams Marketplace',
  67. noticeText:
  68. 'Visit the Teams Marketplace to install this integration. After adding the integration to your team, you will get a welcome message in the General channel to complete installation.',
  69. },
  70. };
  71. render(getComponent(), {organization: org});
  72. await userEvent.click(screen.getByText('Teams Marketplace'));
  73. });
  74. it('Handles external installations with custom button text', async function () {
  75. provider.canAdd = false;
  76. provider.metadata.aspects = {
  77. externalInstall: {
  78. url: 'https://teams.microsoft.com/l/app/',
  79. buttonText: 'Teams Marketplace',
  80. noticeText:
  81. 'Visit the Teams Marketplace to install this integration. After adding the integration to your team, you will get a welcome message in the General channel to complete installation.',
  82. },
  83. };
  84. externalInstallText = 'Add Installation';
  85. render(getComponent(), {organization: org});
  86. await userEvent.click(screen.getByText('Add Installation'));
  87. });
  88. });