2019-02-05 17:26:45 +08: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';
|
2021-12-08 17:34:24 +08:00
|
|
|
import { createClient } from 'matrix-js-sdk/src/matrix';
|
|
|
|
|
2021-12-09 17:10:23 +08:00
|
|
|
import sdk from '../../../skinned-sdk';
|
2019-02-05 17:26:45 +08:00
|
|
|
import SdkConfig from '../../../../src/SdkConfig';
|
2021-12-08 17:34:24 +08:00
|
|
|
import { createTestClient, mkServerConfig } from "../../../test-utils";
|
|
|
|
|
|
|
|
jest.mock('matrix-js-sdk/src/matrix');
|
|
|
|
jest.useFakeTimers();
|
2019-02-05 17:26:45 +08:00
|
|
|
|
|
|
|
const Registration = sdk.getComponent(
|
|
|
|
'structures.auth.Registration',
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('Registration', function() {
|
|
|
|
let parentDiv;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
parentDiv = document.createElement('div');
|
|
|
|
document.body.appendChild(parentDiv);
|
2021-12-08 17:34:24 +08:00
|
|
|
createClient.mockImplementation(() => createTestClient());
|
2019-02-05 17:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
|
|
|
parentDiv.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
return ReactDOM.render(<Registration
|
2019-05-03 13:46:43 +08:00
|
|
|
serverConfig={mkServerConfig("https://matrix.org", "https://vector.im")}
|
2019-02-05 17:26:45 +08:00
|
|
|
makeRegistrationUrl={() => {}}
|
|
|
|
onLoggedIn={() => {}}
|
|
|
|
onLoginClick={() => {}}
|
|
|
|
onServerConfigChange={() => {}}
|
|
|
|
/>, parentDiv);
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:34:24 +08:00
|
|
|
it('should show server picker', async function() {
|
2019-02-05 17:26:45 +08:00
|
|
|
const root = render();
|
2020-11-25 18:22:16 +08:00
|
|
|
const selector = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_ServerPicker");
|
2019-02-05 17:26:45 +08:00
|
|
|
expect(selector).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2021-12-08 17:34:24 +08:00
|
|
|
it('should show form when custom URLs disabled', async function() {
|
2019-12-16 19:55:01 +08:00
|
|
|
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
2019-02-05 17:26:45 +08:00
|
|
|
disable_custom_urls: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const root = render();
|
|
|
|
|
2019-08-16 22:36:41 +08:00
|
|
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
2019-02-05 17:26:45 +08:00
|
|
|
root.setState({
|
2019-09-19 17:31:34 +08:00
|
|
|
flows: [{
|
|
|
|
stages: [],
|
|
|
|
}],
|
2019-06-11 20:16:49 +08:00
|
|
|
matrixClient: {},
|
|
|
|
busy: false,
|
2019-02-05 17:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const form = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
root,
|
|
|
|
sdk.getComponent('auth.RegistrationForm'),
|
|
|
|
);
|
|
|
|
expect(form).toBeTruthy();
|
|
|
|
});
|
2020-11-25 18:22:16 +08:00
|
|
|
|
2021-12-08 17:34:24 +08:00
|
|
|
it("should show SSO options if those are available", async () => {
|
2020-11-25 18:22:16 +08:00
|
|
|
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();
|
|
|
|
});
|
2019-02-05 17:26:45 +08:00
|
|
|
});
|