From d1ca1f41e71338348006714de933768915df1460 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Fri, 8 Dec 2023 10:18:03 +0100 Subject: [PATCH] :white_check_mark: [#607] Additional tests for valid phone number input --- src/formio/components/PhoneNumberField.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/formio/components/PhoneNumberField.spec.js b/src/formio/components/PhoneNumberField.spec.js index cb1e8860d..956788ccd 100644 --- a/src/formio/components/PhoneNumberField.spec.js +++ b/src/formio/components/PhoneNumberField.spec.js @@ -70,4 +70,22 @@ describe('The phone number component', () => { expect(await screen.findByText('Invalid Phone Number')).toBeVisible(); } ); + + it.each([ + ['+316 123 456 78'], + ['06-12 34 56 78'], + ['06-12-34-56 78'], // weird but ok + ])('allows dashes and spaces for formatting (value: %i)', async value => { + const user = userEvent.setup({delay: 50}); + const {form} = await renderForm(); + + const input = screen.getByLabelText('Phone number'); + expect(input).toBeVisible(); + await user.type(input, value); + expect(input).toHaveDisplayValue(value); + + const component = form.getComponent('phoneNumber'); + expect(component.getValue()).toBe(value); + expect(form.isValid()).toBe(true); + }); });