From 1b1c482f9cb55b1753993894bac527496862df25 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 25 Nov 2020 10:22:16 +0000 Subject: [PATCH] Iterate tests --- res/css/views/elements/_ServerPicker.scss | 2 +- .../structures/auth/Registration.tsx | 36 ++++----- .../views/elements/ServerPicker.tsx | 2 +- test/components/structures/auth/Login-test.js | 77 ++++++++++++++++--- .../structures/auth/Registration-test.js | 30 ++++++-- 5 files changed, 108 insertions(+), 39 deletions(-) diff --git a/res/css/views/elements/_ServerPicker.scss b/res/css/views/elements/_ServerPicker.scss index d3d56a5cd7..ae1e445a9f 100644 --- a/res/css/views/elements/_ServerPicker.scss +++ b/res/css/views/elements/_ServerPicker.scss @@ -65,7 +65,7 @@ limitations under the License. margin-bottom: 16px; } - .mx_AccessibleButton_kind_link { + .mx_ServerPicker_change { padding: 0; font-size: inherit; grid-column: 2; diff --git a/src/components/structures/auth/Registration.tsx b/src/components/structures/auth/Registration.tsx index bf3e4a51d3..750e4bb88b 100644 --- a/src/components/structures/auth/Registration.tsx +++ b/src/components/structures/auth/Registration.tsx @@ -437,19 +437,6 @@ export default class Registration extends React.Component { } }; - private renderServerComponent() { - if (SdkConfig.get()['disable_custom_urls']) { - return null; - } - - return ; - } - private renderRegisterComponent() { const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth'); const Spinner = sdk.getComponent('elements.Spinner'); @@ -474,16 +461,16 @@ export default class Registration extends React.Component { ; } else if (this.state.flows.length) { - let continueWithSection; - const providers = this.state.ssoFlow["org.matrix.msc2858.identity_providers"] - || this.state.ssoFlow.identity_providers || []; - // when there is only a single (or 0) providers we show a wide button with `Continue with X` text - if (providers.length > 1) { - continueWithSection =

{_t("Continue with")}

; - } - let ssoSection; if (this.state.ssoFlow) { + let continueWithSection; + const providers = this.state.ssoFlow["org.matrix.msc2858.identity_providers"] + || this.state.ssoFlow["identity_providers"] || []; + // when there is only a single (or 0) providers we show a wide button with `Continue with X` text + if (providers.length > 1) { + continueWithSection =

{_t("Continue with")}

; + } + ssoSection = { continueWithSection } {

{ _t('Create account') }

{ errorText } { serverDeadSection } - { this.renderServerComponent() } + { this.renderRegisterComponent() } { goBack } { signIn } diff --git a/src/components/views/elements/ServerPicker.tsx b/src/components/views/elements/ServerPicker.tsx index 95ad9030b2..b7fe7e8e84 100644 --- a/src/components/views/elements/ServerPicker.tsx +++ b/src/components/views/elements/ServerPicker.tsx @@ -63,7 +63,7 @@ const ServerPicker = ({ title, dialogTitle, serverConfig, onServerConfigChange } } }); }; - editBtn = + editBtn = {_t("Edit")} ; } diff --git a/test/components/structures/auth/Login-test.js b/test/components/structures/auth/Login-test.js index 7ca210ff93..0631e26cbd 100644 --- a/test/components/structures/auth/Login-test.js +++ b/test/components/structures/auth/Login-test.js @@ -52,7 +52,7 @@ describe('Login', function() { // Set non-empty flows & matrixClient to get past the loading spinner root.setState({ - currentFlow: "m.login.password", + flows: [{ type: "m.login.password" }], }); const form = ReactTestUtils.findRenderedComponentWithType( @@ -61,10 +61,7 @@ describe('Login', function() { ); expect(form).toBeTruthy(); - const changeServerLink = ReactTestUtils.findRenderedDOMComponentWithClass( - root, - 'mx_AuthBody_editServerDetails', - ); + const changeServerLink = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_ServerPicker_change'); expect(changeServerLink).toBeTruthy(); }); @@ -77,7 +74,7 @@ describe('Login', function() { // Set non-empty flows & matrixClient to get past the loading spinner root.setState({ - currentFlow: "m.login.password", + flows: [{ type: "m.login.password" }], }); const form = ReactTestUtils.findRenderedComponentWithType( @@ -86,10 +83,70 @@ describe('Login', function() { ); expect(form).toBeTruthy(); - const changeServerLinks = ReactTestUtils.scryRenderedDOMComponentsWithClass( - root, - 'mx_AuthBody_editServerDetails', - ); + const changeServerLinks = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, 'mx_ServerPicker_change'); expect(changeServerLinks).toHaveLength(0); }); + + it("should show SSO button if that flow is available", () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ + disable_custom_urls: true, + }); + + const root = render(); + + // Set non-empty flows & matrixClient to get past the loading spinner + root.setState({ + flows: [{ type: "m.login.sso" }], + }); + + const ssoButton = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_SSOButton"); + expect(ssoButton).toBeTruthy(); + }); + + it("should show both SSO button and username+password if both are available", () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ + disable_custom_urls: true, + }); + + const root = render(); + + // Set non-empty flows & matrixClient to get past the loading spinner + root.setState({ + flows: [{ type: "m.login.password" }, { type: "m.login.sso" }], + }); + + const form = ReactTestUtils.findRenderedComponentWithType(root, sdk.getComponent('auth.PasswordLogin')); + expect(form).toBeTruthy(); + + const ssoButton = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_SSOButton"); + expect(ssoButton).toBeTruthy(); + }); + + it("should show multiple SSO buttons if multiple identity_providers are available", () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ + disable_custom_urls: true, + }); + + const root = render(); + + // Set non-empty flows & matrixClient to get past the loading spinner + root.setState({ + flows: [{ + type: "m.login.sso", + identity_providers: [{ + id: "a", + name: "Provider 1", + }, { + id: "b", + name: "Provider 2", + }, { + id: "c", + name: "Provider 3", + }], + }], + }); + + const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton"); + expect(ssoButtons.length).toBe(3); + }); }); diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index bf26763a79..3e8e887329 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -48,12 +48,9 @@ describe('Registration', function() { />, parentDiv); } - it('should show server type selector', function() { + it('should show server picker', function() { const root = render(); - const selector = ReactTestUtils.findRenderedComponentWithType( - root, - sdk.getComponent('auth.ServerTypeSelector'), - ); + const selector = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_ServerPicker"); expect(selector).toBeTruthy(); }); @@ -79,4 +76,27 @@ describe('Registration', function() { ); expect(form).toBeTruthy(); }); + + it("should show SSO options if those are available", () => { + jest.spyOn(SdkConfig, "get").mockReturnValue({ + disable_custom_urls: true, + }); + + const root = render(); + + // Set non-empty flows & matrixClient to get past the loading spinner + root.setState({ + flows: [{ + stages: [], + }], + ssoFlow: { + type: "m.login.sso", + }, + matrixClient: {}, + busy: false, + }); + + const ssoButton = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_SSOButton"); + expect(ssoButton).toBeTruthy(); + }); });