2019-02-05 17:33:12 +01:00
|
|
|
/*
|
|
|
|
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 React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import ReactTestUtils from 'react-dom/test-utils';
|
2019-12-16 12:12:48 +01:00
|
|
|
import sdk from '../../../skinned-sdk';
|
2019-02-05 17:33:12 +01:00
|
|
|
import SdkConfig from '../../../../src/SdkConfig';
|
2019-05-03 07:46:43 +02:00
|
|
|
import {mkServerConfig} from "../../../test-utils";
|
2019-02-05 17:33:12 +01:00
|
|
|
|
|
|
|
const Login = sdk.getComponent(
|
|
|
|
'structures.auth.Login',
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('Login', function() {
|
|
|
|
let parentDiv;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
parentDiv = document.createElement('div');
|
|
|
|
document.body.appendChild(parentDiv);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
|
|
|
parentDiv.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
return ReactDOM.render(<Login
|
2019-05-03 07:46:43 +02:00
|
|
|
serverConfig={mkServerConfig("https://matrix.org", "https://vector.im")}
|
2019-02-05 17:33:12 +01:00
|
|
|
onLoggedIn={() => {}}
|
|
|
|
onRegisterClick={() => {}}
|
|
|
|
onServerConfigChange={() => {}}
|
|
|
|
/>, parentDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should show form with change server link', function() {
|
|
|
|
const root = render();
|
|
|
|
|
2019-09-11 12:20:03 +02:00
|
|
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
|
|
|
root.setState({
|
2020-11-25 11:22:16 +01:00
|
|
|
flows: [{ type: "m.login.password" }],
|
2019-09-11 12:20:03 +02:00
|
|
|
});
|
|
|
|
|
2019-02-05 17:33:12 +01:00
|
|
|
const form = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
root,
|
|
|
|
sdk.getComponent('auth.PasswordLogin'),
|
|
|
|
);
|
|
|
|
expect(form).toBeTruthy();
|
|
|
|
|
2020-11-25 11:22:16 +01:00
|
|
|
const changeServerLink = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_ServerPicker_change');
|
2019-02-05 17:33:12 +01:00
|
|
|
expect(changeServerLink).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show form without change server link when custom URLs disabled', function() {
|
2019-12-16 12:55:01 +01:00
|
|
|
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
2019-02-05 17:33:12 +01:00
|
|
|
disable_custom_urls: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const root = render();
|
|
|
|
|
2019-09-11 12:01:06 +02:00
|
|
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
|
|
|
root.setState({
|
2020-11-25 11:22:16 +01:00
|
|
|
flows: [{ type: "m.login.password" }],
|
2019-09-11 12:01:06 +02:00
|
|
|
});
|
|
|
|
|
2019-02-05 17:33:12 +01:00
|
|
|
const form = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
root,
|
|
|
|
sdk.getComponent('auth.PasswordLogin'),
|
|
|
|
);
|
|
|
|
expect(form).toBeTruthy();
|
|
|
|
|
2020-11-25 11:22:16 +01:00
|
|
|
const changeServerLinks = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, 'mx_ServerPicker_change');
|
2019-02-05 17:33:12 +01:00
|
|
|
expect(changeServerLinks).toHaveLength(0);
|
|
|
|
});
|
2020-11-25 11:22:16 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2019-02-05 17:33:12 +01:00
|
|
|
});
|