30 test failures to go :D

This commit is contained in:
Michael Telatynski 2019-12-16 11:12:48 +00:00
parent ffa2ac172c
commit 6ad31fe023
33 changed files with 424 additions and 709 deletions

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import { DecryptionFailure, DecryptionFailureTracker } from '../src/DecryptionFailureTracker';
import { MatrixEvent } from 'matrix-js-sdk';

View file

@ -11,7 +11,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import {phasedRollOutExpiredForUser} from '../src/PhasedRollOut';
const OFFSET = 6000000;

View file

@ -14,43 +14,41 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import ScalarAuthClient from '../src/ScalarAuthClient';
import MatrixClientPeg from '../src/MatrixClientPeg';
import { stubClient } from './test-utils';
describe('ScalarAuthClient', function() {
let clientSandbox;
beforeEach(function() {
sinon.stub(window.localStorage, 'getItem').withArgs('mx_scalar_token').returns('brokentoken');
clientSandbox = stubClient();
});
afterEach(function() {
clientSandbox.restore();
sinon.restore();
window.localStorage.getItem = jest.fn((arg) => {
if (arg === "mx_scalar_token") return "brokentoken";
});
stubClient();
});
it('should request a new token if the old one fails', async function() {
const sac = new ScalarAuthClient();
sac._getAccountName = sinon.stub();
sac._getAccountName.withArgs('brokentoken').rejects({
message: "Invalid token",
sac._getAccountName = jest.fn((arg) => {
switch (arg) {
case "brokentoken":
return Promise.reject({
message: "Invalid token",
});
case "wokentoken":
return Promise.resolve(MatrixClientPeg.get().getUserId());
}
});
sac._getAccountName.withArgs('wokentoken').resolves(MatrixClientPeg.get().getUserId());
MatrixClientPeg.get().getOpenIdToken = sinon.stub().resolves('this is your openid token');
MatrixClientPeg.get().getOpenIdToken = jest.fn().mockResolvedValue('this is your openid token');
sac.exchangeForScalarToken = sinon.stub().withArgs('this is your openid token').resolves('wokentoken');
sac.exchangeForScalarToken = jest.fn((arg) => {
if (arg === "this is your openid token") return Promise.resolve("wokentoken");
});
await sac.connect();
expect(sac.exchangeForScalarToken.calledWith('this is your openid token')).toBeTruthy();
expect(sac.exchangeForScalarToken).toBeCalledWith('this is your openid token');
expect(sac.scalarToken).toEqual('wokentoken');
});
});

View file

@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import * as Matrix from 'matrix-js-sdk';
import { startTermsFlow, Service } from '../src/Terms';
@ -44,107 +40,100 @@ const IM_SERVICE_ONE = new Service(Matrix.SERVICE_TYPES.IM, 'https://imone.test'
const IM_SERVICE_TWO = new Service(Matrix.SERVICE_TYPES.IM, 'https://imtwo.test', 'a token token');
describe('Terms', function() {
let sandbox;
beforeEach(function() {
sandbox = stubClient();
});
afterEach(function() {
sandbox.restore();
stubClient();
});
it('should prompt for all terms & services if no account data', async function() {
MatrixClientPeg.get().getAccountData = sinon.stub().returns(null);
MatrixClientPeg.get().getTerms = sinon.stub().returns({
MatrixClientPeg.get().getAccountData = jest.fn().mockReturnValue(null);
MatrixClientPeg.get().getTerms = jest.fn().mockReturnValue({
policies: {
"policy_the_first": POLICY_ONE,
},
});
const interactionCallback = sinon.stub().resolves([]);
const interactionCallback = jest.fn().mockResolvedValue([]);
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
console.log("interaction callback calls", interactionCallback.getCall(0));
console.log("interaction callback calls", interactionCallback.mock.calls[0]);
expect(interactionCallback.calledWith([
expect(interactionCallback).toBeCalledWith([
{
service: IM_SERVICE_ONE,
policies: {
policy_the_first: POLICY_ONE,
},
},
])).toBeTruthy();
], []);
});
it('should not prompt if all policies are signed in account data', async function() {
MatrixClientPeg.get().getAccountData = sinon.stub().returns({
getContent: sinon.stub().returns({
MatrixClientPeg.get().getAccountData = jest.fn().mockReturnValue({
getContent: jest.fn().mockReturnValue({
accepted: ["http://example.com/one"],
}),
});
MatrixClientPeg.get().getTerms = sinon.stub().returns({
MatrixClientPeg.get().getTerms = jest.fn().mockReturnValue({
policies: {
"policy_the_first": POLICY_ONE,
},
});
MatrixClientPeg.get().agreeToTerms = sinon.stub();
MatrixClientPeg.get().agreeToTerms = jest.fn();
const interactionCallback = sinon.spy();
const interactionCallback = jest.fn();
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.getCall(0).args);
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.mock.calls[0]);
expect(interactionCallback.called).toBeFalsy();
expect(MatrixClientPeg.get().agreeToTerms.calledWith(
expect(interactionCallback).not.toHaveBeenCalled();
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
Matrix.SERVICE_TYPES.IM,
'https://imone.test',
'a token token',
["http://example.com/one"],
)).toBeTruthy();
);
});
it("should prompt for only terms that aren't already signed", async function() {
MatrixClientPeg.get().getAccountData = sinon.stub().returns({
getContent: sinon.stub().returns({
MatrixClientPeg.get().getAccountData = jest.fn().mockReturnValue({
getContent: jest.fn().mockReturnValue({
accepted: ["http://example.com/one"],
}),
});
MatrixClientPeg.get().getTerms = sinon.stub().returns({
MatrixClientPeg.get().getTerms = jest.fn().mockReturnValue({
policies: {
"policy_the_first": POLICY_ONE,
"policy_the_second": POLICY_TWO,
},
});
MatrixClientPeg.get().agreeToTerms = sinon.stub();
MatrixClientPeg.get().agreeToTerms = jest.fn();
const interactionCallback = sinon.stub().resolves(["http://example.com/one", "http://example.com/two"]);
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
console.log("interactionCallback call", interactionCallback.getCall(0).args);
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.getCall(0).args);
console.log("interactionCallback call", interactionCallback.mock.calls[0]);
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.mock.calls[0]);
expect(interactionCallback.calledWith([
expect(interactionCallback).toBeCalledWith([
{
service: IM_SERVICE_ONE,
policies: {
policy_the_second: POLICY_TWO,
},
},
])).toBeTruthy();
expect(MatrixClientPeg.get().agreeToTerms.calledWith(
], ["http://example.com/one"]);
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
Matrix.SERVICE_TYPES.IM,
'https://imone.test',
'a token token',
["http://example.com/one", "http://example.com/two"],
)).toBeTruthy();
);
});
it("should prompt for only services with un-agreed policies", async function() {
MatrixClientPeg.get().getAccountData = sinon.stub().returns({
getContent: sinon.stub().returns({
MatrixClientPeg.get().getAccountData = jest.fn().mockReturnValue({
getContent: jest.fn().mockReturnValue({
accepted: ["http://example.com/one"],
}),
});
MatrixClientPeg.get().getTerms = sinon.stub();
MatrixClientPeg.get().getTerms.callsFake((serviceType, baseUrl, accessToken) => {
MatrixClientPeg.get().getTerms = jest.fn((serviceType, baseUrl, accessToken) => {
switch (baseUrl) {
case 'https://imone.test':
return {
@ -161,35 +150,35 @@ describe('Terms', function() {
}
});
MatrixClientPeg.get().agreeToTerms = sinon.stub();
MatrixClientPeg.get().agreeToTerms = jest.fn();
const interactionCallback = sinon.stub().resolves(["http://example.com/one", "http://example.com/two"]);
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
await startTermsFlow([IM_SERVICE_ONE, IM_SERVICE_TWO], interactionCallback);
console.log("getTerms call 0", MatrixClientPeg.get().getTerms.getCall(0).args);
console.log("getTerms call 1", MatrixClientPeg.get().getTerms.getCall(1).args);
console.log("interactionCallback call", interactionCallback.getCall(0).args);
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.getCall(0).args);
// console.log("getTerms call 0", MatrixClientPeg.get().getTerms.getCall(0).args);
// console.log("getTerms call 1", MatrixClientPeg.get().getTerms.getCall(1).args);
// console.log("interactionCallback call", interactionCallback.getCall(0).args);
// console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.getCall(0).args);
expect(interactionCallback.calledWith([
expect(interactionCallback).toBeCalledWith([
{
service: IM_SERVICE_TWO,
policies: {
policy_the_second: POLICY_TWO,
},
},
])).toBeTruthy();
expect(MatrixClientPeg.get().agreeToTerms.calledWith(
], ["http://example.com/one"]);
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
Matrix.SERVICE_TYPES.IM,
'https://imone.test',
'a token token',
["http://example.com/one"],
)).toBeTruthy();
expect(MatrixClientPeg.get().agreeToTerms.calledWith(
);
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
Matrix.SERVICE_TYPES.IM,
'https://imtwo.test',
'a token token',
["http://example.com/two"],
)).toBeTruthy();
);
});
});

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import lolex from 'lolex';
import jest from 'jest-mock';
import EventEmitter from 'events';

View file

@ -1,7 +0,0 @@
// all-tests.js
//
// Our master test file: uses the webpack require API to find our test files
// and run them
const context = require.context('.', true, /-test\.jsx?$/);
context.keys().forEach(context);

View file

@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import QueryMatcher from '../../src/autocomplete/QueryMatcher';
const OBJECTS = [

View file

@ -17,14 +17,13 @@ limitations under the License.
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import expect from 'expect';
import MockHttpBackend from 'matrix-mock-request';
import MatrixClientPeg from '../../../src/MatrixClientPeg';
import sdk from 'matrix-react-sdk';
import sdk from '../../skinned-sdk';
import Matrix from 'matrix-js-sdk';
import * as TestUtils from 'test-utils';
import * as TestUtils from '../../test-utils';
const { waitForUpdate } = TestUtils;
const GroupView = sdk.getComponent('structures.GroupView');

View file

@ -23,10 +23,9 @@ import ReactDOM from "react-dom";
import PropTypes from "prop-types";
const TestUtils = require('react-dom/test-utils');
const expect = require('expect');
import sinon from 'sinon';
import { EventEmitter } from "events";
const sdk = require('matrix-react-sdk');
import sdk from '../../skinned-sdk';
const MessagePanel = sdk.getComponent('structures.MessagePanel');
import MatrixClientPeg from '../../../src/MatrixClientPeg';
@ -72,15 +71,14 @@ describe('MessagePanel', function() {
const clock = mockclock.clock();
const realSetTimeout = window.setTimeout;
const events = mkEvents();
let sandbox = null;
beforeEach(function() {
sandbox = test_utils.stubClient();
test_utils.stubClient();
client = MatrixClientPeg.get();
client.credentials = {userId: '@me:here'};
// HACK: We assume all settings want to be disabled
SettingsStore.getValue = sinon.stub().returns(false);
SettingsStore.getValue = jest.fn().returns(false);
SettingsStore.getValue.withArgs('showDisplaynameChanges').returns(true);
// This option clobbers the duration of all animations to be 1ms
@ -94,7 +92,6 @@ describe('MessagePanel', function() {
delete Velocity.mock;
clock.uninstall();
sandbox.restore();
});
function mkEvents() {

View file

@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import {mkServerConfig} from "../../../test-utils";
@ -36,7 +34,6 @@ describe('Login', function() {
});
afterEach(function() {
sinon.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
});
@ -72,7 +69,7 @@ describe('Login', function() {
});
it('should show form without change server link when custom URLs disabled', function() {
sinon.stub(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").returns({
disable_custom_urls: true,
});

View file

@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import {mkServerConfig} from "../../../test-utils";
@ -36,7 +34,6 @@ describe('Registration', function() {
});
afterEach(function() {
sinon.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
});
@ -61,7 +58,7 @@ describe('Registration', function() {
});
it('should show form when custom URLs disabled', function() {
sinon.stub(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").returns({
disable_custom_urls: true,
});

View file

@ -14,14 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sinon from 'sinon';
import MatrixReactTestUtils from 'matrix-react-test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
import * as test_utils from '../../../test-utils';
@ -33,10 +31,9 @@ const InteractiveAuthDialog = sdk.getComponent(
describe('InteractiveAuthDialog', function() {
let parentDiv;
let sandbox;
beforeEach(function() {
sandbox = test_utils.stubClient(sandbox);
test_utils.stubClient();
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
});
@ -44,12 +41,11 @@ describe('InteractiveAuthDialog', function() {
afterEach(function() {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
sandbox.restore();
});
it('Should successfully complete a password flow', function() {
const onFinished = sinon.spy();
const doRequest = sinon.stub().returns(Promise.resolve({a: 1}));
const onFinished = jest.fn();
const doRequest = jest.fn().mockResolvedValue({a: 1});
// tell the stub matrixclient to return a real userid
const client = MatrixClientPeg.get();
@ -108,8 +104,8 @@ describe('InteractiveAuthDialog', function() {
// let the request complete
return sleep(1);
}).then(() => {
expect(onFinished.callCount).toEqual(1);
expect(onFinished.calledWithExactly(true, {a: 1})).toBe(true);
expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toBeCalledWith(true, {a: 1});
});
});
});

View file

@ -1,8 +1,7 @@
import expect from 'expect';
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import ShallowRenderer from "react-test-renderer/shallow";
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import * as languageHandler from '../../../../src/languageHandler';
import * as testUtils from '../../../test-utils';
@ -12,8 +11,6 @@ const MemberEventListSummary = testUtils.wrapInMatrixClientContext(
);
describe('MemberEventListSummary', function() {
let sandbox;
// Generate dummy event tiles for use in simulating an expanded MELS
const generateTiles = (events) => {
return events.map((e) => {
@ -88,7 +85,7 @@ describe('MemberEventListSummary', function() {
};
beforeEach(function(done) {
sandbox = testUtils.stubClient();
testUtils.stubClient();
languageHandler.setLanguage('en').then(done);
languageHandler.setMissingEntryGenerator(function(key) {
@ -96,10 +93,6 @@ describe('MemberEventListSummary', function() {
});
});
afterEach(function() {
sandbox.restore();
});
it('renders expanded events if there are less than props.threshold', function() {
const events = generateEvents([
{userId: "@user_1:some.domain", prevMembership: "leave", membership: "join"},

View file

@ -17,14 +17,13 @@ limitations under the License.
import React from "react";
import ReactDOM from "react-dom";
import ReactTestUtils from "react-dom/test-utils";
import expect from "expect";
import MockHttpBackend from "matrix-mock-request";
import MatrixClientPeg from "../../../../src/MatrixClientPeg";
import sdk from "matrix-react-sdk";
import sdk from "../../../skinned-sdk";
import Matrix from "matrix-js-sdk";
import * as TestUtils from "test-utils";
import * as TestUtils from "../../../test-utils";
const { waitForUpdate } = TestUtils;
const GroupMemberList = sdk.getComponent("views.groups.GroupMemberList");

View file

@ -1,10 +1,9 @@
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import expect from 'expect';
import lolex from 'lolex';
import * as TestUtils from 'test-utils';
import * as TestUtils from '../../../test-utils';
import sdk from '../../../../src/index';
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
@ -26,7 +25,6 @@ describe('MemberList', () => {
}
let parentDiv = null;
let sandbox = null;
let client = null;
let root = null;
let clock = null;
@ -38,7 +36,7 @@ describe('MemberList', () => {
let defaultUsers = [];
beforeEach(function() {
sandbox = TestUtils.stubClient(sandbox);
TestUtils.stubClient();
client = MatrixClientPeg.get();
client.hasLazyLoadMembersEnabled = () => false;
@ -115,7 +113,6 @@ describe('MemberList', () => {
parentDiv.remove();
parentDiv = null;
}
sandbox.restore();
clock.uninstall();

View file

@ -1,10 +1,8 @@
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import expect from 'expect';
import sinon from 'sinon';
import * as testUtils from '../../../test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
const MessageComposerInput = sdk.getComponent('views.rooms.MessageComposerInput');
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
import {sleep} from "../../../../src/utils/promise";
@ -23,13 +21,12 @@ function addTextToDraft(text) {
xdescribe('MessageComposerInput', () => {
let parentDiv = null,
sandbox = null,
client = null,
mci = null,
room = testUtils.mkStubRoom('!DdJkzRliezrwpNebLk:matrix.org');
beforeEach(function() {
sandbox = testUtils.stubClient(sandbox);
testUtils.stubClient();
client = MatrixClientPeg.get();
client.credentials = {userId: '@me:domain.com'};
@ -54,7 +51,6 @@ xdescribe('MessageComposerInput', () => {
parentDiv.remove();
parentDiv = null;
}
sandbox.restore();
done();
});
});
@ -75,66 +71,66 @@ xdescribe('MessageComposerInput', () => {
});
it('should not send messages when composer is empty', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(true);
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(false, 'should not send message');
expect(spy).not.toBeCalled();
});
it('should not change content unnecessarily on RTE -> Markdown conversion', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(true);
addTextToDraft('a');
mci.handleKeyCommand('toggle-mode');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('a');
});
it('should not change content unnecessarily on Markdown -> RTE conversion', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('a');
mci.handleKeyCommand('toggle-mode');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('a');
});
it('should send emoji messages when rich text is enabled', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(true);
addTextToDraft('☹');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true, 'should send message');
});
it('should send emoji messages when Markdown is enabled', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('☹');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true, 'should send message');
});
// FIXME
// it('should convert basic Markdown to rich text correctly', () => {
// const spy = sinon.spy(client, 'sendHtmlMessage');
// const spy = jest.spyOn(client, 'sendHtmlMessage');
// mci.enableRichtext(false);
// addTextToDraft('*abc*');
// mci.handleKeyCommand('toggle-mode');
// mci.handleReturn(sinon.stub());
// mci.handleReturn(jest.fn());
// console.error(spy.args[0][2]);
// expect(spy.args[0][2]).toContain('<em>abc');
// });
//
// it('should convert basic rich text to Markdown correctly', () => {
// const spy = sinon.spy(client, 'sendHtmlMessage');
// const spy = jest.spyOn(client, 'sendHtmlMessage');
// mci.enableRichtext(true);
// process.nextTick(() => {
//
@ -142,43 +138,43 @@ xdescribe('MessageComposerInput', () => {
// mci.handleKeyCommand('italic');
// addTextToDraft('abc');
// mci.handleKeyCommand('toggle-mode');
// mci.handleReturn(sinon.stub());
// mci.handleReturn(jest.fn());
// expect(['_abc_', '*abc*']).toContain(spy.args[0][1]);
// });
it('should insert formatting characters in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
mci.handleKeyCommand('italic');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(['__', '**']).toContain(spy.args[0][1].body);
});
it('should not entity-encode " in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('"');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('"');
});
it('should escape characters without other markup in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('\\*escaped\\*');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('*escaped*');
});
it('should escape characters with other markup in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('\\*escaped\\* *italic*');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('\\*escaped\\* *italic*');
@ -186,20 +182,20 @@ xdescribe('MessageComposerInput', () => {
});
it('should not convert -_- into a horizontal rule in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('-_-');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('-_-');
});
it('should not strip <del> tags in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('<del>striked-out</del>');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('<del>striked-out</del>');
@ -207,30 +203,30 @@ xdescribe('MessageComposerInput', () => {
});
it('should not strike-through ~~~ in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('~~~striked-out~~~');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('~~~striked-out~~~');
});
it('should not mark single unmarkedup paragraphs as HTML in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
});
it('should not mark two unmarkedup paragraphs as HTML in Markdown mode', () => {
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
addTextToDraft('Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nFusce congue sapien sed neque molestie volutpat.');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1].body).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nFusce congue sapien sed neque molestie volutpat.');
@ -238,7 +234,7 @@ xdescribe('MessageComposerInput', () => {
it('should strip tab-completed mentions so that only the display name is sent in the plain body in Markdown mode', () => {
// Sending a HTML message because we have entities in the composer (because of completions)
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(false);
mci.setDisplayedCompletion({
completion: 'Some Member',
@ -246,7 +242,7 @@ xdescribe('MessageComposerInput', () => {
href: `https://matrix.to/#/@some_member:domain.bla`,
});
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.args[0][1].body).toEqual(
'Some Member',
@ -260,7 +256,7 @@ xdescribe('MessageComposerInput', () => {
it('should strip tab-completed mentions so that only the display name is sent in the plain body in RTE mode', () => {
// Sending a HTML message because we have entities in the composer (because of completions)
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
mci.enableRichtext(true);
mci.setDisplayedCompletion({
completion: 'Some Member',
@ -268,7 +264,7 @@ xdescribe('MessageComposerInput', () => {
href: `https://matrix.to/#/@some_member:domain.bla`,
});
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.args[0][1].body).toEqual('Some Member');
expect(spy.args[0][1].formatted_body).toEqual('<a href="https://matrix.to/#/@some_member:domain.bla">Some Member</a>');
@ -276,12 +272,12 @@ xdescribe('MessageComposerInput', () => {
it('should not strip non-tab-completed mentions when manually typing MD', () => {
// Sending a HTML message because we have entities in the composer (because of completions)
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
// Markdown mode enabled
mci.enableRichtext(false);
addTextToDraft('[My Not-Tab-Completed Mention](https://matrix.to/#/@some_member:domain.bla)');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.args[0][1].body).toEqual('[My Not-Tab-Completed Mention](https://matrix.to/#/@some_member:domain.bla)');
expect(spy.args[0][1].formatted_body).toEqual('<a href="https://matrix.to/#/@some_member:domain.bla">My Not-Tab-Completed Mention</a>');
@ -289,12 +285,12 @@ xdescribe('MessageComposerInput', () => {
it('should not strip arbitrary typed (i.e. not tab-completed) MD links', () => {
// Sending a HTML message because we have entities in the composer (because of completions)
const spy = sinon.spy(client, 'sendMessage');
const spy = jest.spyOn(client, 'sendMessage');
// Markdown mode enabled
mci.enableRichtext(false);
addTextToDraft('[Click here](https://some.lovely.url)');
mci.handleReturn(sinon.stub());
mci.handleReturn(jest.fn());
expect(spy.args[0][1].body).toEqual('[Click here](https://some.lovely.url)');
expect(spy.args[0][1].formatted_body).toEqual('<a href="https://some.lovely.url">Click here</a>');

View file

@ -1,10 +1,9 @@
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import expect from 'expect';
import lolex from 'lolex';
import * as TestUtils from 'test-utils';
import * as TestUtils from '../../../test-utils';
import sdk from '../../../../src/index';
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
@ -31,7 +30,6 @@ describe('RoomList', () => {
}
let parentDiv = null;
let sandbox = null;
let client = null;
let root = null;
const myUserId = '@me:domain';
@ -45,7 +43,7 @@ describe('RoomList', () => {
let myOtherMember;
beforeEach(function() {
sandbox = TestUtils.stubClient(sandbox);
TestUtils.stubClient();
client = MatrixClientPeg.get();
client.credentials = {userId: myUserId};
//revert this to prototype method as the test-utils monkey-patches this to return a hardcoded value
@ -111,7 +109,6 @@ describe('RoomList', () => {
parentDiv.remove();
parentDiv = null;
}
sandbox.restore();
clock.uninstall();

View file

@ -1,190 +1,187 @@
// TODO: Rewrite room settings tests for dialog support
// import React from 'react';
// import ReactDOM from 'react-dom';
// import expect from 'expect';
// import jest from 'jest-mock';
// import * as testUtils from '../../../test-utils';
// import sdk from 'matrix-react-sdk';
// const WrappedRoomSettings = testUtils.wrapInMatrixClientContext(sdk.getComponent('views.rooms.RoomSettings'));
// import MatrixClientPeg from '../../../../src/MatrixClientPeg';
// import SettingsStore from '../../../../src/settings/SettingsStore';
//
//
// describe('RoomSettings', () => {
// let parentDiv = null;
// let sandbox = null;
// let client = null;
// let roomSettings = null;
// const room = testUtils.mkStubRoom('!DdJkzRliezrwpNebLk:matrix.org');
//
// function expectSentStateEvent(roomId, eventType, expectedEventContent) {
// let found = false;
// for (const call of client.sendStateEvent.mock.calls) {
// const [
// actualRoomId,
// actualEventType,
// actualEventContent,
// ] = call.slice(0, 3);
//
// if (roomId === actualRoomId && actualEventType === eventType) {
// expect(actualEventContent).toEqual(expectedEventContent);
// found = true;
// break;
// }
// }
// expect(found).toBe(true);
// }
//
// beforeEach(function(done) {
// sandbox = testUtils.stubClient();
// client = MatrixClientPeg.get();
// client.credentials = {userId: '@me:domain.com'};
//
// client.setRoomName = jest.fn().mockReturnValue(Promise.resolve());
// client.setRoomTopic = jest.fn().mockReturnValue(Promise.resolve());
// client.setRoomDirectoryVisibility = jest.fn().mockReturnValue(Promise.resolve());
//
// // Covers any room state event (e.g. name, avatar, topic)
// client.sendStateEvent = jest.fn().mockReturnValue(Promise.resolve());
//
// // Covers room tagging
// client.setRoomTag = jest.fn().mockReturnValue(Promise.resolve());
// client.deleteRoomTag = jest.fn().mockReturnValue(Promise.resolve());
//
// // Covers any setting in the SettingsStore
// // (including local client settings not stored via matrix)
// SettingsStore.setValue = jest.fn().mockReturnValue(Promise.resolve());
//
// parentDiv = document.createElement('div');
// document.body.appendChild(parentDiv);
//
// const gatherWrappedRef = (r) => {roomSettings = r;};
//
// // get use wrappedRef because we're using wrapInMatrixClientContext
// ReactDOM.render(
// <WrappedRoomSettings
// wrappedRef={gatherWrappedRef}
// room={room}
// />,
// parentDiv,
// done,
// );
// });
//
// afterEach((done) => {
// if (parentDiv) {
// ReactDOM.unmountComponentAtNode(parentDiv);
// parentDiv.remove();
// parentDiv = null;
// }
// sandbox.restore();
// done();
// });
//
// it('should not set when no setting is changed', (done) => {
// roomSettings.save().then(() => {
// expect(client.sendStateEvent).not.toHaveBeenCalled();
// expect(client.setRoomTag).not.toHaveBeenCalled();
// expect(client.deleteRoomTag).not.toHaveBeenCalled();
// done();
// });
// });
//
// // XXX: Apparently we do call SettingsStore.setValue
// xit('should not settings via the SettingsStore when no setting is changed', (done) => {
// roomSettings.save().then(() => {
// expect(SettingsStore.setValue).not.toHaveBeenCalled();
// done();
// });
// });
//
// it('should set room name when it has changed', (done) => {
// const name = "My Room Name";
// roomSettings.setName(name);
//
// roomSettings.save().then(() => {
// expect(client.setRoomName.mock.calls[0].slice(0, 2))
// .toEqual(['!DdJkzRliezrwpNebLk:matrix.org', name]);
//
// done();
// });
// });
//
// it('should set room topic when it has changed', (done) => {
// const topic = "this is a topic";
// roomSettings.setTopic(topic);
//
// roomSettings.save().then(() => {
// expect(client.setRoomTopic.mock.calls[0].slice(0, 2))
// .toEqual(['!DdJkzRliezrwpNebLk:matrix.org', topic]);
//
// done();
// });
// });
//
// it('should set history visibility when it has changed', (done) => {
// const historyVisibility = "translucent";
// roomSettings.setState({
// history_visibility: historyVisibility,
// });
//
// roomSettings.save().then(() => {
// expectSentStateEvent(
// "!DdJkzRliezrwpNebLk:matrix.org",
// "m.room.history_visibility", {history_visibility: historyVisibility},
// );
// done();
// });
// });
//
// // XXX: Can't test this because we `getRoomDirectoryVisibility` in `componentWillMount`
// xit('should set room directory publicity when set to true', (done) => {
// const isRoomPublished = true;
// roomSettings.setState({
// isRoomPublished,
// }, () => {
// roomSettings.save().then(() => {
// expect(client.setRoomDirectoryVisibility.calls[0].arguments.slice(0, 2))
// .toEqual("!DdJkzRliezrwpNebLk:matrix.org", isRoomPublished ? "public" : "private");
// done();
// });
// });
// });
//
// it('should set power levels when changed', (done) => {
// roomSettings.onPowerLevelsChanged(42, "invite");
//
// roomSettings.save().then(() => {
// expectSentStateEvent(
// "!DdJkzRliezrwpNebLk:matrix.org",
// "m.room.power_levels", { invite: 42 },
// );
// done();
// });
// });
//
// it('should set event power levels when changed', (done) => {
// roomSettings.onPowerLevelsChanged(42, "event_levels_m.room.message");
//
// roomSettings.save().then(() => {
// // We expect all state events to be set to the state_default (50)
// // See powerLevelDescriptors in RoomSettings
// expectSentStateEvent(
// "!DdJkzRliezrwpNebLk:matrix.org",
// "m.room.power_levels", {
// events: {
// 'm.room.message': 42,
// 'm.room.avatar': 50,
// 'm.room.name': 50,
// 'm.room.canonical_alias': 50,
// 'm.room.history_visibility': 50,
// 'm.room.power_levels': 50,
// 'm.room.topic': 50,
// 'im.vector.modular.widgets': 50,
// },
// },
// );
// done();
// });
// });
// });
import React from 'react';
import ReactDOM from 'react-dom';
import jest from 'jest-mock';
import * as testUtils from '../../../test-utils';
import sdk from '../../../skinned-sdk';
const WrappedRoomSettings = testUtils.wrapInMatrixClientContext(sdk.getComponent('views.rooms.RoomSettings'));
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
import SettingsStore from '../../../../src/settings/SettingsStore';
describe.skip('RoomSettings', () => {
let parentDiv = null;
let client = null;
let roomSettings = null;
const room = testUtils.mkStubRoom('!DdJkzRliezrwpNebLk:matrix.org');
function expectSentStateEvent(roomId, eventType, expectedEventContent) {
let found = false;
for (const call of client.sendStateEvent.mock.calls) {
const [
actualRoomId,
actualEventType,
actualEventContent,
] = call.slice(0, 3);
if (roomId === actualRoomId && actualEventType === eventType) {
expect(actualEventContent).toEqual(expectedEventContent);
found = true;
break;
}
}
expect(found).toBe(true);
}
beforeEach(function(done) {
testUtils.stubClient();
client = MatrixClientPeg.get();
client.credentials = {userId: '@me:domain.com'};
client.setRoomName = jest.fn().mockReturnValue(Promise.resolve());
client.setRoomTopic = jest.fn().mockReturnValue(Promise.resolve());
client.setRoomDirectoryVisibility = jest.fn().mockReturnValue(Promise.resolve());
// Covers any room state event (e.g. name, avatar, topic)
client.sendStateEvent = jest.fn().mockReturnValue(Promise.resolve());
// Covers room tagging
client.setRoomTag = jest.fn().mockReturnValue(Promise.resolve());
client.deleteRoomTag = jest.fn().mockReturnValue(Promise.resolve());
// Covers any setting in the SettingsStore
// (including local client settings not stored via matrix)
SettingsStore.setValue = jest.fn().mockReturnValue(Promise.resolve());
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
const gatherWrappedRef = (r) => {roomSettings = r;};
// get use wrappedRef because we're using wrapInMatrixClientContext
ReactDOM.render(
<WrappedRoomSettings
wrappedRef={gatherWrappedRef}
room={room}
/>,
parentDiv,
done,
);
});
afterEach((done) => {
if (parentDiv) {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
parentDiv = null;
}
done();
});
it('should not set when no setting is changed', (done) => {
roomSettings.save().then(() => {
expect(client.sendStateEvent).not.toHaveBeenCalled();
expect(client.setRoomTag).not.toHaveBeenCalled();
expect(client.deleteRoomTag).not.toHaveBeenCalled();
done();
});
});
// XXX: Apparently we do call SettingsStore.setValue
xit('should not settings via the SettingsStore when no setting is changed', (done) => {
roomSettings.save().then(() => {
expect(SettingsStore.setValue).not.toHaveBeenCalled();
done();
});
});
it('should set room name when it has changed', (done) => {
const name = "My Room Name";
roomSettings.setName(name);
roomSettings.save().then(() => {
expect(client.setRoomName.mock.calls[0].slice(0, 2))
.toEqual(['!DdJkzRliezrwpNebLk:matrix.org', name]);
done();
});
});
it('should set room topic when it has changed', (done) => {
const topic = "this is a topic";
roomSettings.setTopic(topic);
roomSettings.save().then(() => {
expect(client.setRoomTopic.mock.calls[0].slice(0, 2))
.toEqual(['!DdJkzRliezrwpNebLk:matrix.org', topic]);
done();
});
});
it('should set history visibility when it has changed', (done) => {
const historyVisibility = "translucent";
roomSettings.setState({
history_visibility: historyVisibility,
});
roomSettings.save().then(() => {
expectSentStateEvent(
"!DdJkzRliezrwpNebLk:matrix.org",
"m.room.history_visibility", {history_visibility: historyVisibility},
);
done();
});
});
// XXX: Can't test this because we `getRoomDirectoryVisibility` in `componentWillMount`
xit('should set room directory publicity when set to true', (done) => {
const isRoomPublished = true;
roomSettings.setState({
isRoomPublished,
}, () => {
roomSettings.save().then(() => {
expect(client.setRoomDirectoryVisibility.calls[0].arguments.slice(0, 2))
.toEqual("!DdJkzRliezrwpNebLk:matrix.org", isRoomPublished ? "public" : "private");
done();
});
});
});
it('should set power levels when changed', (done) => {
roomSettings.onPowerLevelsChanged(42, "invite");
roomSettings.save().then(() => {
expectSentStateEvent(
"!DdJkzRliezrwpNebLk:matrix.org",
"m.room.power_levels", { invite: 42 },
);
done();
});
});
it('should set event power levels when changed', (done) => {
roomSettings.onPowerLevelsChanged(42, "event_levels_m.room.message");
roomSettings.save().then(() => {
// We expect all state events to be set to the state_default (50)
// See powerLevelDescriptors in RoomSettings
expectSentStateEvent(
"!DdJkzRliezrwpNebLk:matrix.org",
"m.room.power_levels", {
events: {
'm.room.message': 42,
'm.room.avatar': 50,
'm.room.name': 50,
'm.room.canonical_alias': 50,
'm.room.history_visibility': 50,
'm.room.power_levels': 50,
'm.room.topic': 50,
'im.vector.modular.widgets': 50,
},
},
);
done();
});
});
});

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import {getLineAndNodePosition} from "../../src/editor/caret";
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import {parseEvent} from "../../src/editor/deserialize";
import {createPartCreator} from "./mock";

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import {diffDeletion, diffAtCaret} from "../../src/editor/diff";
describe('editor/diff', function() {

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import HistoryManager, {MAX_STEP_LENGTH} from "../../src/editor/history";
describe('editor/history', function() {

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";

View file

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import EditorModel from "../../src/editor/model";
import {htmlSerializeIfNeeded} from "../../src/editor/serialize";
import {createPartCreator} from "./mock";

View file

@ -5,18 +5,12 @@ import * as languageHandler from '../../src/languageHandler';
const testUtils = require('../test-utils');
describe('languageHandler', function() {
let sandbox;
beforeEach(function(done) {
sandbox = testUtils.stubClient();
testUtils.stubClient();
languageHandler.setLanguage('en').then(done);
});
afterEach(function() {
sandbox.restore();
});
it('translates a string to german', function() {
languageHandler.setLanguage('de').then(function() {
const translated = languageHandler._t('Rooms');

View file

@ -1,8 +1,5 @@
import expect from 'expect';
import RoomViewStore from '../../src/stores/RoomViewStore';
import peg from '../../src/MatrixClientPeg';
import * as testUtils from '../test-utils';
@ -10,20 +7,14 @@ import * as testUtils from '../test-utils';
const dispatch = testUtils.getDispatchForStore(RoomViewStore);
describe('RoomViewStore', function() {
let sandbox;
beforeEach(function() {
sandbox = testUtils.stubClient();
testUtils.stubClient();
peg.get().credentials = { userId: "@test:example.com" };
// Reset the state of the store
RoomViewStore.reset();
});
afterEach(function() {
sandbox.restore();
});
it('can be used to view a room by ID and join', function(done) {
peg.get().joinRoom = (roomAddress) => {
expect(roomAddress).toBe("!randomcharacters:aser.ver");

View file

@ -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.
*/

View file

@ -16,9 +16,7 @@ limitations under the License.
"use strict";
import * as MegolmExportEncryption from '../../src/utils/MegolmExportEncryption';
import expect from 'expect';
import SubtleCrypto from 'subtle';
const TEST_VECTORS=[
[
@ -58,19 +56,22 @@ const TEST_VECTORS=[
"bWnSXS9oymiqwUIGs08sXI33ZA==\n" +
"-----END MEGOLM SESSION DATA-----",
],
]
;
];
function stringToArray(s) {
return new TextEncoder().encode(s).buffer;
}
describe('MegolmExportEncryption', function() {
before(function() {
// if we don't have subtlecrypto, go home now
if (!window.crypto.subtle && !window.crypto.webkitSubtle) {
this.skip();
}
let MegolmExportEncryption;
beforeAll(() => {
window.crypto = { subtle: SubtleCrypto };
MegolmExportEncryption = require("../../src/utils/MegolmExportEncryption");
});
afterAll(() => {
window.crypto = undefined;
});
describe('decrypt', function() {

View file

@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import peg from '../../../src/MatrixClientPeg';
import {
makeGroupPermalink,
@ -66,17 +65,11 @@ function mockRoom(roomId, members, serverACL) {
}
describe('Permalinks', function() {
let sandbox;
beforeEach(function() {
sandbox = testUtils.stubClient();
testUtils.stubClient();
peg.get().credentials = { userId: "@test:example.com" };
});
afterEach(function() {
sandbox.restore();
});
it('should pick no candidate servers when the room has no members', function() {
const room = mockRoom("!fake:example.org", []);
const creator = new RoomPermalinkCreator(room);