index.spec.tsx 1.8 KB

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