You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
Merge remote-tracking branch 'origin/t3chguy/jest' into travis/sourcemaps
This commit is contained in:
@@ -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,11 +31,9 @@ const InteractiveAuthDialog = sdk.getComponent(
|
||||
|
||||
describe('InteractiveAuthDialog', function() {
|
||||
let parentDiv;
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function() {
|
||||
test_utils.beforeEach(this);
|
||||
sandbox = test_utils.stubClient(sandbox);
|
||||
test_utils.stubClient();
|
||||
parentDiv = document.createElement('div');
|
||||
document.body.appendChild(parentDiv);
|
||||
});
|
||||
@@ -45,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();
|
||||
@@ -96,8 +91,8 @@ describe('InteractiveAuthDialog', function() {
|
||||
expect(submitNode.disabled).toBe(false);
|
||||
ReactTestUtils.Simulate.submit(formNode, {});
|
||||
|
||||
expect(doRequest.callCount).toEqual(1);
|
||||
expect(doRequest.calledWithMatch({
|
||||
expect(doRequest).toHaveBeenCalledTimes(1);
|
||||
expect(doRequest).toBeCalledWith(expect.objectContaining({
|
||||
session: "sess",
|
||||
type: "m.login.password",
|
||||
password: "s3kr3t",
|
||||
@@ -105,12 +100,12 @@ describe('InteractiveAuthDialog', function() {
|
||||
type: "m.id.user",
|
||||
user: "@user:id",
|
||||
},
|
||||
})).toBe(true);
|
||||
}));
|
||||
// let the request complete
|
||||
return sleep(1);
|
||||
}).then(() => {
|
||||
expect(onFinished.callCount).toEqual(1);
|
||||
expect(onFinished.calledWithExactly(true, {a: 1})).toBe(true);
|
||||
}).then(sleep(1)).then(() => {
|
||||
expect(onFinished).toBeCalledTimes(1);
|
||||
expect(onFinished).toBeCalledWith(true, {a: 1});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,9 +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 * as languageHandler from '../../../../src/languageHandler';
|
||||
import sdk from '../../../skinned-sdk';
|
||||
import * as testUtils from '../../../test-utils';
|
||||
|
||||
// Give MELS a matrixClient in its child context
|
||||
@@ -12,8 +10,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) => {
|
||||
@@ -87,18 +83,8 @@ describe('MemberEventListSummary', function() {
|
||||
return eventsForUsers;
|
||||
};
|
||||
|
||||
beforeEach(function(done) {
|
||||
testUtils.beforeEach(this);
|
||||
sandbox = testUtils.stubClient();
|
||||
|
||||
languageHandler.setLanguage('en').then(done);
|
||||
languageHandler.setMissingEntryGenerator(function(key) {
|
||||
return key.split('|', 2)[1];
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
sandbox.restore();
|
||||
beforeEach(function() {
|
||||
testUtils.stubClient();
|
||||
});
|
||||
|
||||
it('renders expanded events if there are less than props.threshold', function() {
|
||||
@@ -167,7 +153,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe("user_1 joined and left and joined");
|
||||
});
|
||||
@@ -203,7 +189,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe("user_1 joined and left 7 times");
|
||||
});
|
||||
@@ -251,7 +237,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was unbanned, joined and left 7 times and was invited",
|
||||
@@ -304,7 +290,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was unbanned, joined and left 2 times, was banned, " +
|
||||
@@ -363,7 +349,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and one other were unbanned, joined and left 2 times and were banned",
|
||||
@@ -401,7 +387,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_0 and 19 others were unbanned, joined and left 2 times and were banned",
|
||||
@@ -452,7 +438,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_2 was unbanned and joined and left 2 times, user_1 was unbanned, " +
|
||||
@@ -526,7 +512,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 was invited, was banned, joined, rejected their invitation, left, " +
|
||||
@@ -573,7 +559,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and one other rejected their invitations and " +
|
||||
@@ -609,7 +595,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 rejected their invitation 2 times",
|
||||
@@ -637,7 +623,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1 and user_2 joined 2 times",
|
||||
@@ -664,7 +650,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_1, user_2 and one other joined",
|
||||
@@ -689,7 +675,7 @@ describe('MemberEventListSummary', function() {
|
||||
const summary = ReactTestUtils.findRenderedDOMComponentWithClass(
|
||||
instance, "mx_EventListSummary_summary",
|
||||
);
|
||||
const summaryText = summary.innerText;
|
||||
const summaryText = summary.textContent;
|
||||
|
||||
expect(summaryText).toBe(
|
||||
"user_0, user_1 and 18 others joined",
|
||||
|
@@ -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");
|
||||
@@ -70,8 +69,6 @@ describe("GroupMemberList", function() {
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
TestUtils.beforeEach(this);
|
||||
|
||||
httpBackend = new MockHttpBackend();
|
||||
|
||||
Matrix.request(httpBackend.requestFn);
|
||||
@@ -115,7 +112,7 @@ describe("GroupMemberList", function() {
|
||||
const memberList = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_MemberList_joined");
|
||||
const memberListElement = ReactDOM.findDOMNode(memberList);
|
||||
expect(memberListElement).toBeTruthy();
|
||||
expect(memberListElement.innerText).toBe("Test");
|
||||
expect(memberListElement.textContent).toBe("Test");
|
||||
});
|
||||
|
||||
httpBackend.when("GET", "/groups/" + groupIdEncoded + "/summary").respond(200, summaryResponse);
|
||||
@@ -135,7 +132,7 @@ describe("GroupMemberList", function() {
|
||||
const memberList = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_MemberList_joined");
|
||||
const memberListElement = ReactDOM.findDOMNode(memberList);
|
||||
expect(memberListElement).toBeTruthy();
|
||||
expect(memberListElement.innerText).toBe("Failed to load group members");
|
||||
expect(memberListElement.textContent).toBe("Failed to load group members");
|
||||
});
|
||||
|
||||
httpBackend.when("GET", "/groups/" + groupIdEncoded + "/summary").respond(200, summaryResponse);
|
||||
|
@@ -1,13 +1,12 @@
|
||||
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';
|
||||
import sdk from '../../../skinned-sdk';
|
||||
|
||||
import {Room, RoomMember, User} from 'matrix-js-sdk';
|
||||
|
||||
@@ -26,7 +25,6 @@ describe('MemberList', () => {
|
||||
}
|
||||
|
||||
let parentDiv = null;
|
||||
let sandbox = null;
|
||||
let client = null;
|
||||
let root = null;
|
||||
let clock = null;
|
||||
@@ -38,8 +36,7 @@ describe('MemberList', () => {
|
||||
let defaultUsers = [];
|
||||
|
||||
beforeEach(function() {
|
||||
TestUtils.beforeEach(this);
|
||||
sandbox = TestUtils.stubClient(sandbox);
|
||||
TestUtils.stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client.hasLazyLoadMembersEnabled = () => false;
|
||||
|
||||
@@ -116,7 +113,6 @@ describe('MemberList', () => {
|
||||
parentDiv.remove();
|
||||
parentDiv = null;
|
||||
}
|
||||
sandbox.restore();
|
||||
|
||||
clock.uninstall();
|
||||
|
||||
|
@@ -1,13 +1,12 @@
|
||||
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';
|
||||
import sdk from '../../../skinned-sdk';
|
||||
import { DragDropContext } from 'react-beautiful-dnd';
|
||||
|
||||
import dis from '../../../../src/dispatcher';
|
||||
@@ -31,7 +30,6 @@ describe('RoomList', () => {
|
||||
}
|
||||
|
||||
let parentDiv = null;
|
||||
let sandbox = null;
|
||||
let client = null;
|
||||
let root = null;
|
||||
const myUserId = '@me:domain';
|
||||
@@ -45,8 +43,7 @@ describe('RoomList', () => {
|
||||
let myOtherMember;
|
||||
|
||||
beforeEach(function() {
|
||||
TestUtils.beforeEach(this);
|
||||
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
|
||||
@@ -112,7 +109,6 @@ describe('RoomList', () => {
|
||||
parentDiv.remove();
|
||||
parentDiv = null;
|
||||
}
|
||||
sandbox.restore();
|
||||
|
||||
clock.uninstall();
|
||||
|
||||
@@ -181,7 +177,7 @@ describe('RoomList', () => {
|
||||
|
||||
function itDoesCorrectOptimisticUpdatesForDraggedRoomTiles() {
|
||||
// TODO: Re-enable dragging tests when we support dragging again.
|
||||
xdescribe('does correct optimistic update when dragging from', () => {
|
||||
describe.skip('does correct optimistic update when dragging from', () => {
|
||||
it('rooms to people', () => {
|
||||
expectCorrectMove(undefined, 'im.vector.fake.direct');
|
||||
});
|
||||
|
@@ -1,191 +1,188 @@
|
||||
// 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) {
|
||||
// testUtils.beforeEach(this);
|
||||
// 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';
|
||||
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
|
||||
import SettingsStore from '../../../../src/settings/SettingsStore';
|
||||
|
||||
|
||||
describe.skip('RoomSettings', () => {
|
||||
const WrappedRoomSettings = testUtils.wrapInMatrixClientContext(sdk.getComponent('views.rooms.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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user