forked from matrix/element-web
Fix unit tests for new login
Supply a server config to the component and adjust the wait logic to be less of a race. The Login component will noop onPasswordLogin if it is "busy", and it is busy when it requests the login flows.
This commit is contained in:
parent
a5092dc763
commit
fc5c93ab5f
|
@ -37,6 +37,8 @@ const ReactDOM = require('react-dom');
|
||||||
const ReactTestUtils = require('react-addons-test-utils');
|
const ReactTestUtils = require('react-addons-test-utils');
|
||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
|
||||||
|
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
|
||||||
|
|
||||||
const test_utils = require('../test-utils');
|
const test_utils = require('../test-utils');
|
||||||
const MockHttpBackend = require('matrix-mock-request');
|
const MockHttpBackend = require('matrix-mock-request');
|
||||||
|
@ -97,17 +99,19 @@ describe('joining a room', function() {
|
||||||
PlatformPeg.set(new WebPlatform());
|
PlatformPeg.set(new WebPlatform());
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
validated_server_config: {
|
validated_server_config: makeType(ValidatedServerConfig, {
|
||||||
hsUrl: HS_URL,
|
hsUrl: HS_URL,
|
||||||
hsName: "TEST_ENVIRONMENT",
|
hsName: "TEST_ENVIRONMENT",
|
||||||
hsNameIsDifferent: false, // yes, we lie
|
hsNameIsDifferent: false, // yes, we lie
|
||||||
isUrl: IS_URL,
|
isUrl: IS_URL,
|
||||||
identityEnabled: true,
|
identityEnabled: true,
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mc = (
|
const mc = (
|
||||||
<MatrixChat config={config}
|
<MatrixChat
|
||||||
|
config={config}
|
||||||
|
serverConfig={config.validated_server_config}
|
||||||
makeRegistrationUrl={()=>{throw new Error("unimplemented");}}
|
makeRegistrationUrl={()=>{throw new Error("unimplemented");}}
|
||||||
initialScreenAfterLogin={{
|
initialScreenAfterLogin={{
|
||||||
screen: 'directory',
|
screen: 'directory',
|
||||||
|
|
|
@ -39,6 +39,8 @@ import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||||
import * as test_utils from '../test-utils';
|
import * as test_utils from '../test-utils';
|
||||||
import MockHttpBackend from 'matrix-mock-request';
|
import MockHttpBackend from 'matrix-mock-request';
|
||||||
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
|
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
|
||||||
|
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
|
||||||
|
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
|
||||||
|
|
||||||
const DEFAULT_HS_URL='http://my_server';
|
const DEFAULT_HS_URL='http://my_server';
|
||||||
const DEFAULT_IS_URL='http://my_is';
|
const DEFAULT_IS_URL='http://my_is';
|
||||||
|
@ -146,13 +148,13 @@ describe('loading:', function() {
|
||||||
const config = Object.assign({
|
const config = Object.assign({
|
||||||
default_hs_url: DEFAULT_HS_URL,
|
default_hs_url: DEFAULT_HS_URL,
|
||||||
default_is_url: DEFAULT_IS_URL,
|
default_is_url: DEFAULT_IS_URL,
|
||||||
validated_server_config: {
|
validated_server_config: makeType(ValidatedServerConfig, {
|
||||||
hsUrl: DEFAULT_HS_URL,
|
hsUrl: DEFAULT_HS_URL,
|
||||||
hsName: "TEST_ENVIRONMENT",
|
hsName: "TEST_ENVIRONMENT",
|
||||||
hsNameIsDifferent: false, // yes, we lie
|
hsNameIsDifferent: false, // yes, we lie
|
||||||
isUrl: DEFAULT_IS_URL,
|
isUrl: DEFAULT_IS_URL,
|
||||||
identityEnabled: true,
|
identityEnabled: true,
|
||||||
},
|
}),
|
||||||
embeddedPages: {
|
embeddedPages: {
|
||||||
homeUrl: 'data:text/html;charset=utf-8;base64,PGh0bWw+PC9odG1sPg==',
|
homeUrl: 'data:text/html;charset=utf-8;base64,PGh0bWw+PC9odG1sPg==',
|
||||||
},
|
},
|
||||||
|
@ -167,6 +169,7 @@ describe('loading:', function() {
|
||||||
<MatrixChat
|
<MatrixChat
|
||||||
onNewScreen={onNewScreen}
|
onNewScreen={onNewScreen}
|
||||||
config={config}
|
config={config}
|
||||||
|
serverConfig={config.validated_server_config}
|
||||||
realQueryParams={params}
|
realQueryParams={params}
|
||||||
startingFragmentQueryParams={fragParts.params}
|
startingFragmentQueryParams={fragParts.params}
|
||||||
enableGuest={true}
|
enableGuest={true}
|
||||||
|
@ -623,11 +626,21 @@ describe('loading:', function() {
|
||||||
|
|
||||||
// check that we have a Login component, send a 'user:pass' login,
|
// check that we have a Login component, send a 'user:pass' login,
|
||||||
// and await the HTTP requests.
|
// and await the HTTP requests.
|
||||||
function completeLogin(matrixChat) {
|
async function completeLogin(matrixChat) {
|
||||||
// we expect a single <Login> component
|
// we expect a single <Login> component
|
||||||
const login = ReactTestUtils.findRenderedComponentWithType(
|
const login = ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login'));
|
matrixChat, sdk.getComponent('structures.auth.Login'));
|
||||||
|
|
||||||
|
// When we switch to the login component, it'll hit the login endpoint
|
||||||
|
// for proof of life and to get flows. We'll only give it one option.
|
||||||
|
httpBackend.when('GET', '/login')
|
||||||
|
.respond(200, {"flows": [{"type": "m.login.password"}]});
|
||||||
|
httpBackend.flush(); // We already would have tried the GET /login request
|
||||||
|
|
||||||
|
// Give the component some time to finish processing the login flows before
|
||||||
|
// continuing.
|
||||||
|
await Promise.delay(100);
|
||||||
|
|
||||||
httpBackend.when('POST', '/login').check(function(req) {
|
httpBackend.when('POST', '/login').check(function(req) {
|
||||||
expect(req.data.type).toEqual('m.login.password');
|
expect(req.data.type).toEqual('m.login.password');
|
||||||
expect(req.data.identifier.type).toEqual('m.id.user');
|
expect(req.data.identifier.type).toEqual('m.id.user');
|
||||||
|
|
Loading…
Reference in New Issue