integrationButton.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. organization={org}
  36. userHasAccess={hasAccess}
  37. onAddIntegration={jest.fn()}
  38. onExternalClick={jest.fn()}
  39. externalInstallText={externalInstallText}
  40. buttonProps={null}
  41. />
  42. </IntegrationContext.Provider>
  43. );
  44. it('Opens the setup dialog on click', async function () {
  45. const focus = jest.fn();
  46. const open = jest.fn().mockReturnValue({focus, close: jest.fn()});
  47. // any is needed here because getSentry has different types for global
  48. (global as any).open = open;
  49. render(getComponent());
  50. await userEvent.click(screen.getByText(/add installation/i));
  51. expect(open.mock.calls).toHaveLength(1);
  52. expect(focus.mock.calls).toHaveLength(1);
  53. expect(open.mock.calls[0][2]).toBe(
  54. 'scrollbars=yes,width=100,height=100,top=334,left=462'
  55. );
  56. });
  57. it('Renders request button when user does not have access', async function () {
  58. hasAccess = false;
  59. render(getComponent());
  60. await userEvent.click(screen.getByText('Request Installation'));
  61. });
  62. it('Handles external installations with default button text', async function () {
  63. provider.canAdd = false;
  64. provider.metadata.aspects = {
  65. externalInstall: {
  66. url: 'https://teams.microsoft.com/l/app/',
  67. buttonText: 'Teams Marketplace',
  68. noticeText:
  69. '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.',
  70. },
  71. };
  72. render(getComponent());
  73. await userEvent.click(screen.getByText('Teams Marketplace'));
  74. });
  75. it('Handles external installations with custom button text', async function () {
  76. provider.canAdd = false;
  77. provider.metadata.aspects = {
  78. externalInstall: {
  79. url: 'https://teams.microsoft.com/l/app/',
  80. buttonText: 'Teams Marketplace',
  81. noticeText:
  82. '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.',
  83. },
  84. };
  85. externalInstallText = 'Add Installation';
  86. render(getComponent());
  87. await userEvent.click(screen.getByText('Add Installation'));
  88. });
  89. });