import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; import AwsLambdaFunctionSelect from 'sentry/views/integrationPipeline/awsLambdaFunctionSelect'; describe('AwsLambdaFunctionSelect', () => { it('choose lambdas', async () => { render( ); expect(screen.getByRole('checkbox', {name: 'lambdaB'})).toBeInTheDocument(); expect(screen.getByRole('button', {name: 'Finish Setup'})).toBeInTheDocument(); // Uncheck lambda A await userEvent.click(screen.getByRole('checkbox', {name: 'lambdaA'})); const {promise, resolve} = Promise.withResolvers(); const submitForm = jest.fn((e: SubmitEvent) => { e.preventDefault(); if (e.target instanceof HTMLFormElement) { resolve(new FormData(e.target)); } }); window.addEventListener('submit', submitForm); // Submit form await userEvent.click(screen.getByRole('button', {name: 'Finish Setup'})); expect(submitForm).toHaveBeenCalled(); // Validate data was passed const formData = await promise; expect(Object.fromEntries(formData.entries())).toEqual({ lambdaA: 'false', lambdaB: 'true', lambdaC: 'true', }); window.removeEventListener('submit', submitForm); }); });