Files
ThreadNet-Web/test/stores/RoomViewStore-test.js
T

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-05-24 16:56:13 +01:00
import expect from 'expect';
import dis from '../../src/dispatcher';
import RoomViewStore from '../../src/stores/RoomViewStore';
import peg from '../../src/MatrixClientPeg';
import * as testUtils from '../test-utils';
2017-07-12 13:58:14 +01:00
import Promise from 'bluebird';
2017-05-24 16:56:13 +01:00
const dispatch = testUtils.getDispatchForStore(RoomViewStore);
describe('RoomViewStore', function() {
let sandbox;
beforeEach(function() {
testUtils.beforeEach(this);
sandbox = testUtils.stubClient();
peg.get().credentials = { userId: "@test:example.com" };
// Reset the state of the store
RoomViewStore.reset();
});
afterEach(function() {
sandbox.restore();
});
it('can be used to view a room by ID and join', function(done) {
2017-06-08 17:47:48 +01:00
peg.get().joinRoom = (roomAddress) => {
expect(roomAddress).toBe("!randomcharacters:aser.ver");
2017-05-24 16:56:13 +01:00
done();
};
dispatch({ action: 'view_room', room_id: '!randomcharacters:aser.ver' });
dispatch({ action: 'join_room' });
expect(RoomViewStore.isJoining()).toBe(true);
});
it('can be used to view a room by alias and join', function(done) {
2017-07-12 14:02:00 +01:00
peg.get().getRoomIdForAlias.returns(Promise.resolve({room_id: "!randomcharacters:aser.ver"}));
2017-06-08 17:47:48 +01:00
peg.get().joinRoom = (roomAddress) => {
expect(roomAddress).toBe("#somealias2:aser.ver");
2017-05-24 16:56:13 +01:00
done();
};
2017-06-02 09:22:48 +01:00
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);
}
});
2017-05-24 16:56:13 +01:00
2017-06-02 09:22:48 +01:00
dispatch({ action: 'view_room', room_alias: '#somealias2:aser.ver' });
2017-05-24 16:56:13 +01:00
});
});