integrationOrganizationLink.spec.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import pick from 'lodash/pick';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {selectByValue} from 'sentry-test/select-new';
  4. import IntegrationOrganizationLink from 'sentry/views/integrationOrganizationLink';
  5. describe('IntegrationOrganizationLink', () => {
  6. let wrapper,
  7. getOrgsMock,
  8. getOrgMock,
  9. getProviderMock,
  10. getMountedComponent,
  11. org1,
  12. org1Lite,
  13. org2,
  14. org2Lite;
  15. beforeEach(() => {
  16. MockApiClient.clearMockResponses();
  17. org1 = TestStubs.Organization({
  18. slug: 'org1',
  19. name: 'Organization 1',
  20. });
  21. org2 = TestStubs.Organization({
  22. slug: 'org2',
  23. name: 'Organization 2',
  24. });
  25. org1Lite = pick(org1, ['slug', 'name', 'id']);
  26. org2Lite = pick(org2, ['slug', 'name', 'id']);
  27. getOrgsMock = MockApiClient.addMockResponse({
  28. url: '/organizations/',
  29. body: [org1Lite, org2Lite],
  30. });
  31. getMountedComponent = () =>
  32. mountWithTheme(
  33. <IntegrationOrganizationLink params={{integrationSlug: 'vercel'}} />
  34. );
  35. });
  36. it('selecting org from dropdown loads the org through the API', async () => {
  37. getOrgMock = MockApiClient.addMockResponse({
  38. url: `/organizations/${org2.slug}/`,
  39. body: org2,
  40. });
  41. getProviderMock = MockApiClient.addMockResponse({
  42. url: `/organizations/${org2.slug}/config/integrations/?provider_key=vercel`,
  43. body: {providers: [TestStubs.VercelProvider()]},
  44. });
  45. wrapper = getMountedComponent();
  46. expect(getOrgsMock).toHaveBeenCalled();
  47. expect(getOrgMock).not.toHaveBeenCalled();
  48. await tick();
  49. wrapper.update();
  50. selectByValue(wrapper, org2.slug, {control: true});
  51. await tick();
  52. wrapper.update();
  53. expect(wrapper.state('selectedOrgSlug')).toBe(org2.slug);
  54. expect(wrapper.state('organization')).toBe(org2);
  55. expect(getProviderMock).toHaveBeenCalled();
  56. expect(getOrgMock).toHaveBeenCalled();
  57. });
  58. });