Add tests for RoomSettings

For setting:
 - name
 - topic
 - history visibility
 - power levels

Testing RoomSettings required more stubbing on the matrix client.

The power level tests should be failing at this commit, with
fixes being made in upcoming commits.

Some tests are marked as known failures that we should fix but
aren't necessarily bugs:
 - SettingStore.setValue is used when saving despite the user not
   having made a change.
 - Testing directory publicity changes cannot be tested because we
   update state asynchronously in componentWillMount (which we do
   not block on in beforeEach).

Also, we needed to use `export default` to make sure everything
uses the same client peg and client.
This commit is contained in:
Luke Barnard 2018-02-28 14:52:53 +00:00
parent 3552800d19
commit d91d1932f4
3 changed files with 206 additions and 2 deletions

View file

@ -68,6 +68,8 @@ export function createTestClient() {
return {
getHomeserverUrl: sinon.stub(),
getIdentityServerUrl: sinon.stub(),
getDomain: sinon.stub().returns("matrix.rog"),
getUserId: sinon.stub().returns("@userId:matrix.rog"),
getPushActionsForEvent: sinon.stub(),
getRoom: sinon.stub().returns(mkStubRoom()),
@ -81,6 +83,7 @@ export function createTestClient() {
paginateEventTimeline: sinon.stub().returns(Promise.resolve()),
sendReadReceipt: sinon.stub().returns(Promise.resolve()),
getRoomIdForAlias: sinon.stub().returns(Promise.resolve()),
getRoomDirectoryVisibility: sinon.stub().returns(Promise.resolve()),
getProfileInfo: sinon.stub().returns(Promise.resolve({})),
getAccountData: (type) => {
return mkEvent({
@ -244,6 +247,7 @@ export function mkStubRoom(roomId = null) {
roomId: roomId,
getAvatarUrl: () => 'mxc://avatar.url/image.png',
}),
getMembersWithMembership: sinon.stub().returns([]),
getJoinedMembers: sinon.stub().returns([]),
getPendingEvents: () => [],
getLiveTimeline: () => stubTimeline,
@ -252,8 +256,16 @@ export function mkStubRoom(roomId = null) {
hasMembershipState: () => null,
currentState: {
getStateEvents: sinon.stub(),
mayClientSendStateEvent: sinon.stub().returns(true),
maySendStateEvent: sinon.stub().returns(true),
members: [],
},
tags: {
"m.favourite": {
order: 0.5,
},
},
setBlacklistUnverifiedDevices: sinon.stub(),
};
}
@ -284,7 +296,7 @@ export function wrapInMatrixClientContext(WrappedComponent) {
}
render() {
return <WrappedComponent {...this.props} />;
return <WrappedComponent ref={this.props.wrappedRef} {...this.props} />;
}
}
return Wrapper;