integrationOrganizationLink.spec.jsx 1.7 KB

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