Initial pass of fixing tests

* Use new components
* Use new tagId prop on sublists
* Define onResize for the room list so it doesn't crash
This commit is contained in:
Travis Ralston 2020-07-07 15:06:06 -06:00
parent a59a8b76a9
commit c774b88bda

View file

@ -57,11 +57,11 @@ describe('RoomList', () => {
parentDiv = document.createElement('div'); parentDiv = document.createElement('div');
document.body.appendChild(parentDiv); document.body.appendChild(parentDiv);
const RoomList = sdk.getComponent('views.rooms.RoomList'); const RoomList = sdk.getComponent('views.rooms.RoomList2');
const WrappedRoomList = TestUtils.wrapInMatrixClientContext(RoomList); const WrappedRoomList = TestUtils.wrapInMatrixClientContext(RoomList);
root = ReactDOM.render( root = ReactDOM.render(
<DragDropContext> <DragDropContext>
<WrappedRoomList searchFilter="" /> <WrappedRoomList searchFilter="" onResize={() => {}} />
</DragDropContext> </DragDropContext>
, parentDiv); , parentDiv);
ReactTestUtils.findRenderedComponentWithType(root, RoomList); ReactTestUtils.findRenderedComponentWithType(root, RoomList);
@ -117,8 +117,8 @@ describe('RoomList', () => {
}); });
function expectRoomInSubList(room, subListTest) { function expectRoomInSubList(room, subListTest) {
const RoomSubList = sdk.getComponent('structures.RoomSubList'); const RoomSubList = sdk.getComponent('views.rooms.RoomSublist2');
const RoomTile = sdk.getComponent('views.rooms.RoomTile'); const RoomTile = sdk.getComponent('views.rooms.RoomTile2');
const subLists = ReactTestUtils.scryRenderedComponentsWithType(root, RoomSubList); const subLists = ReactTestUtils.scryRenderedComponentsWithType(root, RoomSubList);
const containingSubList = subLists.find(subListTest); const containingSubList = subLists.find(subListTest);
@ -140,20 +140,20 @@ describe('RoomList', () => {
expect(expectedRoomTile.props.room).toBe(room); expect(expectedRoomTile.props.room).toBe(room);
} }
function expectCorrectMove(oldTag, newTag) { function expectCorrectMove(oldTagId, newTagId) {
const getTagSubListTest = (tag) => { const getTagSubListTest = (tagId) => {
if (tag === undefined) return (s) => s.props.label.endsWith('Rooms'); return (s) => s.props.tagId === tagId;
return (s) => s.props.tagName === tag;
}; };
// Default to finding the destination sublist with newTag // Default to finding the destination sublist with newTag
const destSubListTest = getTagSubListTest(newTag); const destSubListTest = getTagSubListTest(newTagId);
const srcSubListTest = getTagSubListTest(oldTag); const srcSubListTest = getTagSubListTest(oldTagId);
// Set up the room that will be moved such that it has the correct state for a room in // Set up the room that will be moved such that it has the correct state for a room in
// the section for oldTag // the section for oldTagId
if (['m.favourite', 'm.lowpriority'].includes(oldTag)) movingRoom.tags = {[oldTag]: {}}; if (oldTagId === DefaultTagID.Favourite || oldTagId === DefaultTagID.LowPriority) {
if (oldTag === DefaultTagID.DM) { movingRoom.tags = {[oldTagId]: {}};
} else if (oldTagId === DefaultTagID.DM) {
// Mock inverse m.direct // Mock inverse m.direct
DMRoomMap.shared().roomToUser = { DMRoomMap.shared().roomToUser = {
[movingRoom.roomId]: '@someotheruser:domain', [movingRoom.roomId]: '@someotheruser:domain',
@ -167,7 +167,7 @@ describe('RoomList', () => {
expectRoomInSubList(movingRoom, srcSubListTest); expectRoomInSubList(movingRoom, srcSubListTest);
dis.dispatch({action: 'RoomListActions.tagRoom.pending', request: { dis.dispatch({action: 'RoomListActions.tagRoom.pending', request: {
oldTag, newTag, room: movingRoom, oldTagId, newTagId, room: movingRoom,
}}); }});
// Run all setTimeouts for dispatches and room list rate limiting // Run all setTimeouts for dispatches and room list rate limiting
@ -287,7 +287,7 @@ describe('RoomList', () => {
clock.runAll(); clock.runAll();
// By default, the test will // By default, the test will
expectRoomInSubList(otherRoom, (s) => s.props.label.endsWith('Rooms')); expectRoomInSubList(otherRoom, (s) => s.props.tagId === DefaultTagID.Untagged);
}); });
itDoesCorrectOptimisticUpdatesForDraggedRoomTiles(); itDoesCorrectOptimisticUpdatesForDraggedRoomTiles();