From 5432b0947853caef98520da59be668be5ef0f230 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 5 Feb 2019 05:25:13 +0000 Subject: [PATCH 1/3] Default to registration phase when custom URLs disabled --- src/components/structures/auth/Login.js | 1 - src/components/structures/auth/Registration.js | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index a98e77c12bd..17da4a855f1 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -560,7 +560,6 @@ module.exports = React.createClass({ const ModularServerConfig = sdk.getComponent("auth.ModularServerConfig"); const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); - // TODO: May need to adjust the behavior of this config option if (SdkConfig.get()['disable_custom_urls']) { return null; } diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index c0b393febfb..55cb4b7499a 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -69,6 +69,8 @@ module.exports = React.createClass({ }, getInitialState: function() { + const customURLsAllowed = !SdkConfig.get()['disable_custom_urls']; + return { busy: false, errorText: null, @@ -90,6 +92,8 @@ module.exports = React.createClass({ serverType: null, hsUrl: this.props.customHsUrl, isUrl: this.props.customIsUrl, + // Phase of the overall registration dialog. + phase: customURLsAllowed ? PHASE_SERVER_DETAILS : PHASE_REGISTRATION, flows: null, }; }, @@ -367,7 +371,6 @@ module.exports = React.createClass({ const ModularServerConfig = sdk.getComponent("auth.ModularServerConfig"); const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); - // TODO: May need to adjust the behavior of this config option if (SdkConfig.get()['disable_custom_urls']) { return null; } From a73e3dcd4ceaa58c4c1608b7a936c51254407e5a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 5 Feb 2019 07:11:29 +0000 Subject: [PATCH 2/3] Remove unused props from registration --- src/components/structures/MatrixChat.js | 4 ---- src/components/structures/auth/Registration.js | 6 ------ 2 files changed, 10 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 613d310da97..77800109e44 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1891,7 +1891,6 @@ export default React.createClass({ sessionId={this.state.register_session_id} idSid={this.state.register_id_sid} email={this.props.startingFragmentQueryParams.email} - referrer={this.props.startingFragmentQueryParams.referrer} defaultServerDiscoveryError={this.state.defaultServerDiscoveryError} defaultHsUrl={this.getDefaultHsUrl()} defaultIsUrl={this.getDefaultIsUrl()} @@ -1899,11 +1898,8 @@ export default React.createClass({ customHsUrl={this.getCurrentHsUrl()} customIsUrl={this.getCurrentIsUrl()} makeRegistrationUrl={this._makeRegistrationUrl} - defaultDeviceDisplayName={this.props.defaultDeviceDisplayName} onLoggedIn={this.onRegistered} onLoginClick={this.onLoginClick} - onRegisterClick={this.onRegisterClick} - onCancelClick={MatrixClientPeg.get() ? this.onReturnToAppClick : null} onServerConfigChange={this.onServerConfigChange} /> ); diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 55cb4b7499a..69abd8b88b2 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -54,17 +54,11 @@ module.exports = React.createClass({ defaultIsUrl: PropTypes.string, brand: PropTypes.string, email: PropTypes.string, - referrer: PropTypes.string, - // An error passed along from higher up explaining that something // went wrong when finding the defaultHsUrl. defaultServerDiscoveryError: PropTypes.string, - - defaultDeviceDisplayName: PropTypes.string, - // registration shouldn't know or care how login is done. onLoginClick: PropTypes.func.isRequired, - onCancelClick: PropTypes.func, onServerConfigChange: PropTypes.func.isRequired, }, From 71d1a24fcb79a81c66f74d9e51f78a920fed4570 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 5 Feb 2019 09:26:45 +0000 Subject: [PATCH 3/3] Add some basic registration tests --- .../structures/auth/Registration-test.js | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/components/structures/auth/Registration-test.js diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js new file mode 100644 index 00000000000..a10201d4658 --- /dev/null +++ b/test/components/structures/auth/Registration-test.js @@ -0,0 +1,83 @@ +/* +Copyright 2019 New Vector Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import expect from 'expect'; +import sinon from 'sinon'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestUtils from 'react-dom/test-utils'; +import sdk from 'matrix-react-sdk'; +import SdkConfig from '../../../../src/SdkConfig'; +import * as TestUtils from '../../../test-utils'; + +const Registration = sdk.getComponent( + 'structures.auth.Registration', +); + +describe('Registration', function() { + let parentDiv; + + beforeEach(function() { + TestUtils.beforeEach(this); + parentDiv = document.createElement('div'); + document.body.appendChild(parentDiv); + }); + + afterEach(function() { + sinon.restore(); + ReactDOM.unmountComponentAtNode(parentDiv); + parentDiv.remove(); + }); + + function render() { + return ReactDOM.render( {}} + onLoggedIn={() => {}} + onLoginClick={() => {}} + onServerConfigChange={() => {}} + />, parentDiv); + } + + it('should show server type selector', function() { + const root = render(); + const selector = ReactTestUtils.findRenderedComponentWithType( + root, + sdk.getComponent('auth.ServerTypeSelector'), + ); + expect(selector).toBeTruthy(); + }); + + it('should show form when custom URLs disabled', function() { + sinon.stub(SdkConfig, "get").returns({ + disable_custom_urls: true, + }); + + const root = render(); + + // Set non-empty flows to get past the loading spinner + root.setState({ + flows: [], + }); + + const form = ReactTestUtils.findRenderedComponentWithType( + root, + sdk.getComponent('auth.RegistrationForm'), + ); + expect(form).toBeTruthy(); + }); +});