Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -15,26 +15,26 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import ReactTestUtils from 'react-dom/test-utils';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||
import React from "react";
|
||||
import ReactTestUtils from "react-dom/test-utils";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import { User } from "matrix-js-sdk/src/models/user";
|
||||
import { compare } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
|
||||
import * as TestUtils from '../../../test-utils';
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import * as TestUtils from "../../../test-utils";
|
||||
import MemberList from "../../../../src/components/views/rooms/MemberList";
|
||||
import MemberTile from '../../../../src/components/views/rooms/MemberTile';
|
||||
import { SDKContext } from '../../../../src/contexts/SDKContext';
|
||||
import { TestSdkContext } from '../../../TestSdkContext';
|
||||
import MemberTile from "../../../../src/components/views/rooms/MemberTile";
|
||||
import { SDKContext } from "../../../../src/contexts/SDKContext";
|
||||
import { TestSdkContext } from "../../../TestSdkContext";
|
||||
|
||||
function generateRoomId() {
|
||||
return '!' + Math.random().toString().slice(2, 10) + ':domain';
|
||||
return "!" + Math.random().toString().slice(2, 10) + ":domain";
|
||||
}
|
||||
|
||||
describe('MemberList', () => {
|
||||
describe("MemberList", () => {
|
||||
function createRoom(opts = {}) {
|
||||
const room = new Room(generateRoomId(), null, client.getUserId());
|
||||
if (opts) {
|
||||
|
@ -53,12 +53,12 @@ describe('MemberList', () => {
|
|||
let moderatorUsers = [];
|
||||
let defaultUsers = [];
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
TestUtils.stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client.hasLazyLoadMembersEnabled = () => false;
|
||||
|
||||
parentDiv = document.createElement('div');
|
||||
parentDiv = document.createElement("div");
|
||||
document.body.appendChild(parentDiv);
|
||||
|
||||
// Make room
|
||||
|
@ -76,7 +76,7 @@ describe('MemberList', () => {
|
|||
adminUser.powerLevel = 100;
|
||||
adminUser.user = new User(adminUser.userId);
|
||||
adminUser.user.currentlyActive = true;
|
||||
adminUser.user.presence = 'online';
|
||||
adminUser.user.presence = "online";
|
||||
adminUser.user.lastPresenceTs = 1000;
|
||||
adminUser.user.lastActiveAgo = 10;
|
||||
adminUsers.push(adminUser);
|
||||
|
@ -86,7 +86,7 @@ describe('MemberList', () => {
|
|||
moderatorUser.powerLevel = 50;
|
||||
moderatorUser.user = new User(moderatorUser.userId);
|
||||
moderatorUser.user.currentlyActive = true;
|
||||
moderatorUser.user.presence = 'online';
|
||||
moderatorUser.user.presence = "online";
|
||||
moderatorUser.user.lastPresenceTs = 1000;
|
||||
moderatorUser.user.lastActiveAgo = 10;
|
||||
moderatorUsers.push(moderatorUser);
|
||||
|
@ -96,7 +96,7 @@ describe('MemberList', () => {
|
|||
defaultUser.powerLevel = 0;
|
||||
defaultUser.user = new User(defaultUser.userId);
|
||||
defaultUser.user.currentlyActive = true;
|
||||
defaultUser.user.presence = 'online';
|
||||
defaultUser.user.presence = "online";
|
||||
defaultUser.user.lastPresenceTs = 1000;
|
||||
defaultUser.user.lastActiveAgo = 10;
|
||||
defaultUsers.push(defaultUser);
|
||||
|
@ -109,7 +109,7 @@ describe('MemberList', () => {
|
|||
memberListRoom.currentState = {
|
||||
members: {},
|
||||
getMember: jest.fn(),
|
||||
getStateEvents: (eventType, stateKey) => stateKey === undefined ? [] : null, // ignore 3pid invites
|
||||
getStateEvents: (eventType, stateKey) => (stateKey === undefined ? [] : null), // ignore 3pid invites
|
||||
};
|
||||
for (const member of [...adminUsers, ...moderatorUsers, ...defaultUsers]) {
|
||||
memberListRoom.currentState.members[member.userId] = member;
|
||||
|
@ -121,17 +121,15 @@ describe('MemberList', () => {
|
|||
const context = new TestSdkContext();
|
||||
context.client = client;
|
||||
root = ReactDOM.render(
|
||||
(
|
||||
<SDKContext.Provider value={context}>
|
||||
<MemberList
|
||||
searchQuery=""
|
||||
onClose={jest.fn()}
|
||||
onSearchQueryChanged={jest.fn()}
|
||||
roomId={memberListRoom.roomId}
|
||||
ref={gatherWrappedRef}
|
||||
/>
|
||||
</SDKContext.Provider>
|
||||
),
|
||||
<SDKContext.Provider value={context}>
|
||||
<MemberList
|
||||
searchQuery=""
|
||||
onClose={jest.fn()}
|
||||
onSearchQueryChanged={jest.fn()}
|
||||
roomId={memberListRoom.roomId}
|
||||
ref={gatherWrappedRef}
|
||||
/>
|
||||
</SDKContext.Provider>,
|
||||
parentDiv,
|
||||
);
|
||||
});
|
||||
|
@ -166,15 +164,15 @@ describe('MemberList', () => {
|
|||
let groupChange = false;
|
||||
|
||||
if (isPresenceEnabled) {
|
||||
const convertPresence = (p) => p === 'unavailable' ? 'online' : p;
|
||||
const presenceIndex = p => {
|
||||
const order = ['active', 'online', 'offline'];
|
||||
const convertPresence = (p) => (p === "unavailable" ? "online" : p);
|
||||
const presenceIndex = (p) => {
|
||||
const order = ["active", "online", "offline"];
|
||||
const idx = order.indexOf(convertPresence(p));
|
||||
return idx === -1 ? order.length : idx; // unknown states at the end
|
||||
};
|
||||
|
||||
const idxA = presenceIndex(userA.currentlyActive ? 'active' : userA.presence);
|
||||
const idxB = presenceIndex(userB.currentlyActive ? 'active' : userB.presence);
|
||||
const idxA = presenceIndex(userA.currentlyActive ? "active" : userA.presence);
|
||||
const idxB = presenceIndex(userB.currentlyActive ? "active" : userB.presence);
|
||||
console.log("Comparing presence groups...");
|
||||
expect(idxB).toBeGreaterThanOrEqual(idxA);
|
||||
groupChange = idxA !== idxB;
|
||||
|
@ -203,8 +201,8 @@ describe('MemberList', () => {
|
|||
}
|
||||
|
||||
if (!groupChange) {
|
||||
const nameA = memberA.name[0] === '@' ? memberA.name.slice(1) : memberA.name;
|
||||
const nameB = memberB.name[0] === '@' ? memberB.name.slice(1) : memberB.name;
|
||||
const nameA = memberA.name[0] === "@" ? memberA.name.slice(1) : memberA.name;
|
||||
const nameB = memberB.name[0] === "@" ? memberB.name.slice(1) : memberB.name;
|
||||
const nameCompare = compare(nameB, nameA);
|
||||
console.log("Comparing name");
|
||||
expect(nameCompare).toBeGreaterThanOrEqual(0);
|
||||
|
@ -215,7 +213,7 @@ describe('MemberList', () => {
|
|||
}
|
||||
|
||||
function itDoesOrderMembersCorrectly(enablePresence) {
|
||||
describe('does order members correctly', () => {
|
||||
describe("does order members correctly", () => {
|
||||
// Note: even if presence is disabled, we still expect that the presence
|
||||
// tests will pass. All expectOrderedByPresenceAndPowerLevel does is ensure
|
||||
// the order is perceived correctly, regardless of what we did to the members.
|
||||
|
@ -223,22 +221,22 @@ describe('MemberList', () => {
|
|||
// Each of the 4 tests here is done to prove that the member list can meet
|
||||
// all 4 criteria independently. Together, they should work.
|
||||
|
||||
it('by presence state', () => {
|
||||
it("by presence state", () => {
|
||||
// Intentionally pick users that will confuse the power level sorting
|
||||
const activeUsers = [defaultUsers[0]];
|
||||
const onlineUsers = [adminUsers[0]];
|
||||
const offlineUsers = [...moderatorUsers, ...adminUsers.slice(1), ...defaultUsers.slice(1)];
|
||||
activeUsers.forEach((u) => {
|
||||
u.user.currentlyActive = true;
|
||||
u.user.presence = 'online';
|
||||
u.user.presence = "online";
|
||||
});
|
||||
onlineUsers.forEach((u) => {
|
||||
u.user.currentlyActive = false;
|
||||
u.user.presence = 'online';
|
||||
u.user.presence = "online";
|
||||
});
|
||||
offlineUsers.forEach((u) => {
|
||||
u.user.currentlyActive = false;
|
||||
u.user.presence = 'offline';
|
||||
u.user.presence = "offline";
|
||||
});
|
||||
|
||||
// Bypass all the event listeners and skip to the good part
|
||||
|
@ -249,7 +247,7 @@ describe('MemberList', () => {
|
|||
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
||||
});
|
||||
|
||||
it('by power level', () => {
|
||||
it("by power level", () => {
|
||||
// We already have admin, moderator, and default users so leave them alone
|
||||
|
||||
// Bypass all the event listeners and skip to the good part
|
||||
|
@ -260,7 +258,7 @@ describe('MemberList', () => {
|
|||
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
||||
});
|
||||
|
||||
it('by last active timestamp', () => {
|
||||
it("by last active timestamp", () => {
|
||||
// Intentionally pick users that will confuse the power level sorting
|
||||
// lastActiveAgoTs == lastPresenceTs - lastActiveAgo
|
||||
const activeUsers = [defaultUsers[0]];
|
||||
|
@ -290,7 +288,7 @@ describe('MemberList', () => {
|
|||
expectOrderedByPresenceAndPowerLevel(tiles, enablePresence);
|
||||
});
|
||||
|
||||
it('by name', () => {
|
||||
it("by name", () => {
|
||||
// Intentionally put everyone on the same level to force a name comparison
|
||||
const allUsers = [...adminUsers, ...moderatorUsers, ...defaultUsers];
|
||||
allUsers.forEach((u) => {
|
||||
|
@ -311,12 +309,11 @@ describe('MemberList', () => {
|
|||
});
|
||||
}
|
||||
|
||||
describe('when presence is enabled', () => {
|
||||
describe("when presence is enabled", () => {
|
||||
itDoesOrderMembersCorrectly(true);
|
||||
});
|
||||
|
||||
describe('when presence is not enabled', () => {
|
||||
describe("when presence is not enabled", () => {
|
||||
itDoesOrderMembersCorrectly(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue