awsLambdaFunctionSelect.spec.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import AwsLambdaFunctionSelect from 'sentry/views/integrationPipeline/awsLambdaFunctionSelect';
  3. describe('AwsLambdaFunctionSelect', () => {
  4. it('choose lambdas', async () => {
  5. render(
  6. <AwsLambdaFunctionSelect
  7. initialStepNumber={0}
  8. lambdaFunctions={[
  9. {FunctionName: 'lambdaA', Runtime: 'nodejs12.x'},
  10. {FunctionName: 'lambdaB', Runtime: 'nodejs10.x'},
  11. {FunctionName: 'lambdaC', Runtime: 'nodejs10.x'},
  12. ]}
  13. />
  14. );
  15. expect(screen.getByRole('checkbox', {name: 'lambdaB'})).toBeInTheDocument();
  16. expect(screen.getByRole('button', {name: 'Finish Setup'})).toBeInTheDocument();
  17. // Uncheck lambda A
  18. await userEvent.click(screen.getByRole('checkbox', {name: 'lambdaA'}));
  19. const {promise, resolve} = Promise.withResolvers<FormData>();
  20. const submitForm = jest.fn((e: SubmitEvent) => {
  21. e.preventDefault();
  22. if (e.target instanceof HTMLFormElement) {
  23. resolve(new FormData(e.target));
  24. }
  25. });
  26. window.addEventListener('submit', submitForm);
  27. // Submit form
  28. await userEvent.click(screen.getByRole('button', {name: 'Finish Setup'}));
  29. expect(submitForm).toHaveBeenCalled();
  30. // Validate data was passed
  31. const formData = await promise;
  32. expect(Object.fromEntries(formData.entries())).toEqual({
  33. lambdaA: 'false',
  34. lambdaB: 'true',
  35. lambdaC: 'true',
  36. });
  37. window.removeEventListener('submit', submitForm);
  38. });
  39. });