Skip to content

Commit fc5c93a

Browse files
committed
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.
1 parent a5092dc commit fc5c93a

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎test/app-tests/joining.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const ReactDOM = require('react-dom');
3737
const ReactTestUtils = require('react-addons-test-utils');
3838
const expect = require('expect');
3939
import Promise from 'bluebird';
40+
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
41+
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
4042

4143
const test_utils = require('../test-utils');
4244
const MockHttpBackend = require('matrix-mock-request');
@@ -97,17 +99,19 @@ describe('joining a room', function() {
9799
PlatformPeg.set(new WebPlatform());
98100

99101
const config = {
100-
validated_server_config: {
102+
validated_server_config: makeType(ValidatedServerConfig, {
101103
hsUrl: HS_URL,
102104
hsName: "TEST_ENVIRONMENT",
103105
hsNameIsDifferent: false, // yes, we lie
104106
isUrl: IS_URL,
105107
identityEnabled: true,
106-
},
108+
}),
107109
};
108110

109111
const mc = (
110-
<MatrixChat config={config}
112+
<MatrixChat
113+
config={config}
114+
serverConfig={config.validated_server_config}
111115
makeRegistrationUrl={()=>{throw new Error("unimplemented");}}
112116
initialScreenAfterLogin={{
113117
screen: 'directory',

‎test/app-tests/loading.js‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import dis from 'matrix-react-sdk/lib/dispatcher';
3939
import * as test_utils from '../test-utils';
4040
import MockHttpBackend from 'matrix-mock-request';
4141
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
42+
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
43+
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
4244

4345
const DEFAULT_HS_URL='http://my_server';
4446
const DEFAULT_IS_URL='http://my_is';
@@ -146,13 +148,13 @@ describe('loading:', function() {
146148
const config = Object.assign({
147149
default_hs_url: DEFAULT_HS_URL,
148150
default_is_url: DEFAULT_IS_URL,
149-
validated_server_config: {
151+
validated_server_config: makeType(ValidatedServerConfig, {
150152
hsUrl: DEFAULT_HS_URL,
151153
hsName: "TEST_ENVIRONMENT",
152154
hsNameIsDifferent: false, // yes, we lie
153155
isUrl: DEFAULT_IS_URL,
154156
identityEnabled: true,
155-
},
157+
}),
156158
embeddedPages: {
157159
homeUrl: 'data:text/html;charset=utf-8;base64,PGh0bWw+PC9odG1sPg==',
158160
},
@@ -167,6 +169,7 @@ describe('loading:', function() {
167169
<MatrixChat
168170
onNewScreen={onNewScreen}
169171
config={config}
172+
serverConfig={config.validated_server_config}
170173
realQueryParams={params}
171174
startingFragmentQueryParams={fragParts.params}
172175
enableGuest={true}
@@ -623,11 +626,21 @@ describe('loading:', function() {
623626

624627
// check that we have a Login component, send a 'user:pass' login,
625628
// and await the HTTP requests.
626-
function completeLogin(matrixChat) {
629+
async function completeLogin(matrixChat) {
627630
// we expect a single <Login> component
628631
const login = ReactTestUtils.findRenderedComponentWithType(
629632
matrixChat, sdk.getComponent('structures.auth.Login'));
630633

634+
// When we switch to the login component, it'll hit the login endpoint
635+
// for proof of life and to get flows. We'll only give it one option.
636+
httpBackend.when('GET', '/login')
637+
.respond(200, {"flows": [{"type": "m.login.password"}]});
638+
httpBackend.flush(); // We already would have tried the GET /login request
639+
640+
// Give the component some time to finish processing the login flows before
641+
// continuing.
642+
await Promise.delay(100);
643+
631644
httpBackend.when('POST', '/login').check(function(req) {
632645
expect(req.data.type).toEqual('m.login.password');
633646
expect(req.data.identifier.type).toEqual('m.id.user');

0 commit comments

Comments
 (0)