configureIntegration.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {OpsgenieIntegrationFixture} from 'sentry-fixture/opsgenieIntegration';
  2. import {OpsgenieIntegrationProviderFixture} from 'sentry-fixture/opsgenieIntegrationProvider';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  5. import {
  6. render,
  7. renderGlobalModal,
  8. screen,
  9. userEvent,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import ConfigureIntegration from 'sentry/views/settings/organizationIntegrations/configureIntegration';
  12. describe('OpsgenieMigrationButton', function () {
  13. const org = OrganizationFixture({
  14. access: ['org:integrations', 'org:write'],
  15. });
  16. const integrationId = '1';
  17. it('Migrate Plugin button hits migration endpoint', async function () {
  18. MockApiClient.addMockResponse({
  19. url: `/organizations/${org.slug}/config/integrations/`,
  20. body: {
  21. providers: [OpsgenieIntegrationProviderFixture()],
  22. },
  23. });
  24. MockApiClient.addMockResponse({
  25. url: `/organizations/${org.slug}/integrations/${integrationId}/`,
  26. body: OpsgenieIntegrationFixture(),
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/organizations/${org.slug}/plugins/configs/`,
  30. body: [
  31. {
  32. id: 'opsgenie',
  33. name: 'Opsgenie',
  34. slug: 'opsgenie',
  35. projectList: [
  36. {
  37. projectId: 2,
  38. projectSlug: 'python',
  39. projectName: 'python',
  40. enabled: true,
  41. configured: true,
  42. projectPlatform: 'python',
  43. },
  44. ],
  45. },
  46. ],
  47. });
  48. const onConfirmCall = MockApiClient.addMockResponse({
  49. url: `/organizations/${org.slug}/integrations/${integrationId}/migrate-opsgenie/`,
  50. method: 'PUT',
  51. });
  52. render(
  53. <ConfigureIntegration
  54. {...RouteComponentPropsFixture()}
  55. params={{integrationId, providerKey: 'opsgenie'}}
  56. />,
  57. {organization: org}
  58. );
  59. renderGlobalModal();
  60. expect(await screen.findByRole('button', {name: 'Migrate Plugin'})).toBeEnabled();
  61. await userEvent.click(screen.getByRole('button', {name: 'Migrate Plugin'}));
  62. expect(screen.queryByRole('button', {name: 'Confirm'})).toBeInTheDocument();
  63. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  64. expect(onConfirmCall).toHaveBeenCalled();
  65. });
  66. });