Skip to content

Commit b742342

Browse files
authored
Merge pull request element-hq#1938 from vector-im/rav/more_loading_tests
More app-loading tests
2 parents 6a19655 + fe4bb3e commit b742342

1 file changed

Lines changed: 97 additions & 16 deletions

File tree

‎test/app-tests/loading.js‎

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ describe('loading:', function () {
5050
// document.body.appendChild(parentDiv);
5151

5252
windowLocation = null;
53+
54+
window.localStorage.clear();
5355
});
5456

5557
afterEach(function() {
@@ -131,8 +133,7 @@ describe('loading:', function () {
131133
q.delay(1).then(() => {
132134
// at this point, we're trying to do a guest registration;
133135
// we expect a spinner
134-
ReactTestUtils.findRenderedComponentWithType(
135-
matrixChat, sdk.getComponent('elements.Spinner'));
136+
assertAtLoadingSpinner(matrixChat);
136137

137138
httpBackend.when('POST', '/register').check(function(req) {
138139
expect(req.queryParams.kind).toEqual('guest');
@@ -153,8 +154,7 @@ describe('loading:', function () {
153154
q.delay(1).then(() => {
154155
// at this point, we're trying to do a guest registration;
155156
// we expect a spinner
156-
ReactTestUtils.findRenderedComponentWithType(
157-
matrixChat, sdk.getComponent('elements.Spinner'));
157+
assertAtLoadingSpinner(matrixChat);
158158

159159
httpBackend.when('POST', '/register').check(function(req) {
160160
expect(req.queryParams.kind).toEqual('guest');
@@ -193,14 +193,10 @@ describe('loading:', function () {
193193

194194
describe("MatrixClient rehydrated from stored credentials:", function() {
195195
beforeEach(function() {
196-
// start with a logged-in client
197-
MatrixClientPeg.replaceUsingCreds({
198-
homeserverUrl: 'http://localhost',
199-
identityServerUrl: 'http://localhost',
200-
userId: '@me:localhost',
201-
accessToken: 'access_token',
202-
guest: false,
203-
});
196+
localStorage.setItem("mx_hs_url", "http://localhost" );
197+
localStorage.setItem("mx_is_url", "http://localhost" );
198+
localStorage.setItem("mx_access_token", "access_token");
199+
localStorage.setItem("mx_user_id", "@me:localhost");
204200
});
205201

206202
it('shows a directory by default if we have no joined rooms', function(done) {
@@ -212,8 +208,8 @@ describe('loading:', function () {
212208

213209
q.delay(1).then(() => {
214210
// we expect a spinner
215-
ReactTestUtils.findRenderedComponentWithType(
216-
matrixChat, sdk.getComponent('elements.Spinner'));
211+
assertAtSyncingSpinner(matrixChat);
212+
217213
return httpBackend.flush();
218214
}).then(() => {
219215
// once the sync completes, we should have a directory
@@ -233,8 +229,8 @@ describe('loading:', function () {
233229

234230
q.delay(1).then(() => {
235231
// we expect a spinner
236-
ReactTestUtils.findRenderedComponentWithType(
237-
matrixChat, sdk.getComponent('elements.Spinner'));
232+
assertAtSyncingSpinner(matrixChat);
233+
238234
return httpBackend.flush();
239235
}).then(() => {
240236
// once the sync completes, we should have a room view
@@ -246,4 +242,89 @@ describe('loading:', function () {
246242

247243
});
248244
});
245+
246+
describe('Guest auto-registration:', function() {
247+
it('shows a directory by default', function (done) {
248+
let matrixChat = loadApp("");
249+
250+
q.delay(1).then(() => {
251+
// at this point, we're trying to do a guest registration;
252+
// we expect a spinner
253+
assertAtLoadingSpinner(matrixChat);
254+
255+
httpBackend.when('POST', '/register').check(function(req) {
256+
expect(req.queryParams.kind).toEqual('guest');
257+
}).respond(200, {
258+
user_id: "@guest:localhost",
259+
access_token: "secret_token",
260+
});
261+
262+
return httpBackend.flush();
263+
}).then(() => {
264+
// now we should have a spinner with a logout link
265+
assertAtSyncingSpinner(matrixChat);
266+
267+
httpBackend.when('GET', '/sync').respond(200, {});
268+
return httpBackend.flush();
269+
}).then(() => {
270+
// once the sync completes, we should have a directory
271+
httpBackend.verifyNoOutstandingExpectation();
272+
ReactTestUtils.findRenderedComponentWithType(
273+
matrixChat, sdk.getComponent('structures.RoomDirectory'));
274+
expect(windowLocation.hash).toEqual("#/directory");
275+
}).done(done, done);
276+
});
277+
278+
it('shows a room view if we followed a room link', function(done) {
279+
let matrixChat = loadApp("#/room/!room:id");
280+
q.delay(10).then(() => {
281+
// at this point, we're trying to do a guest registration;
282+
// we expect a spinner
283+
assertAtLoadingSpinner(matrixChat);
284+
285+
httpBackend.when('POST', '/register').check(function(req) {
286+
expect(req.queryParams.kind).toEqual('guest');
287+
}).respond(200, {
288+
user_id: "@guest:localhost",
289+
access_token: "secret_token",
290+
});
291+
292+
return httpBackend.flush();
293+
}).then(() => {
294+
// now we should have a spinner with a logout link
295+
assertAtSyncingSpinner(matrixChat);
296+
297+
httpBackend.when('GET', '/sync').respond(200, {});
298+
return httpBackend.flush();
299+
}).then(() => {
300+
// once the sync completes, we should have a room view
301+
httpBackend.verifyNoOutstandingExpectation();
302+
ReactTestUtils.findRenderedComponentWithType(
303+
matrixChat, sdk.getComponent('structures.RoomView'));
304+
expect(windowLocation.hash).toEqual("#/room/!room:id");
305+
}).done(done, done);
306+
});
307+
});
249308
});
309+
310+
// assert that we are on the loading page
311+
function assertAtLoadingSpinner(matrixChat) {
312+
var domComponent = ReactDOM.findDOMNode(matrixChat);
313+
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
314+
315+
// just the spinner
316+
expect(domComponent.children.length).toEqual(1);
317+
}
318+
319+
// we've got login creds, and are waiting for the sync to finish.
320+
// the page includes a logout link.
321+
function assertAtSyncingSpinner(matrixChat) {
322+
var domComponent = ReactDOM.findDOMNode(matrixChat);
323+
expect(domComponent.className).toEqual("mx_MatrixChat_splash");
324+
325+
ReactTestUtils.findRenderedComponentWithType(
326+
matrixChat, sdk.getComponent('elements.Spinner'));
327+
var logoutLink = ReactTestUtils.findRenderedDOMComponentWithTag(
328+
matrixChat, 'a');
329+
expect(logoutLink.text).toEqual("Logout");
330+
}

0 commit comments

Comments
 (0)