From 143ffccb0a1e70699f3a1e2980c37b7ab344d647 Mon Sep 17 00:00:00 2001 From: Kerry Date: Thu, 1 Jun 2023 13:08:44 +1200 Subject: [PATCH] Fix: server picker validates unselected option (#11020) * add aria-label to default homeserver checkbox * test ServerPickerDialog * remove debug * strict fixes * dont validate unselected server field on ServerPickerDialog * i18n --- src/components/views/dialogs/ServerPickerDialog.tsx | 8 ++++++-- test/components/views/dialogs/ServerPickerDialog-test.tsx | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/views/dialogs/ServerPickerDialog.tsx b/src/components/views/dialogs/ServerPickerDialog.tsx index 03c046084f..9641bd7715 100644 --- a/src/components/views/dialogs/ServerPickerDialog.tsx +++ b/src/components/views/dialogs/ServerPickerDialog.tsx @@ -157,15 +157,19 @@ export default class ServerPickerDialog extends React.PureComponent => { ev.preventDefault(); + if (this.state.defaultChosen) { + this.props.onFinished(this.defaultServer); + } + const valid = await this.fieldRef.current?.validate({ allowEmpty: false }); - if (!valid && !this.state.defaultChosen) { + if (!valid) { this.fieldRef.current?.focus(); this.fieldRef.current?.validate({ allowEmpty: false, focused: true }); return; } - this.props.onFinished(this.state.defaultChosen ? this.defaultServer : this.validatedConf); + this.props.onFinished(this.validatedConf); }; public render(): React.ReactNode { diff --git a/test/components/views/dialogs/ServerPickerDialog-test.tsx b/test/components/views/dialogs/ServerPickerDialog-test.tsx index 2ddfcb0c84..f54ed1beb5 100644 --- a/test/components/views/dialogs/ServerPickerDialog-test.tsx +++ b/test/components/views/dialogs/ServerPickerDialog-test.tsx @@ -110,12 +110,6 @@ describe("", () => { fireEvent.click(screen.getByText("Continue")); - // serverpicker still validates the 'other homeserver' field on submit - // when default is chosen - // so this throws a lot of errors into the console - // and is asynchronous while waiting for validation - await flushPromises(); - // closed dialog with default server expect(onFinished).toHaveBeenCalledWith(defaultServerConfig); });