Some basic tests for RoomView

This commit is contained in:
David Baker 2016-06-17 12:20:26 +01:00
parent 624e34c48a
commit 1fbf027a40
3 changed files with 84 additions and 1 deletions

View File

@ -0,0 +1,66 @@
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;
beforeEach(function() {
sandbox = test_utils.stubClient();
this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel');
Skinner.addComponent('structures.TimelinePanel', stubComponent());
Skinner.addComponent('views.rooms.RoomHeader', stubComponent());
peg.get().credentials = { userId: "@test:example.com" };
});
afterEach(function() {
sandbox.restore();
Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel);
});
it('resolves a room alias to a room id', function (done) {
peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"}));
var onRoomIdResolved = sinon.spy();
var parentDiv = document.createElement('div');
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
process.nextTick(function() {
expect(onRoomIdResolved.called).toExist();
ReactDOM.unmountComponentAtNode(parentDiv);
done();
});
});
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 parentDiv = document.createElement('div');
var roomView = ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" />, parentDiv);
peg.get().joinRoom = sinon.spy();
process.nextTick(function() {
roomView.onJoinButtonClicked();
process.nextTick(function() {
expect(peg.get().joinRoom.calledWith('#alias:ser.ver')).toExist();
ReactDOM.unmountComponentAtNode(parentDiv);
done();
});
});
});
});

View File

@ -22,6 +22,7 @@ var components = skin.components;
components['structures.LeftPanel'] = stubComponent();
components['structures.RightPanel'] = stubComponent();
components['structures.RoomDirectory'] = stubComponent();
components['rooms.SearchBar'] = stubComponent();
components['views.globals.MatrixToolbar'] = stubComponent();
components['views.globals.GuestWarningBar'] = stubComponent();
components['views.globals.NewVersionBar'] = stubComponent();

View File

@ -34,13 +34,16 @@ module.exports.stubClient = function() {
getIdentityServerUrl: sinon.stub(),
getPushActionsForEvent: sinon.stub(),
getRoom: sinon.stub(),
getRoom: sinon.stub().returns(this.mkStubRoom()),
getRooms: sinon.stub().returns([]),
loginFlows: sinon.stub(),
on: sinon.stub(),
removeListener: sinon.stub(),
paginateEventTimeline: sinon.stub().returns(q()),
sendReadReceipt: sinon.stub().returns(q()),
getRoomIdForAlias: sinon.stub().returns(q()),
getProfileInfo: sinon.stub().returns(q({})),
};
// stub out the methods in MatrixClientPeg
@ -169,3 +172,16 @@ module.exports.mkMessage = function(opts) {
};
return module.exports.mkEvent(opts);
};
module.exports.mkStubRoom = function() {
return {
getReceiptsForEvent: sinon.stub().returns([]),
getMember: sinon.stub().returns({}),
getJoinedMembers: sinon.stub().returns([]),
currentState: {
getStateEvents: sinon.stub(),
members: [],
},
};
};