@@ -30,6 +30,7 @@ import sdk from 'matrix-react-sdk';
3030import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg' ;
3131import * as languageHandler from 'matrix-react-sdk/lib/languageHandler' ;
3232import { VIEWS } from 'matrix-react-sdk/lib/components/structures/MatrixChat' ;
33+ import dis from 'matrix-react-sdk/lib/dispatcher' ;
3334
3435import * as test_utils from '../test-utils' ;
3536import MockHttpBackend from '../mock-request' ;
@@ -493,6 +494,76 @@ describe('loading:', function () {
493494 expect ( windowLocation . hash ) . toEqual ( "#/room/!room:id" ) ;
494495 } ) . done ( done , done ) ;
495496 } ) ;
497+
498+ describe ( 'Login as user' , function ( ) {
499+ beforeEach ( function ( ) {
500+ // first we have to load the homepage
501+ loadApp ( ) ;
502+
503+ httpBackend . when ( 'POST' , '/register' ) . check ( function ( req ) {
504+ expect ( req . queryParams . kind ) . toEqual ( 'guest' ) ;
505+ } ) . respond ( 200 , {
506+ user_id : "@guest:localhost" ,
507+ access_token : "secret_token" ,
508+ } ) ;
509+
510+ return httpBackend . flush ( ) . then ( ( ) => {
511+ return awaitSyncingSpinner ( matrixChat ) ;
512+ } ) . then ( ( ) => {
513+ // we got a sync spinner - let the sync complete
514+ return expectAndAwaitSync ( ) ;
515+ } ) . then ( ( ) => {
516+ // once the sync completes, we should have a home page
517+ ReactTestUtils . findRenderedComponentWithType (
518+ matrixChat , sdk . getComponent ( 'structures.HomePage' ) ) ;
519+
520+ // we simulate a click on the 'login' button by firing off
521+ // the relevant dispatch.
522+ //
523+ // XXX: is it an anti-pattern to access the react-sdk's
524+ // dispatcher in this way? Is it better to find the login
525+ // button and simulate a click? (we might have to arrange
526+ // for it to be shown - it's not always, due to the
527+ // collapsing left panel
528+
529+ dis . dispatch ( { action : 'start_login' } ) ;
530+
531+ return q . delay ( 1 ) ;
532+ } ) ;
533+ } ) ;
534+
535+ it ( 'should give us a login page' , function ( ) {
536+ expect ( windowLocation . hash ) . toEqual ( "#/login" ) ;
537+
538+ // we expect a single <Login> component
539+ ReactTestUtils . findRenderedComponentWithType (
540+ matrixChat , sdk . getComponent ( 'structures.login.Login' )
541+ ) ;
542+ } ) ;
543+
544+ it ( 'should allow us to return to the app' , function ( ) {
545+ const login = ReactTestUtils . findRenderedComponentWithType (
546+ matrixChat , sdk . getComponent ( 'structures.login.Login' )
547+ ) ;
548+
549+ const linkText = 'Return to app' ;
550+
551+ const returnToApp = ReactTestUtils . scryRenderedDOMComponentsWithTag (
552+ login , 'a' ) . find ( ( e ) => e . innerText === linkText ) ;
553+
554+ if ( ! returnToApp ) {
555+ throw new Error ( `Couldn't find '${ linkText } ' link` ) ;
556+ }
557+
558+ ReactTestUtils . Simulate . click ( returnToApp ) ;
559+
560+ return q . delay ( 1 ) . then ( ( ) => {
561+ // we should be straight back into the home page
562+ ReactTestUtils . findRenderedComponentWithType (
563+ matrixChat , sdk . getComponent ( 'structures.HomePage' ) ) ;
564+ } ) ;
565+ } ) ;
566+ } ) ;
496567 } ) ;
497568
498569 describe ( 'Token login:' , function ( ) {
0 commit comments