2016-04-13 11:15:04 +02:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* joining.js: tests for the various paths when joining a room */
|
|
|
|
|
|
|
|
require('skin-sdk');
|
|
|
|
|
|
|
|
var jssdk = require('matrix-js-sdk');
|
|
|
|
|
|
|
|
var sdk = require('matrix-react-sdk');
|
|
|
|
var peg = require('matrix-react-sdk/lib/MatrixClientPeg');
|
|
|
|
var dis = require('matrix-react-sdk/lib/dispatcher');
|
2017-03-29 17:07:11 +02:00
|
|
|
var PageTypes = require('matrix-react-sdk/lib/PageTypes');
|
2016-04-13 11:15:04 +02:00
|
|
|
var MatrixChat = sdk.getComponent('structures.MatrixChat');
|
|
|
|
var RoomDirectory = sdk.getComponent('structures.RoomDirectory');
|
|
|
|
var RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar');
|
|
|
|
var RoomView = sdk.getComponent('structures.RoomView');
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
var ReactDOM = require('react-dom');
|
|
|
|
var ReactTestUtils = require('react-addons-test-utils');
|
|
|
|
var expect = require('expect');
|
2017-07-13 01:48:31 +02:00
|
|
|
import Promise from 'bluebird';
|
2016-04-13 11:15:04 +02:00
|
|
|
|
|
|
|
var test_utils = require('../test-utils');
|
2017-07-04 16:25:09 +02:00
|
|
|
var MockHttpBackend = require('matrix-mock-request');
|
2016-04-13 11:15:04 +02:00
|
|
|
|
|
|
|
var HS_URL='http://localhost';
|
|
|
|
var IS_URL='http://localhost';
|
|
|
|
var USER_ID='@me:localhost';
|
|
|
|
var ACCESS_TOKEN='access_token';
|
|
|
|
|
|
|
|
describe('joining a room', function () {
|
|
|
|
describe('over federation', function () {
|
|
|
|
var parentDiv;
|
|
|
|
var httpBackend;
|
|
|
|
var matrixChat;
|
2016-08-10 23:39:53 +02:00
|
|
|
|
2016-04-13 11:15:04 +02:00
|
|
|
beforeEach(function() {
|
|
|
|
test_utils.beforeEach(this);
|
|
|
|
httpBackend = new MockHttpBackend();
|
|
|
|
jssdk.request(httpBackend.requestFn);
|
|
|
|
parentDiv = document.createElement('div');
|
2016-04-13 12:16:38 +02:00
|
|
|
|
|
|
|
// uncomment this to actually add the div to the UI, to help with
|
|
|
|
// debugging (but slow things down)
|
|
|
|
// document.body.appendChild(parentDiv);
|
2016-04-13 11:15:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
if (parentDiv) {
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
2016-04-13 12:16:38 +02:00
|
|
|
parentDiv.remove();
|
2016-04-13 11:15:04 +02:00
|
|
|
parentDiv = null;
|
|
|
|
}
|
|
|
|
});
|
2016-08-10 23:39:53 +02:00
|
|
|
|
2017-06-14 17:07:40 +02:00
|
|
|
it('should not get stuck at a spinner', function() {
|
2016-04-13 11:15:04 +02:00
|
|
|
var ROOM_ALIAS = '#alias:localhost';
|
|
|
|
var ROOM_ID = '!id:localhost';
|
2016-08-10 23:39:53 +02:00
|
|
|
|
2016-04-13 11:15:04 +02:00
|
|
|
httpBackend.when('GET', '/pushrules').respond(200, {});
|
|
|
|
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' });
|
2017-04-18 14:45:31 +02:00
|
|
|
|
|
|
|
// note that we deliberately do *not* set an expectation for a
|
|
|
|
// presence update - setting one makes the first httpBackend.flush
|
|
|
|
// return before the first /sync arrives.
|
2016-04-13 11:15:04 +02:00
|
|
|
|
|
|
|
// start with a logged-in client
|
2016-08-10 23:39:53 +02:00
|
|
|
localStorage.setItem("mx_hs_url", HS_URL );
|
|
|
|
localStorage.setItem("mx_is_url", IS_URL );
|
|
|
|
localStorage.setItem("mx_access_token", ACCESS_TOKEN );
|
|
|
|
localStorage.setItem("mx_user_id", USER_ID);
|
|
|
|
|
2017-05-18 14:39:33 +02:00
|
|
|
var mc = (
|
|
|
|
<MatrixChat config={{}}
|
|
|
|
makeRegistrationUrl={()=>{throw new Error("unimplemented");}}
|
2017-06-05 21:16:44 +02:00
|
|
|
initialScreenAfterLogin={{
|
|
|
|
screen: 'directory',
|
|
|
|
}}
|
2017-05-18 14:39:33 +02:00
|
|
|
/>
|
|
|
|
);
|
2016-04-13 11:15:04 +02:00
|
|
|
matrixChat = ReactDOM.render(mc, parentDiv);
|
|
|
|
|
|
|
|
var roomView;
|
2017-04-18 14:45:31 +02:00
|
|
|
|
2017-05-18 14:39:33 +02:00
|
|
|
// wait for /sync to happen. This may take some time, as the client
|
|
|
|
// has to initialise indexeddb.
|
|
|
|
console.log("waiting for /sync");
|
|
|
|
httpBackend.when('GET', '/sync')
|
|
|
|
.respond(200, {});
|
|
|
|
|
2017-07-14 17:14:42 +02:00
|
|
|
return httpBackend.flushAllExpected({
|
|
|
|
timeout: 1000,
|
|
|
|
}).then(() => {
|
2017-04-18 14:45:31 +02:00
|
|
|
// wait for the directory requests
|
|
|
|
httpBackend.when('POST', '/publicRooms').respond(200, {chunk: []});
|
|
|
|
httpBackend.when('GET', '/thirdparty/protocols').respond(200, {});
|
2017-07-13 14:23:10 +02:00
|
|
|
return httpBackend.flushAllExpected();
|
2017-02-17 15:32:08 +01:00
|
|
|
}).then(() => {
|
2017-07-13 14:23:10 +02:00
|
|
|
console.log(`${Date.now()} App made requests for directory view; switching to a room.`);
|
|
|
|
|
2016-04-13 11:15:04 +02:00
|
|
|
var roomDir = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
matrixChat, RoomDirectory);
|
|
|
|
|
|
|
|
// enter an alias in the input, and simulate enter
|
|
|
|
var input = ReactTestUtils.findRenderedDOMComponentWithTag(
|
|
|
|
roomDir, 'input');
|
|
|
|
input.value = ROOM_ALIAS;
|
2016-09-23 18:18:52 +02:00
|
|
|
ReactTestUtils.Simulate.change(input);
|
2016-04-13 11:15:04 +02:00
|
|
|
ReactTestUtils.Simulate.keyUp(input, {key: 'Enter'});
|
|
|
|
|
|
|
|
// that should create a roomview which will start a peek; wait
|
|
|
|
// for the peek.
|
2017-04-18 14:45:31 +02:00
|
|
|
httpBackend.when('GET', '/directory/room/'+encodeURIComponent(ROOM_ALIAS)).respond(200, { room_id: ROOM_ID });
|
2016-06-17 18:49:11 +02:00
|
|
|
httpBackend.when('GET', '/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync")
|
2016-04-13 11:15:04 +02:00
|
|
|
.respond(401, {errcode: 'M_GUEST_ACCESS_FORBIDDEN'});
|
2017-06-05 21:16:44 +02:00
|
|
|
|
2017-07-13 14:23:10 +02:00
|
|
|
return httpBackend.flushAllExpected();
|
2016-04-13 11:15:04 +02:00
|
|
|
}).then(() => {
|
2017-07-13 14:23:10 +02:00
|
|
|
console.log(`${Date.now()} App made room preview request`);
|
2016-04-13 11:15:04 +02:00
|
|
|
|
2017-07-13 14:23:10 +02:00
|
|
|
// we should now have a roomview
|
2016-04-13 11:15:04 +02:00
|
|
|
roomView = ReactTestUtils.findRenderedComponentWithType(
|
|
|
|
matrixChat, RoomView);
|
|
|
|
|
2017-07-13 14:23:10 +02:00
|
|
|
// the preview bar may take a tick to be displayed
|
|
|
|
return Promise.delay(1);
|
|
|
|
}).then(() => {
|
2017-06-05 21:16:44 +02:00
|
|
|
const previewBar = ReactTestUtils.findRenderedComponentWithType(
|
2016-04-13 11:15:04 +02:00
|
|
|
roomView, RoomPreviewBar);
|
|
|
|
|
2017-06-05 21:16:44 +02:00
|
|
|
const joinLink = ReactTestUtils.findRenderedDOMComponentWithTag(
|
2016-04-13 11:15:04 +02:00
|
|
|
previewBar, 'a');
|
|
|
|
|
|
|
|
ReactTestUtils.Simulate.click(joinLink);
|
|
|
|
|
2017-06-08 19:01:55 +02:00
|
|
|
httpBackend.when('POST', '/join/'+encodeURIComponent(ROOM_ALIAS))
|
2016-04-13 11:15:04 +02:00
|
|
|
.respond(200, {room_id: ROOM_ID});
|
2016-12-16 16:20:52 +01:00
|
|
|
}).then(() => {
|
|
|
|
// wait for the join request to be made
|
2017-07-13 01:33:28 +02:00
|
|
|
return Promise.delay(1);
|
2017-06-06 16:59:24 +02:00
|
|
|
}).then(() => {
|
|
|
|
// and again, because the state update has to go to the store and
|
|
|
|
// then one dispatch within the store, then to the view
|
|
|
|
// XXX: This is *super flaky*: a better way would be to declare
|
|
|
|
// that we expect a certain state transition to happen, then wait
|
|
|
|
// for that transition to occur.
|
2017-07-13 01:33:28 +02:00
|
|
|
return Promise.delay(1);
|
2016-12-16 16:20:52 +01:00
|
|
|
}).then(() => {
|
2016-04-13 11:15:04 +02:00
|
|
|
// the roomview should now be loading
|
|
|
|
expect(roomView.state.room).toBe(null);
|
|
|
|
expect(roomView.state.joining).toBe(true);
|
|
|
|
|
|
|
|
// there should be a spinner
|
|
|
|
ReactTestUtils.findRenderedDOMComponentWithClass(
|
|
|
|
roomView, "mx_Spinner");
|
|
|
|
|
2017-06-05 21:16:44 +02:00
|
|
|
// flush it through
|
2017-06-08 19:01:55 +02:00
|
|
|
return httpBackend.flush('/join/'+encodeURIComponent(ROOM_ALIAS));
|
2017-06-05 21:16:44 +02:00
|
|
|
}).then(() => {
|
|
|
|
httpBackend.verifyNoOutstandingExpectation();
|
|
|
|
|
2017-07-13 01:33:28 +02:00
|
|
|
return Promise.delay(1);
|
2017-06-06 16:59:24 +02:00
|
|
|
}).then(() => {
|
2017-09-19 11:23:12 +02:00
|
|
|
// NB. we don't expect the 'joining' flag to reset at any point:
|
|
|
|
// it will stay set and we observe whether we have Room object for
|
|
|
|
// the room and whether our member event shows we're joined.
|
|
|
|
|
2016-04-13 11:15:04 +02:00
|
|
|
// now send the room down the /sync pipe
|
|
|
|
httpBackend.when('GET', '/sync').
|
|
|
|
respond(200, {
|
|
|
|
rooms: {
|
|
|
|
join: {
|
|
|
|
[ROOM_ID]: {
|
|
|
|
state: {},
|
|
|
|
timeline: {
|
|
|
|
events: [],
|
|
|
|
limited: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return httpBackend.flush();
|
|
|
|
}).then(() => {
|
|
|
|
// now the room should have loaded
|
|
|
|
expect(roomView.state.room).toExist();
|
2017-06-14 17:07:40 +02:00
|
|
|
});
|
2016-04-13 11:15:04 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|