mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Merge pull request #313 from matrix-org/dbkr/roomview_tests
Some basic tests for RoomView
This commit is contained in:
commit
aa67e33744
3 changed files with 91 additions and 1 deletions
73
test/components/structures/RoomView-test.js
Normal file
73
test/components/structures/RoomView-test.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
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;
|
||||
var parentDiv;
|
||||
|
||||
beforeEach(function() {
|
||||
sandbox = test_utils.stubClient();
|
||||
parentDiv = document.createElement('div');
|
||||
|
||||
this.oldTimelinePanel = Skinner.getComponent('structures.TimelinePanel');
|
||||
this.oldRoomHeader = Skinner.getComponent('views.rooms.RoomHeader');
|
||||
Skinner.addComponent('structures.TimelinePanel', stubComponent());
|
||||
Skinner.addComponent('views.rooms.RoomHeader', stubComponent());
|
||||
|
||||
peg.get().credentials = { userId: "@test:example.com" };
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
sandbox.restore();
|
||||
|
||||
ReactDOM.unmountComponentAtNode(parentDiv);
|
||||
|
||||
Skinner.addComponent('structures.TimelinePanel', this.oldTimelinePanel);
|
||||
Skinner.addComponent('views.rooms.RoomHeader', this.oldRoomHeader);
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
ReactDOM.render(<RoomView roomAddress="#alias:ser.ver" onRoomIdResolved={onRoomIdResolved} />, parentDiv);
|
||||
|
||||
process.nextTick(function() {
|
||||
// These expect()s don't read very well and don't give very good failure
|
||||
// messages, but expect's toHaveBeenCalled only takes an expect spy object,
|
||||
// not a sinon spy object.
|
||||
expect(onRoomIdResolved.called).toExist();
|
||||
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();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -29,6 +29,7 @@ components['views.elements.Spinner'] = stubComponent({displayName: 'Spinner'});
|
|||
components['views.messages.DateSeparator'] = stubComponent({displayName: 'DateSeparator'});
|
||||
components['views.messages.MessageTimestamp'] = stubComponent({displayName: 'MessageTimestamp'});
|
||||
components['views.messages.SenderProfile'] = stubComponent({displayName: 'SenderProfile'});
|
||||
components['views.rooms.SearchBar'] = stubComponent();
|
||||
|
||||
sdk.loadSkin(skin);
|
||||
|
||||
|
|
|
@ -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: [],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue