Add tests for testing room tile updates when tags (groups in LLP) are selected
parent
80d251b622
commit
e15b39092d
|
@ -12,9 +12,22 @@ import { DragDropContext } from 'react-beautiful-dnd';
|
||||||
|
|
||||||
import dis from '../../../../src/dispatcher';
|
import dis from '../../../../src/dispatcher';
|
||||||
import DMRoomMap from '../../../../src/utils/DMRoomMap.js';
|
import DMRoomMap from '../../../../src/utils/DMRoomMap.js';
|
||||||
|
import GroupStore from '../../../../src/stores/GroupStore.js';
|
||||||
|
|
||||||
import { Room, RoomMember } from 'matrix-js-sdk';
|
import { Room, RoomMember } from 'matrix-js-sdk';
|
||||||
|
|
||||||
|
function generateRoomId() {
|
||||||
|
return '!' + Math.random().toString().slice(2, 10) + ':domain';
|
||||||
|
}
|
||||||
|
|
||||||
|
function createRoom(opts) {
|
||||||
|
const room = new Room(generateRoomId());
|
||||||
|
if (opts) {
|
||||||
|
Object.assign(room, opts);
|
||||||
|
}
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
|
||||||
describe('RoomList', () => {
|
describe('RoomList', () => {
|
||||||
let parentDiv = null;
|
let parentDiv = null;
|
||||||
let sandbox = null;
|
let sandbox = null;
|
||||||
|
@ -23,6 +36,13 @@ describe('RoomList', () => {
|
||||||
const myUserId = '@me:domain';
|
const myUserId = '@me:domain';
|
||||||
let clock = null;
|
let clock = null;
|
||||||
|
|
||||||
|
const movingRoomId = '!someroomid';
|
||||||
|
let movingRoom;
|
||||||
|
let otherRoom;
|
||||||
|
|
||||||
|
let myMember;
|
||||||
|
let myOtherMember;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
TestUtils.beforeEach(this);
|
TestUtils.beforeEach(this);
|
||||||
sandbox = TestUtils.stubClient(sandbox);
|
sandbox = TestUtils.stubClient(sandbox);
|
||||||
|
@ -44,6 +64,40 @@ describe('RoomList', () => {
|
||||||
</DragDropContext>
|
</DragDropContext>
|
||||||
, parentDiv);
|
, parentDiv);
|
||||||
ReactTestUtils.findRenderedComponentWithType(root, RoomList);
|
ReactTestUtils.findRenderedComponentWithType(root, RoomList);
|
||||||
|
|
||||||
|
movingRoom = createRoom({name: 'Moving room'});
|
||||||
|
expect(movingRoom.roomId).toNotBe(null);
|
||||||
|
|
||||||
|
// Mock joined member
|
||||||
|
myMember = new RoomMember(movingRoomId, myUserId);
|
||||||
|
myMember.membership = 'join';
|
||||||
|
movingRoom.getMember = (userId) => ({
|
||||||
|
[client.credentials.userId]: myMember,
|
||||||
|
}[userId]);
|
||||||
|
|
||||||
|
otherRoom = createRoom({name: 'Other room'});
|
||||||
|
myOtherMember = new RoomMember(otherRoom.roomId, myUserId);
|
||||||
|
myOtherMember.membership = 'join';
|
||||||
|
otherRoom.getMember = (userId) => ({
|
||||||
|
[client.credentials.userId]: myOtherMember,
|
||||||
|
}[userId]);
|
||||||
|
|
||||||
|
// Mock the matrix client
|
||||||
|
client.getRooms = () => [
|
||||||
|
movingRoom,
|
||||||
|
otherRoom,
|
||||||
|
createRoom({tags: {'m.favourite': {order: 0.1}}, name: 'Some other room'}),
|
||||||
|
createRoom({tags: {'m.favourite': {order: 0.2}}, name: 'Some other room 2'}),
|
||||||
|
createRoom({tags: {'m.lowpriority': {}}, name: 'Some unimportant room'}),
|
||||||
|
createRoom({tags: {'custom.tag': {}}, name: 'Some room customly tagged'}),
|
||||||
|
];
|
||||||
|
|
||||||
|
const roomMap = {};
|
||||||
|
client.getRooms().forEach((r) => {
|
||||||
|
roomMap[r.roomId] = r;
|
||||||
|
});
|
||||||
|
|
||||||
|
client.getRoom = (roomId) => roomMap[roomId];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach((done) => {
|
afterEach((done) => {
|
||||||
|
@ -59,18 +113,6 @@ describe('RoomList', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when no tags are selected', () => {
|
|
||||||
describe('does correct optimistic update when dragging from', () => {
|
|
||||||
const movingRoomId = '!someroomid';
|
|
||||||
const movingRoom = new Room(movingRoomId);
|
|
||||||
|
|
||||||
// Mock joined member
|
|
||||||
const myMember = new RoomMember(movingRoomId, myUserId);
|
|
||||||
myMember.membership = 'join';
|
|
||||||
movingRoom.getMember = (userId) => ({
|
|
||||||
[client.credentials.userId]: myMember,
|
|
||||||
}[userId]);
|
|
||||||
|
|
||||||
function expectRoomInSubList(room, subListTest) {
|
function expectRoomInSubList(room, subListTest) {
|
||||||
const RoomSubList = sdk.getComponent('structures.RoomSubList');
|
const RoomSubList = sdk.getComponent('structures.RoomSubList');
|
||||||
const RoomTile = sdk.getComponent('views.rooms.RoomTile');
|
const RoomTile = sdk.getComponent('views.rooms.RoomTile');
|
||||||
|
@ -80,10 +122,14 @@ describe('RoomList', () => {
|
||||||
|
|
||||||
let expectedRoomTile;
|
let expectedRoomTile;
|
||||||
try {
|
try {
|
||||||
expectedRoomTile = ReactTestUtils.findRenderedComponentWithType(containingSubList, RoomTile);
|
const roomTiles = ReactTestUtils.scryRenderedComponentsWithType(containingSubList, RoomTile);
|
||||||
|
console.info({roomTiles: roomTiles.length});
|
||||||
|
expectedRoomTile = roomTiles.find((tile) => tile.props.room === room);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// truncate the error message because it's spammy
|
// truncate the error message because it's spammy
|
||||||
err.message = 'Error finding RoomTile: ' + err.message.split('componentType')[0] + '...';
|
err.message = 'Error finding RoomTile for ' + room.roomId + ' in ' +
|
||||||
|
subListTest + ': ' +
|
||||||
|
err.message.split('componentType')[0] + '...';
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +147,8 @@ describe('RoomList', () => {
|
||||||
const destSubListTest = getTagSubListTest(newTag);
|
const destSubListTest = getTagSubListTest(newTag);
|
||||||
const srcSubListTest = getTagSubListTest(oldTag);
|
const srcSubListTest = getTagSubListTest(oldTag);
|
||||||
|
|
||||||
// Mock the matrix client
|
// Set up the room that will be moved such that it has the correct state for a room in
|
||||||
client.getRooms = () => [movingRoom];
|
// the section for oldTag
|
||||||
|
|
||||||
if (['m.favourite', 'm.lowpriority'].includes(oldTag)) movingRoom.tags = {[oldTag]: {}};
|
if (['m.favourite', 'm.lowpriority'].includes(oldTag)) movingRoom.tags = {[oldTag]: {}};
|
||||||
if (oldTag === 'im.vector.fake.direct') {
|
if (oldTag === 'im.vector.fake.direct') {
|
||||||
// Mock inverse m.direct
|
// Mock inverse m.direct
|
||||||
|
@ -128,6 +173,8 @@ describe('RoomList', () => {
|
||||||
expectRoomInSubList(movingRoom, destSubListTest);
|
expectRoomInSubList(movingRoom, destSubListTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function itDoesCorrectOptimisticUpdatesForDraggedRoomTiles() {
|
||||||
|
describe('does correct optimistic update when dragging from', () => {
|
||||||
it('rooms to people', () => {
|
it('rooms to people', () => {
|
||||||
expectCorrectMove(undefined, 'im.vector.fake.direct');
|
expectCorrectMove(undefined, 'im.vector.fake.direct');
|
||||||
});
|
});
|
||||||
|
@ -179,6 +226,67 @@ describe('RoomList', () => {
|
||||||
expectCorrectMove('m.favourite', 'm.lowpriority');
|
expectCorrectMove('m.favourite', 'm.lowpriority');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('when no tags are selected', () => {
|
||||||
|
itDoesCorrectOptimisticUpdatesForDraggedRoomTiles();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when tags are selected', () => {
|
||||||
|
function setupSelectedTag() {
|
||||||
|
// Simulate a complete sync BEFORE dispatching anything else
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'MatrixActions.sync',
|
||||||
|
prevState: null,
|
||||||
|
state: 'PREPARED',
|
||||||
|
matrixClient: client,
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Simulate joined groups being received
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'GroupActions.fetchJoinedGroups.success',
|
||||||
|
result: {
|
||||||
|
groups: ['+group:domain'],
|
||||||
|
},
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Simulate receiving tag ordering account data
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'MatrixActions.accountData',
|
||||||
|
event_type: 'im.vector.web.tag_ordering',
|
||||||
|
event_content: {
|
||||||
|
tags: ['+group:domain'],
|
||||||
|
},
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// GroupStore is not flux, mock and notify
|
||||||
|
GroupStore.getGroupRooms = (groupId) => {
|
||||||
|
return [movingRoom];
|
||||||
|
};
|
||||||
|
GroupStore._notifyListeners();
|
||||||
|
|
||||||
|
// Select tag
|
||||||
|
dis.dispatch({action: 'select_tag', tag: '+group:domain'}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setupSelectedTag();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays the correct rooms when the groups rooms are changed', () => {
|
||||||
|
GroupStore.getGroupRooms = (groupId) => {
|
||||||
|
return [movingRoom, otherRoom];
|
||||||
|
};
|
||||||
|
GroupStore._notifyListeners();
|
||||||
|
|
||||||
|
// Run through RoomList debouncing
|
||||||
|
clock.runAll();
|
||||||
|
|
||||||
|
// By default, the test will
|
||||||
|
expectRoomInSubList(otherRoom, (s) => s.props.label.endsWith('Rooms'));
|
||||||
|
});
|
||||||
|
|
||||||
|
itDoesCorrectOptimisticUpdatesForDraggedRoomTiles();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue