diff --git a/frontend/src/components/Trial/Trial.test.tsx b/frontend/src/components/Trial/Trial.test.tsx index 5c3b5667c..4099bbdb8 100644 --- a/frontend/src/components/Trial/Trial.test.tsx +++ b/frontend/src/components/Trial/Trial.test.tsx @@ -158,4 +158,65 @@ describe('Trial', () => { ); }); }); + + it("calls onResult when form is not defined", async () => { + const formless_feedback_form = { + ...feedback_form, + form: undefined + }; + render(); + fireEvent.click(screen.getByTestId('mock-feedback-form')); + await waitFor(() => { + expect(mockOnResult).toHaveBeenCalled(); + }); + }); + + it("calls onResult and onNext when form is not defined and break_round_on is met", async () => { + const formless_feedback_form = { + ...feedback_form, + form: undefined + }; + const config = { + ...defaultConfig, + break_round_on: { NOT: ['fast'] } + }; + render(); + fireEvent.click(screen.getByTestId('mock-feedback-form')); + await waitFor(() => { + expect(mockOnResult).toHaveBeenCalled(); + expect(mockOnNext).toHaveBeenCalledTimes(1); + }); + }); + + it("calls only onResult when form is not defined and break_round_on is NOT met", async () => { + const formless_feedback_form = { + ...feedback_form, + form: undefined + }; + const config = { + ...defaultConfig, + break_round_on: { NOT: ['slow'] } + }; + render(); + fireEvent.click(screen.getByTestId('mock-feedback-form')); + await waitFor(() => { + expect(mockOnResult).toHaveBeenCalled(); + expect(mockOnNext).not.toHaveBeenCalled(); + }); + }); }); diff --git a/frontend/src/components/Trial/Trial.tsx b/frontend/src/components/Trial/Trial.tsx index be0c868f5..358fc7d85 100644 --- a/frontend/src/components/Trial/Trial.tsx +++ b/frontend/src/components/Trial/Trial.tsx @@ -63,10 +63,12 @@ const Trial = (props: TrialProps) => { // Create result data const makeResult = useCallback( async (result: { type: 'time_passed' }) => { + // Prevent multiple submissions if (submitted.current) { return; } + submitted.current = true; if (!feedback_form) { @@ -83,7 +85,7 @@ const Trial = (props: TrialProps) => { return; } - const { form } = feedback_form; + const { form = [] } = feedback_form; if (result.type === "time_passed") { form.map((formElement) => (formElement.value = "TIMEOUT"));