Skip to content

Commit 2f0b07b

Browse files
web-forms (Vue UI): test for host app integration ignoring submit callback
1 parent 3a096ab commit 2f0b07b

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/web-forms/tests/components/OdkWebForm.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,21 @@ describe('OdkWebForm', () => {
397397
hostSubmissonHandler: asyncPostSubmissionNoopHandler,
398398
expectedPostSubmissionValue: firstSubmissionInputValue,
399399
},
400+
401+
// EVERYTHING is optional. This case ensures that introducing the callback
402+
// as a second parameter doesn't introduce regressions in a host
403+
// integration which only uses the first parameter.
404+
{
405+
description: 'does not reset form state by default (no callback)',
406+
hostSubmissonHandler: null,
407+
expectedPostSubmissionValue: firstSubmissionInputValue,
408+
},
400409
])('$description', async ({ hostSubmissonHandler, expectedPostSubmissionValue }) => {
401410
const component = mountComponent(resetStateForm, {
402411
onSubmit: (payload, callback) => {
403-
callback(hostSubmissonHandler?.(payload));
412+
if (hostSubmissonHandler != null) {
413+
callback(hostSubmissonHandler(payload));
414+
}
404415
},
405416
});
406417

@@ -415,11 +426,20 @@ describe('OdkWebForm', () => {
415426
// Click submit
416427
await component.get('button[aria-label="Send"]').trigger('click');
417428

418-
// Check that submission callback was called
419-
expect(submittedPayload).not.toBeNull();
429+
// Check either:
430+
//
431+
// - If "host" provides no submission handler, then no submission handler implementation could cause a side-effect (assignment of the payload it was passed to `submittedPayload`)
432+
// - If "host" does provide a submission handler, we've called it in the submit event handler.
433+
if (hostSubmissonHandler == null) {
434+
expect(submittedPayload).toBeNull();
435+
} else {
436+
expect(submittedPayload).not.toBeNull();
437+
}
420438

421439
textInput = component.get<HTMLInputElement>('input.p-inputtext');
422440

441+
// Check that Web Forms has performed the expected post-submit side effect
442+
// (if one is expected)
423443
expect(textInput.element.value).toBe(expectedPostSubmissionValue);
424444
});
425445
});

0 commit comments

Comments
 (0)