diff --git a/src/internal/analytics/__tests__/components/analytics-funnel.test.tsx b/src/internal/analytics/__tests__/components/analytics-funnel.test.tsx index 080d598481..bd55fdf4b1 100644 --- a/src/internal/analytics/__tests__/components/analytics-funnel.test.tsx +++ b/src/internal/analytics/__tests__/components/analytics-funnel.test.tsx @@ -489,7 +489,7 @@ describe('AnalyticsFunnelSubStep', () => { }); }); - test('calls funnelSubStepComplete with the correct arguments when the substep loses focus', async () => { + test('calls funnelSubStepComplete with the correct arguments when the substep loses focus by keyboard', async () => { const ChildComponent = () => { const { subStepRef, funnelSubStepProps } = useFunnelSubStep(); @@ -529,8 +529,62 @@ describe('AnalyticsFunnelSubStep', () => { subStepNameSelector: expect.any(String), }); }); + + test('calls funnelSubStepComplete with the correct arguments when the substep loses focus by mouse', async () => { + const ChildComponent = () => { + const { subStepRef, funnelSubStepProps } = useFunnelSubStep(); + + return ( +
+ +
+ ); + }; + + const stepNumber = 1; + const stepNameSelector = '.step-name-selector'; + + const { getByTestId } = render( + <> + + + + + + + + + + ); + + simulateUserClick(getByTestId('input')); + + await runPendingPromises(); + + simulateUserClick(getByTestId('outside')); + + await runPendingPromises(); + + expect(FunnelMetrics.funnelSubStepComplete).toHaveBeenCalledTimes(1); + expect(FunnelMetrics.funnelSubStepComplete).toHaveBeenCalledWith({ + funnelInteractionId: mockedFunnelInteractionId, + stepNumber, + stepNameSelector, + subStepAllSelector: expect.any(String), + subStepSelector: expect.any(String), + subStepNameSelector: expect.any(String), + }); + }); }); +const simulateUserClick = (element: HTMLElement) => { + // See https://testing-library.com/docs/guide-events/ + fireEvent.mouseDown(element); + element.focus(); + fireEvent.mouseUp(element); + fireEvent.click(element); +}; + const runPendingPromises = async () => { jest.runAllTimers(); await Promise.resolve();