addIntegrationRow.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 AddIntegrationRow from 'sentry/views/alerts/rules/issue/addIntegrationRow';
  6. import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
  7. jest.mock('sentry/actionCreators/modal');
  8. describe('AddIntegrationRow', function () {
  9. let org;
  10. const project = ProjectFixture();
  11. const provider = GitHubIntegrationProviderFixture();
  12. beforeEach(function () {
  13. org = OrganizationFixture();
  14. jest.clearAllMocks();
  15. });
  16. const getComponent = () => (
  17. <IntegrationContext.Provider
  18. value={{
  19. provider: provider,
  20. type: 'first_party',
  21. installStatus: 'Not Installed',
  22. analyticsParams: {
  23. view: 'onboarding',
  24. already_installed: false,
  25. },
  26. modalParams: {project: project.id},
  27. }}
  28. >
  29. <AddIntegrationRow onClick={jest.fn()} />
  30. </IntegrationContext.Provider>
  31. );
  32. it('renders', async () => {
  33. render(getComponent(), {organization: org});
  34. const button = await screen.findByRole('button', {name: /add integration/i});
  35. expect(button).toBeInTheDocument();
  36. });
  37. it('opens the setup dialog on click', async () => {
  38. const focus = jest.fn();
  39. const open = jest.fn().mockReturnValue({focus, close: jest.fn()});
  40. // any is needed here because getSentry has different types for global
  41. (global as any).open = open;
  42. render(getComponent(), {organization: org});
  43. const button = await screen.findByRole('button', {name: /add integration/i});
  44. await userEvent.click(button);
  45. expect(open.mock.calls).toHaveLength(1);
  46. expect(focus.mock.calls).toHaveLength(1);
  47. expect(open.mock.calls[0][2]).toBe(
  48. 'scrollbars=yes,width=100,height=100,top=334,left=462'
  49. );
  50. });
  51. it('renders request button when user does not have access', async () => {
  52. org.access = ['org:read'];
  53. render(getComponent(), {organization: org});
  54. await screen.findByRole('button', {name: /request installation/i});
  55. });
  56. });