element-web/test/components/structures/auth/Registration-test.js
Travis Ralston d8a939df5d
Use & enforce snake_case naming convention on config.json settings (#8062)
* Document and support the established naming convention for config opts

This change:
* Rename `ConfigOptions` to `IConfigOptions` to match code convention/style, plus move it to a dedicated file
* Update comments and surrounding documentation
* Define every single documented option (from element-web's config.md)
* Enable a linter to enforce the convention
* Invent a translation layer for a different change to use
* No attempt to fix build errors from doing this (at this stage)

* Add demo of lint rule in action

* Fix all obvious instances of SdkConfig case conflicts

* Fix tests to use SdkConfig directly

* Add docs to make unset() calling safer

* Appease the linter

* Update documentation to match snake_case_config

* Fix more instances of square brackets off SdkConfig
2022-03-18 10:12:36 -06:00

105 lines
3.2 KiB
JavaScript

/*
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';
import { createClient } from 'matrix-js-sdk/src/matrix';
import sdk from '../../../skinned-sdk';
import SdkConfig, { DEFAULTS } from '../../../../src/SdkConfig';
import { createTestClient, mkServerConfig } from "../../../test-utils";
jest.mock('matrix-js-sdk/src/matrix');
jest.useFakeTimers();
const Registration = sdk.getComponent(
'structures.auth.Registration',
);
describe('Registration', function() {
let parentDiv;
beforeEach(function() {
SdkConfig.put({
...DEFAULTS,
disable_custom_urls: true,
});
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
createClient.mockImplementation(() => createTestClient());
});
afterEach(function() {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
SdkConfig.unset(); // we touch the config, so clean up
});
function render() {
return ReactDOM.render(<Registration
serverConfig={mkServerConfig("https://matrix.org", "https://vector.im")}
makeRegistrationUrl={() => {}}
onLoggedIn={() => {}}
onLoginClick={() => {}}
onServerConfigChange={() => {}}
/>, parentDiv);
}
it('should show server picker', async function() {
const root = render();
const selector = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_ServerPicker");
expect(selector).toBeTruthy();
});
it('should show form when custom URLs disabled', async function() {
const root = render();
// Set non-empty flows & matrixClient to get past the loading spinner
root.setState({
flows: [{
stages: [],
}],
matrixClient: {},
busy: false,
});
const form = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.RegistrationForm'),
);
expect(form).toBeTruthy();
});
it("should show SSO options if those are available", async () => {
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();
});
});