2019-02-05 12:26:45 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 New Vector Ltd
|
2022-05-16 11:23:51 +03:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2019-02-05 12:26:45 +03:00
|
|
|
|
|
|
|
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 12:34:24 +03:00
|
|
|
import { createClient } from 'matrix-js-sdk/src/matrix';
|
2022-05-16 11:23:51 +03:00
|
|
|
import { mocked } from 'jest-mock';
|
2021-12-08 12:34:24 +03:00
|
|
|
|
2022-02-21 19:57:44 +03:00
|
|
|
import SdkConfig, { DEFAULTS } from '../../../../src/SdkConfig';
|
2021-12-08 12:34:24 +03:00
|
|
|
import { createTestClient, mkServerConfig } from "../../../test-utils";
|
2022-03-03 00:09:24 +03:00
|
|
|
import Registration from "../../../../src/components/structures/auth/Registration";
|
|
|
|
import RegistrationForm from "../../../../src/components/views/auth/RegistrationForm";
|
2021-12-08 12:34:24 +03:00
|
|
|
|
|
|
|
jest.mock('matrix-js-sdk/src/matrix');
|
|
|
|
jest.useFakeTimers();
|
2019-02-05 12:26:45 +03:00
|
|
|
|
|
|
|
describe('Registration', function() {
|
|
|
|
let parentDiv;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2022-03-18 19:12:36 +03:00
|
|
|
SdkConfig.put({
|
2022-02-21 19:57:44 +03:00
|
|
|
...DEFAULTS,
|
|
|
|
disable_custom_urls: true,
|
|
|
|
});
|
2019-02-05 12:26:45 +03:00
|
|
|
parentDiv = document.createElement('div');
|
|
|
|
document.body.appendChild(parentDiv);
|
2022-05-16 11:23:51 +03:00
|
|
|
mocked(createClient).mockImplementation(() => createTestClient());
|
2019-02-05 12:26:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
|
|
|
parentDiv.remove();
|
2022-03-18 19:12:36 +03:00
|
|
|
SdkConfig.unset(); // we touch the config, so clean up
|
2019-02-05 12:26:45 +03:00
|
|
|
});
|
|
|
|
|
2022-05-16 11:23:51 +03:00
|
|
|
const defaultProps = {
|
|
|
|
defaultDeviceDisplayName: 'test-device-display-name',
|
|
|
|
serverConfig: mkServerConfig("https://matrix.org", "https://vector.im"),
|
|
|
|
makeRegistrationUrl: jest.fn(),
|
|
|
|
onLoggedIn: jest.fn(),
|
|
|
|
onLoginClick: jest.fn(),
|
|
|
|
onServerConfigChange: jest.fn(),
|
|
|
|
};
|
2019-02-05 12:26:45 +03:00
|
|
|
function render() {
|
2022-05-16 11:23:51 +03:00
|
|
|
return ReactDOM.render<typeof Registration>(<Registration
|
|
|
|
{...defaultProps}
|
|
|
|
/>, parentDiv) as React.Component<typeof Registration>;
|
2019-02-05 12:26:45 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 12:34:24 +03:00
|
|
|
it('should show server picker', async function() {
|
2019-02-05 12:26:45 +03:00
|
|
|
const root = render();
|
2020-11-25 13:22:16 +03:00
|
|
|
const selector = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_ServerPicker");
|
2019-02-05 12:26:45 +03:00
|
|
|
expect(selector).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2021-12-08 12:34:24 +03:00
|
|
|
it('should show form when custom URLs disabled', async function() {
|
2019-02-05 12:26:45 +03:00
|
|
|
const root = render();
|
|
|
|
|
2019-08-16 17:36:41 +03:00
|
|
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
2019-02-05 12:26:45 +03:00
|
|
|
root.setState({
|
2019-09-19 12:31:34 +03:00
|
|
|
flows: [{
|
|
|
|
stages: [],
|
|
|
|
}],
|
2019-06-11 15:16:49 +03:00
|
|
|
matrixClient: {},
|
|
|
|
busy: false,
|
2019-02-05 12:26:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const form = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
root,
|
2022-03-03 00:09:24 +03:00
|
|
|
RegistrationForm,
|
2019-02-05 12:26:45 +03:00
|
|
|
);
|
|
|
|
expect(form).toBeTruthy();
|
|
|
|
});
|
2020-11-25 13:22:16 +03:00
|
|
|
|
2021-12-08 12:34:24 +03:00
|
|
|
it("should show SSO options if those are available", async () => {
|
2020-11-25 13:22:16 +03:00
|
|
|
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 12:26:45 +03:00
|
|
|
});
|