index.spec.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import selectEvent from 'react-select-event';
  2. import pick from 'lodash/pick';
  3. import {VercelProvider} from 'sentry-fixture/vercelIntegration';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import IntegrationOrganizationLink from 'sentry/views/integrationOrganizationLink';
  7. describe('IntegrationOrganizationLink', () => {
  8. it('selecting org from dropdown loads the org through the API', async () => {
  9. const {routerProps} = initializeOrg();
  10. const org1 = TestStubs.Organization({
  11. slug: 'org1',
  12. name: 'Organization 1',
  13. });
  14. const org2 = TestStubs.Organization({
  15. slug: 'org2',
  16. name: 'Organization 2',
  17. });
  18. const org1Lite = pick(org1, ['slug', 'name', 'id']);
  19. const org2Lite = pick(org2, ['slug', 'name', 'id']);
  20. const getOrgsMock = MockApiClient.addMockResponse({
  21. url: '/organizations/',
  22. body: [org1Lite, org2Lite],
  23. });
  24. const getOrgMock = MockApiClient.addMockResponse({
  25. url: `/organizations/${org2.slug}/`,
  26. body: org2,
  27. });
  28. const getProviderMock = MockApiClient.addMockResponse({
  29. url: `/organizations/${org2.slug}/config/integrations/?provider_key=vercel`,
  30. body: {providers: [VercelProvider()]},
  31. });
  32. render(
  33. <IntegrationOrganizationLink
  34. {...routerProps}
  35. params={{integrationSlug: 'vercel'}}
  36. />
  37. );
  38. expect(getOrgsMock).toHaveBeenCalled();
  39. expect(getOrgMock).not.toHaveBeenCalled();
  40. // Select organization
  41. await selectEvent.select(screen.getByRole('textbox'), org2.name);
  42. expect(screen.getByRole('button', {name: 'Install Vercel'})).toBeEnabled();
  43. expect(getProviderMock).toHaveBeenCalled();
  44. expect(getOrgMock).toHaveBeenCalled();
  45. });
  46. });