addIntegration.spec.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import AddIntegration from 'sentry/views/organizationIntegrations/addIntegration';
  3. describe('AddIntegration', function () {
  4. const provider = TestStubs.GitHubIntegrationProvider();
  5. const integration = TestStubs.GitHubIntegration();
  6. it('Adds an integration on dialog completion', async function () {
  7. const onAdd = jest.fn();
  8. const focus = jest.fn();
  9. const open = jest.fn().mockReturnValue({focus});
  10. global.open = open;
  11. render(
  12. <AddIntegration provider={provider} onInstall={onAdd}>
  13. {onClick => (
  14. <a href="#" onClick={onClick}>
  15. Click
  16. </a>
  17. )}
  18. </AddIntegration>
  19. );
  20. const newIntegration = {
  21. success: true,
  22. data: Object.assign({}, integration, {
  23. id: '2',
  24. domain_name: 'new-integration.github.com',
  25. icon: 'http://example.com/new-integration-icon.png',
  26. name: 'New Integration',
  27. }),
  28. };
  29. window.postMessage(newIntegration, '*');
  30. await waitFor(() => expect(onAdd).toHaveBeenCalledWith(newIntegration.data));
  31. });
  32. });