22import { Route } from '@ember/-internals/routing' ;
33import Controller from '@ember/controller' ;
44import { Object as EmberObject , A as emberA } from '@ember/-internals/runtime' ;
5- import { moduleFor , ApplicationTestCase , getTextOf } from 'internal-test-helpers' ;
5+ import { moduleFor , ApplicationTestCase , getTextOf , runLoopSettled } from 'internal-test-helpers' ;
66import { run } from '@ember/runloop' ;
77import { computed , set } from '@ember/-internals/metal' ;
88import { isDestroying } from '@glimmer/destroyable' ;
@@ -502,8 +502,6 @@ class LoadingTests extends ApplicationTestCase {
502502 } )
503503 ) ;
504504
505- this . add ( 'route:loading' , Route . extend ( { } ) ) ;
506- this . add ( 'route:home' , Route . extend ( { } ) ) ;
507505 this . add (
508506 'route:special' ,
509507 Route . extend ( {
@@ -518,7 +516,6 @@ class LoadingTests extends ApplicationTestCase {
518516
519517 this . addTemplate ( 'root.index' , '<h3>Home</h3>' ) ;
520518 this . addTemplate ( 'special' , '<p>{{@model.id}}</p>' ) ;
521- this . addTemplate ( 'loading' , '<p>LOADING!</p>' ) ;
522519
523520 return this . visit ( '/' ) . then ( ( ) => {
524521 rootElement = document . getElementById ( 'qunit-fixture' ) ;
@@ -755,7 +752,7 @@ class LoadingTests extends ApplicationTestCase {
755752 } ) ;
756753 }
757754
758- [ '@test Parent route context change' ] ( assert ) {
755+ async [ '@test Parent route context change' ] ( assert ) {
759756 let editCount = 0 ;
760757 let editedPostIds = emberA ( ) ;
761758
@@ -777,8 +774,8 @@ class LoadingTests extends ApplicationTestCase {
777774 'route:posts' ,
778775 Route . extend ( {
779776 actions : {
780- showPost ( context ) {
781- expectDeprecation ( ( ) => {
777+ async showPost ( context ) {
778+ await expectDeprecationAsync ( ( ) => {
782779 this . transitionTo ( 'post' , context ) ;
783780 } , / C a l l i n g t r a n s i t i o n T o o n a r o u t e i s d e p r e c a t e d / ) ;
784781 } ,
@@ -798,8 +795,8 @@ class LoadingTests extends ApplicationTestCase {
798795 } ,
799796
800797 actions : {
801- editPost ( ) {
802- expectDeprecation ( ( ) => {
798+ async editPost ( ) {
799+ await expectDeprecationAsync ( ( ) => {
803800 this . transitionTo ( 'post.edit' ) ;
804801 } , / C a l l i n g t r a n s i t i o n T o o n a r o u t e i s d e p r e c a t e d / ) ;
805802 } ,
@@ -815,22 +812,26 @@ class LoadingTests extends ApplicationTestCase {
815812 editedPostIds . push ( postId ) ;
816813 return null ;
817814 } ,
815+
818816 setup ( ) {
819817 this . _super ( ...arguments ) ;
820818 editCount ++ ;
821819 } ,
822820 } )
823821 ) ;
824822
825- return this . visit ( '/posts/1' ) . then ( ( ) => {
826- assert . ok ( true , '/posts/1 has been handled' ) ;
827- let router = this . applicationInstance . lookup ( 'router:main' ) ;
828- run ( ( ) => router . send ( 'editPost' ) ) ;
829- run ( ( ) => router . send ( 'showPost' , { id : '2' } ) ) ;
830- run ( ( ) => router . send ( 'editPost' ) ) ;
831- assert . equal ( editCount , 2 , 'set up the edit route twice without failure' ) ;
832- assert . deepEqual ( editedPostIds , [ '1' , '2' ] , 'modelFor posts.post returns the right context' ) ;
833- } ) ;
823+ await this . visit ( '/posts/1' ) ;
824+ assert . ok ( true , '/posts/1 has been handled' ) ;
825+ let router = this . applicationInstance . lookup ( 'router:main' ) ;
826+ run ( ( ) => router . send ( 'editPost' ) ) ;
827+ await runLoopSettled ( ) ;
828+ await runLoopSettled ( ) ;
829+ run ( ( ) => router . send ( 'showPost' , { id : '2' } ) ) ;
830+ await runLoopSettled ( ) ;
831+ run ( ( ) => router . send ( 'editPost' ) ) ;
832+ await runLoopSettled ( ) ;
833+ assert . equal ( editCount , 2 , 'set up the edit route twice without failure' ) ;
834+ assert . deepEqual ( editedPostIds , [ '1' , '2' ] , 'modelFor posts.post returns the right context' ) ;
834835 }
835836
836837 [ '@test ApplicationRoute with model does not proxy the currentPath' ] ( assert ) {
@@ -941,6 +942,14 @@ class LoadingTests extends ApplicationTestCase {
941942 assert . equal ( childcount , 2 ) ;
942943 } ) ;
943944 }
945+
946+ [ '@test What about loading states' ] ( assert ) {
947+ assert . expect ( 1 ) ;
948+ this . add ( 'route:loading' , Route . extend ( { } ) ) ;
949+ return this . visit ( '/' ) . then ( ( ) => {
950+ assert . ok ( true ) ;
951+ } ) ;
952+ }
944953}
945954
946955moduleFor ( 'Route - model loading' , LoadingTests ) ;
@@ -968,6 +977,12 @@ moduleFor(
968977 return routePromises . get ( name ) ;
969978 }
970979
980+ // if (name.indexOf('loading')) {
981+ // let route = getRoute(name);
982+ // routes.set(name, route);
983+ // return route;
984+ // }
985+
971986 let promise = new RSVP . Promise ( ( resolve ) => {
972987 setTimeout ( ( ) => {
973988 if ( isDestroying ( this ) ) {
0 commit comments