Step 8.3: Convert RoomViewStore to a more modern singleton for imports

This commit is contained in:
Travis Ralston 2022-03-22 23:26:30 -06:00
parent 8d2dba4102
commit d5ed1eb66e
24 changed files with 99 additions and 102 deletions

View file

@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import RoomViewStore from '../../src/stores/RoomViewStore';
import { RoomViewStore } from '../../src/stores/RoomViewStore';
import { Action } from '../../src/dispatcher/actions';
import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg';
import * as testUtils from '../test-utils';
const dispatch = testUtils.getDispatchForStore(RoomViewStore);
const dispatch = testUtils.getDispatchForStore(RoomViewStore.instance);
jest.mock('../../src/utils/DMRoomMap', () => {
const mock = {
@ -41,7 +41,7 @@ describe('RoomViewStore', function() {
peg.get().off = jest.fn();
// Reset the state of the store
RoomViewStore.reset();
RoomViewStore.instance.reset();
});
it('can be used to view a room by ID and join', function(done) {
@ -52,16 +52,16 @@ describe('RoomViewStore', function() {
dispatch({ action: Action.ViewRoom, room_id: '!randomcharacters:aser.ver' });
dispatch({ action: 'join_room' });
expect(RoomViewStore.isJoining()).toBe(true);
expect(RoomViewStore.instance.isJoining()).toBe(true);
});
it('can be used to view a room by alias and join', function(done) {
const token = RoomViewStore.addListener(() => {
const token = RoomViewStore.instance.addListener(() => {
// Wait until the room alias has resolved and the room ID is
if (!RoomViewStore.isRoomLoading()) {
expect(RoomViewStore.getRoomId()).toBe("!randomcharacters:aser.ver");
if (!RoomViewStore.instance.isRoomLoading()) {
expect(RoomViewStore.instance.getRoomId()).toBe("!randomcharacters:aser.ver");
dispatch({ action: 'join_room' });
expect(RoomViewStore.isJoining()).toBe(true);
expect(RoomViewStore.instance.isJoining()).toBe(true);
}
});