Skip to content

Commit

Permalink
Merge pull request #4201 from vector-im/luke/fix-tests
Browse files Browse the repository at this point in the history
Fix tests for new-guest-access
  • Loading branch information
dbkr authored Jun 5, 2017
2 parents 5e67bcd + feaff9d commit 88e843d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/structures/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = React.createClass({
{ method: "GET", url: src },
(err, response, body) => {
if (err || response.status < 200 || response.status >= 300) {
console.log(error);
console.log(err);
this.setState({ page: "Couldn't load home page" });
}

Expand Down
37 changes: 19 additions & 18 deletions test/app-tests/joining.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ describe('joining a room', function () {
var mc = (
<MatrixChat config={{}}
makeRegistrationUrl={()=>{throw new Error("unimplemented");}}
initialScreenAfterLogin={{
screen: 'directory',
}}
/>
);
matrixChat = ReactDOM.render(mc, parentDiv);

// switch to the Directory
matrixChat._setPage(PageTypes.RoomDirectory);

var roomView;

// wait for /sync to happen. This may take some time, as the client
Expand Down Expand Up @@ -138,38 +138,32 @@ describe('joining a room', function () {
httpBackend.when('GET', '/directory/room/'+encodeURIComponent(ROOM_ALIAS)).respond(200, { room_id: ROOM_ID });
httpBackend.when('GET', '/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync")
.respond(401, {errcode: 'M_GUEST_ACCESS_FORBIDDEN'});
return httpBackend.flush();

return q.all([
httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS)),
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync"),
]);
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();

// we should now have a roomview, with a preview bar
roomView = ReactTestUtils.findRenderedComponentWithType(
matrixChat, RoomView);

var previewBar = ReactTestUtils.findRenderedComponentWithType(
const previewBar = ReactTestUtils.findRenderedComponentWithType(
roomView, RoomPreviewBar);

var joinLink = ReactTestUtils.findRenderedDOMComponentWithTag(
const joinLink = ReactTestUtils.findRenderedDOMComponentWithTag(
previewBar, 'a');

ReactTestUtils.Simulate.click(joinLink);

// that will fire off a request to check our displayname, followed by a
// join request
httpBackend.when('GET', '/profile/'+encodeURIComponent(USER_ID))
.respond(200, {displayname: 'boris'});
httpBackend.when('POST', '/join/'+encodeURIComponent(ROOM_ALIAS))
httpBackend.when('POST', '/join/'+encodeURIComponent(ROOM_ID))
.respond(200, {room_id: ROOM_ID});
return httpBackend.flush();
}).then(() => {
// wait for the join request to be made
return q.delay(1);
}).then(() => {
// flush it through
return httpBackend.flush();
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();

// the roomview should now be loading
expect(roomView.state.room).toBe(null);
expect(roomView.state.joining).toBe(true);
Expand All @@ -178,6 +172,14 @@ describe('joining a room', function () {
ReactTestUtils.findRenderedDOMComponentWithClass(
roomView, "mx_Spinner");

// flush it through
return httpBackend.flush('/join/'+encodeURIComponent(ROOM_ID));
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();

// We've joined, expect this to false
expect(roomView.state.joining).toBe(false);

// now send the room down the /sync pipe
httpBackend.when('GET', '/sync').
respond(200, {
Expand All @@ -197,7 +199,6 @@ describe('joining a room', function () {
}).then(() => {
// now the room should have loaded
expect(roomView.state.room).toExist();
expect(roomView.state.joining).toBe(false);
}).done(done, done);
});
});
Expand Down
10 changes: 4 additions & 6 deletions test/app-tests/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('loading:', function () {
function routeUrl(location, matrixChat) {
console.log(Date.now() + ` routing URL '${location}'`);
const s = getScreenFromLocation(location);
console.log("Showing screen "+ s);
console.log("Showing screen ", s);
matrixChat.showScreen(s.screen, s.params);
}

Expand Down Expand Up @@ -193,14 +193,12 @@ describe('loading:', function () {

return httpBackend.flush();
}).then(() => {
// Wait for another trip around the event loop for the UI to update
return q.delay(1);
}).then(() => {
// we expect a single <Login> component
// we expect a single <Login> component following session load
ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.login.Login'));
expect(windowLocation.hash).toEqual("");
}).done(done, done);
done();
});
});

it('should follow the original link after successful login', function(done) {
Expand Down

0 comments on commit 88e843d

Please sign in to comment.