2016-06-17 13:20:26 +02:00
|
|
|
var React = require('react');
|
|
|
|
var expect = require('expect');
|
|
|
|
var sinon = require('sinon');
|
|
|
|
var ReactDOM = require("react-dom");
|
|
|
|
|
|
|
|
var sdk = require('matrix-react-sdk');
|
|
|
|
var RoomView = sdk.getComponent('structures.RoomView');
|
|
|
|
var peg = require('../../../src/MatrixClientPeg');
|
|
|
|
|
|
|
|
var test_utils = require('../../test-utils');
|
|
|
|
var q = require('q');
|
|
|
|
|
|
|
|
var Skinner = require("../../../src/Skinner");
|
|
|
|
var stubComponent = require('../../components/stub-component.js');
|
|
|
|
|
|
|
|
describe('RoomView', function () {
|
|
|
|
var sandbox;
|
2016-06-17 16:50:13 +02:00
|
|
|
var parentDiv;
|
2016-06-17 13:20:26 +02:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2016-10-10 18:51:26 +02:00
|
|
|
test_utils.beforeEach(this);
|
2016-06-17 13:20:26 +02:00
|
|
|
sandbox = test_utils.stubClient();
|
2016-06-17 16:50:13 +02:00
|
|
|
parentDiv = document.createElement('div');
|
2016-06-17 13:20:26 +02:00
|
|
|
|
|
|
|
this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel');
|
2016-06-17 13:23:45 +02:00
|
|
|
this.oldRoomHeader = Skinner.getComponent('views.rooms.RoomHeader');
|
2016-06-17 13:20:26 +02:00
|
|
|
Skinner.addComponent('structures.TimelinePanel', stubComponent());
|
|
|
|
Skinner.addComponent('views.rooms.RoomHeader', stubComponent());
|
|
|
|
|
|
|
|
peg.get().credentials = { userId: "@test:example.com" };
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
sandbox.restore();
|
2016-06-17 16:50:13 +02:00
|
|
|
|
|
|
|
ReactDOM.unmountComponentAtNode(parentDiv);
|
|
|
|
|
2016-06-17 13:20:26 +02:00
|
|
|
Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel);
|
2016-06-17 13:23:45 +02:00
|
|
|
Skinner.addComponent('views.rooms.RoomHeader', this.oldRoomHeader);
|
2016-06-17 13:20:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('resolves a room alias to a room id', function (done) {
|
|
|
|
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
|
|
|
|
|
2017-01-31 23:40:53 +01:00
|
|
|
function onRoomIdResolved(room_id) {
|
|
|
|
expect(room_id).toEqual("!randomcharacters:aser.ver");
|
|
|
|
done();
|
|
|
|
}
|
2016-06-17 13:20:26 +02:00
|
|
|
|
|
|
|
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('joins by alias if given an alias', function (done) {
|
|
|
|
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
|
|
|
|
peg.get().getProfileInfo.returns(q({displayname: "foo"}));
|
|
|
|
var roomView = ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" />, parentDiv);
|
|
|
|
|
2016-12-08 19:44:38 +01:00
|
|
|
peg.get().joinRoom = function(x) {
|
|
|
|
expect(x).toEqual('#alias:ser.ver');
|
|
|
|
done();
|
2016-12-09 11:59:05 +01:00
|
|
|
};
|
2016-10-10 18:51:26 +02:00
|
|
|
|
2016-06-17 13:20:26 +02:00
|
|
|
process.nextTick(function() {
|
|
|
|
roomView.onJoinButtonClicked();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|