30 test failures to go :D
This commit is contained in:
parent
ffa2ac172c
commit
6ad31fe023
33 changed files with 424 additions and 709 deletions
|
@ -1,6 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
import sinon from 'sinon';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import peg from '../src/MatrixClientPeg';
|
||||
|
@ -27,8 +26,6 @@ export function getRenderer() {
|
|||
* @returns {sinon.Sandbox}; remember to call sandbox.restore afterwards.
|
||||
*/
|
||||
export function stubClient() {
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
||||
const client = createTestClient();
|
||||
|
||||
// stub out the methods in MatrixClientPeg
|
||||
|
@ -37,12 +34,11 @@ export function stubClient() {
|
|||
// so we do this for each method
|
||||
const methods = ['get', 'unset', 'replaceUsingCreds'];
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
sandbox.stub(peg, methods[i]);
|
||||
peg[methods[i]] = jest.spyOn(peg, methods[i]);
|
||||
}
|
||||
// MatrixClientPeg.get() is called a /lot/, so implement it with our own
|
||||
// fast stub function rather than a sinon stub
|
||||
peg.get = function() { return client; };
|
||||
return sandbox;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,27 +48,27 @@ export function stubClient() {
|
|||
*/
|
||||
export function createTestClient() {
|
||||
return {
|
||||
getHomeserverUrl: sinon.stub(),
|
||||
getIdentityServerUrl: sinon.stub(),
|
||||
getDomain: sinon.stub().returns("matrix.rog"),
|
||||
getUserId: sinon.stub().returns("@userId:matrix.rog"),
|
||||
getHomeserverUrl: jest.fn(),
|
||||
getIdentityServerUrl: jest.fn(),
|
||||
getDomain: jest.fn().mockReturnValue("matrix.rog"),
|
||||
getUserId: jest.fn().mockReturnValue("@userId:matrix.rog"),
|
||||
|
||||
getPushActionsForEvent: sinon.stub(),
|
||||
getRoom: sinon.stub().returns(mkStubRoom()),
|
||||
getRooms: sinon.stub().returns([]),
|
||||
getVisibleRooms: sinon.stub().returns([]),
|
||||
getGroups: sinon.stub().returns([]),
|
||||
loginFlows: sinon.stub(),
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
isRoomEncrypted: sinon.stub().returns(false),
|
||||
peekInRoom: sinon.stub().returns(Promise.resolve(mkStubRoom())),
|
||||
getPushActionsForEvent: jest.fn(),
|
||||
getRoom: jest.fn().mockReturnValue(mkStubRoom()),
|
||||
getRooms: jest.fn().mockReturnValue([]),
|
||||
getVisibleRooms: jest.fn().mockReturnValue([]),
|
||||
getGroups: jest.fn().mockReturnValue([]),
|
||||
loginFlows: jest.fn(),
|
||||
on: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
isRoomEncrypted: jest.fn().mockReturnValue(false),
|
||||
peekInRoom: jest.fn().mockResolvedValue(mkStubRoom()),
|
||||
|
||||
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({})),
|
||||
paginateEventTimeline: jest.fn().mockResolvedValue(undefined),
|
||||
sendReadReceipt: jest.fn().mockResolvedValue(undefined),
|
||||
getRoomIdForAlias: jest.fn().mockResolvedValue(undefined),
|
||||
getRoomDirectoryVisibility: jest.fn().mockResolvedValue(undefined),
|
||||
getProfileInfo: jest.fn().mockResolvedValue({}),
|
||||
getAccountData: (type) => {
|
||||
return mkEvent({
|
||||
type,
|
||||
|
@ -81,9 +77,9 @@ export function createTestClient() {
|
|||
});
|
||||
},
|
||||
mxcUrlToHttp: (mxc) => 'http://this.is.a.url/',
|
||||
setAccountData: sinon.stub(),
|
||||
sendTyping: sinon.stub().returns(Promise.resolve({})),
|
||||
sendMessage: () => Promise.resolve({}),
|
||||
setAccountData: jest.fn(),
|
||||
sendTyping: jest.fn().mockResolvedValue({}),
|
||||
sendMessage: () => jest.fn().mockResolvedValue({}),
|
||||
getSyncState: () => "SYNCING",
|
||||
generateClientSecret: () => "t35tcl1Ent5ECr3T",
|
||||
isGuest: () => false,
|
||||
|
@ -214,15 +210,15 @@ export function mkStubRoom(roomId = null) {
|
|||
const stubTimeline = { getEvents: () => [] };
|
||||
return {
|
||||
roomId,
|
||||
getReceiptsForEvent: sinon.stub().returns([]),
|
||||
getMember: sinon.stub().returns({
|
||||
getReceiptsForEvent: jest.fn().mockReturnValue([]),
|
||||
getMember: jest.fn().mockReturnValue({
|
||||
userId: '@member:domain.bla',
|
||||
name: 'Member',
|
||||
roomId: roomId,
|
||||
getAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||
}),
|
||||
getMembersWithMembership: sinon.stub().returns([]),
|
||||
getJoinedMembers: sinon.stub().returns([]),
|
||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||
getJoinedMembers: jest.fn().mockReturnValue([]),
|
||||
getPendingEvents: () => [],
|
||||
getLiveTimeline: () => stubTimeline,
|
||||
getUnfilteredTimelineSet: () => null,
|
||||
|
@ -231,12 +227,12 @@ export function mkStubRoom(roomId = null) {
|
|||
getVersion: () => '1',
|
||||
shouldUpgradeToVersion: () => null,
|
||||
getMyMembership: () => "join",
|
||||
maySendMessage: sinon.stub().returns(true),
|
||||
maySendMessage: jest.fn().mockReturnValue(true),
|
||||
currentState: {
|
||||
getStateEvents: sinon.stub(),
|
||||
mayClientSendStateEvent: sinon.stub().returns(true),
|
||||
maySendStateEvent: sinon.stub().returns(true),
|
||||
maySendEvent: sinon.stub().returns(true),
|
||||
getStateEvents: jest.fn(),
|
||||
mayClientSendStateEvent: jest.fn().mockReturnValue(true),
|
||||
maySendStateEvent: jest.fn().mockReturnValue(true),
|
||||
maySendEvent: jest.fn().mockReturnValue(true),
|
||||
members: [],
|
||||
},
|
||||
tags: {
|
||||
|
@ -244,9 +240,9 @@ export function mkStubRoom(roomId = null) {
|
|||
order: 0.5,
|
||||
},
|
||||
},
|
||||
setBlacklistUnverifiedDevices: sinon.stub(),
|
||||
on: sinon.stub(),
|
||||
removeListener: sinon.stub(),
|
||||
setBlacklistUnverifiedDevices: jest.fn(),
|
||||
on: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -295,7 +291,7 @@ export function wrapInMatrixClientContext(WrappedComponent) {
|
|||
/**
|
||||
* Call fn before calling componentDidUpdate on a react component instance, inst.
|
||||
* @param {React.Component} inst an instance of a React component.
|
||||
* @param {integer} updates Number of updates to wait for. (Defaults to 1.)
|
||||
* @param {number} updates Number of updates to wait for. (Defaults to 1.)
|
||||
* @returns {Promise} promise that resolves when componentDidUpdate is called on
|
||||
* given component instance.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue