From 7808994b719ef4cce19c9bcca3aba52315c1fc9a Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 2 Jun 2017 09:22:48 +0100 Subject: [PATCH] Modify RVS test to wait until room loaded This allows for the alias resolution to occur before a join is attempted. In theory, join_room could in future do an optional view_room-esque thing before attemping a join which would be less fragile than dispatching things in the right order. Also, make sure the store indicates that it is not loading when a room ID has been used - no alias resolution need take place. --- src/stores/RoomViewStore.js | 6 +++--- test/stores/RoomViewStore-test.js | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index a74652a39d..b94e772b02 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -87,10 +87,10 @@ class RoomViewStore extends Store { if (payload.room_id) { this._setState({ roomId: payload.room_id, + roomLoading: false, + roomLoadError: null, }); - } - - if (payload.room_alias && !payload.room_id) { + } else if (payload.room_alias) { this._setState({ roomId: null, roomAlias: payload.room_alias, diff --git a/test/stores/RoomViewStore-test.js b/test/stores/RoomViewStore-test.js index 7100dced19..2f545ffd74 100644 --- a/test/stores/RoomViewStore-test.js +++ b/test/stores/RoomViewStore-test.js @@ -45,12 +45,15 @@ describe('RoomViewStore', function() { done(); }; - dispatch({ action: 'view_room', room_alias: '#somealias2:aser.ver' }); + RoomViewStore.addListener(() => { + // Wait until the room alias has resolved and the room ID is + if (!RoomViewStore.isRoomLoading()) { + expect(RoomViewStore.getRoomId()).toBe("!randomcharacters:aser.ver"); + dispatch({ action: 'join_room' }); + expect(RoomViewStore.isJoining()).toBe(true); + } + }); - // Wait for the next event loop to allow for room alias resolution - setTimeout(() => { - dispatch({ action: 'join_room' }); - expect(RoomViewStore.isJoining()).toBe(true); - }, 0); + dispatch({ action: 'view_room', room_alias: '#somealias2:aser.ver' }); }); });