awsLambdaCloudformation.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import selectEvent from 'react-select-event';
  2. import * as qs from 'query-string';
  3. import {fireEvent, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import AwsLambdaCloudformation from 'sentry/views/integrationPipeline/awsLambdaCloudformation';
  5. describe('AwsLambdaCloudformation', () => {
  6. let windowAssignMock;
  7. beforeEach(() => {
  8. windowAssignMock = jest.fn();
  9. window.location.assign = windowAssignMock;
  10. window.localStorage.setItem('AWS_EXTERNAL_ID', 'my-id');
  11. });
  12. it('submit arn', async () => {
  13. render(
  14. <AwsLambdaCloudformation
  15. baseCloudformationUrl="https://console.aws.amazon.com/cloudformation/home#/stacks/create/review"
  16. templateUrl="https://example.com/file.json"
  17. stackName="Sentry-Monitoring-Stack"
  18. regionList={['us-east-1', 'us-west-1']}
  19. accountNumber=""
  20. region=""
  21. initialStepNumber={0}
  22. />
  23. );
  24. // Open configuration fields
  25. await userEvent.click(screen.getByRole('button', {name: "I've created the stack"}));
  26. // XXX(epurkhiser): This form is pretty wonky with how it works, and
  27. // probably needs cleaned up again in the future. I couldn't get
  28. // await userEvent.type to work here because of something relating to the
  29. // validation I think.
  30. // Fill out fields
  31. const accountNumber = screen.getByRole('textbox', {name: 'AWS Account Number'});
  32. fireEvent.change(accountNumber, {target: {value: '599817902985'}});
  33. await selectEvent.select(screen.getByRole('textbox', {name: 'AWS Region'}), [
  34. ['us-west-1'],
  35. ]);
  36. expect(screen.getByRole('button', {name: 'Next'})).toBeEnabled();
  37. await userEvent.click(screen.getByRole('button', {name: 'Next'}));
  38. const query = qs.stringify({
  39. accountNumber: '599817902985',
  40. region: 'us-west-1',
  41. awsExternalId: 'my-id',
  42. });
  43. expect(windowAssignMock).toHaveBeenCalledWith(
  44. `${window.location.origin}/extensions/aws_lambda/setup/?${query}`
  45. );
  46. });
  47. });