index.spec.tsx 1.7 KB

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