Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test case for lazily loaded engines with loading states #19266

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@ember/-internals/routing/lib/utils.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export function stashParamNames(router: EmberRouter, routeInfos: PrivateRouteInf


routeInfo['_names'] = names; routeInfo['_names'] = names;


let route = routeInfo.route!; let route = routeInfo.route;
if (route !== undefined) {
route._stashNames(routeInfo, dynamicParent!); route._stashNames(routeInfo, dynamicParent!);
} }
}


routeInfos['_namesStashed'] = true; routeInfos['_namesStashed'] = true;
} }
Expand Down
116 changes: 60 additions & 56 deletions packages/ember/tests/routing/model_loading_test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { Object as EmberObject, A as emberA } from '@ember/-internals/runtime';
import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers';
import { run } from '@ember/runloop'; import { run } from '@ember/runloop';
import { computed, set } from '@ember/-internals/metal'; import { computed, set } from '@ember/-internals/metal';
import { isDestroying } from '@glimmer/destroyable';
import RSVP from 'rsvp';


let originalConsoleError; let originalConsoleError;


moduleFor( class LoadingTests extends ApplicationTestCase {
'Route - model loading',
class extends ApplicationTestCase {
constructor() { constructor() {
super(...arguments); super(...arguments);
this.addTemplate('home', '<h3 class="hours">Hours</h3>'); this.addTemplate('home', '<h3 class="hours">Hours</h3>');
Expand Down Expand Up @@ -137,11 +137,7 @@ moduleFor(
return this.visit('/').then(() => { return this.visit('/').then(() => {
let text = this.$('ul li:nth-child(3)').text(); let text = this.$('ul li:nth-child(3)').text();


assert.equal( assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
text,
'Sunday: Noon to 6pm',
'The template was rendered with the hours context'
);
}); });
} }


Expand All @@ -162,11 +158,7 @@ moduleFor(
let homeRoute = this.applicationInstance.lookup('route:home'); let homeRoute = this.applicationInstance.lookup('route:home');
let homeController = this.applicationInstance.lookup('controller:home'); let homeController = this.applicationInstance.lookup('controller:home');


assert.equal( assert.equal(homeRoute.controller, homeController, 'route controller is the home controller');
homeRoute.controller,
homeController,
'route controller is the home controller'
);
}); });
} }


Expand All @@ -190,11 +182,7 @@ moduleFor(
let myController = this.applicationInstance.lookup('controller:myController'); let myController = this.applicationInstance.lookup('controller:myController');
let text = this.$('p').text(); let text = this.$('p').text();


assert.equal( assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
homeRoute.controller,
myController,
'route controller is set by controllerName'
);
assert.equal( assert.equal(
text, text,
'foo', 'foo',
Expand Down Expand Up @@ -236,11 +224,7 @@ moduleFor(
let myController = this.applicationInstance.lookup('controller:myController'); let myController = this.applicationInstance.lookup('controller:myController');
let text = this.$('p').text(); let text = this.$('p').text();


assert.equal( assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
homeRoute.controller,
myController,
'route controller is set by controllerName'
);


assert.equal( assert.equal(
text, text,
Expand Down Expand Up @@ -285,11 +269,7 @@ moduleFor(
let myController = this.applicationInstance.lookup('controller:myController'); let myController = this.applicationInstance.lookup('controller:myController');
let text = this.$('p').text(); let text = this.$('p').text();


assert.equal( assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
homeRoute.controller,
myController,
'route controller is set by controllerName'
);


assert.equal( assert.equal(
text, text,
Expand Down Expand Up @@ -317,19 +297,12 @@ moduleFor(
}) })
); );


this.addTemplate( this.addTemplate('home', '<ul>{{#each this.hours as |entry|}}<li>{{entry}}</li>{{/each}}</ul>');
'home',
'<ul>{{#each this.hours as |entry|}}<li>{{entry}}</li>{{/each}}</ul>'
);


return this.visit('/').then(() => { return this.visit('/').then(() => {
let text = this.$('ul li:nth-child(3)').text(); let text = this.$('ul li:nth-child(3)').text();


assert.equal( assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
text,
'Sunday: Noon to 6pm',
'The template was rendered with the hours context'
);
}); });
} }


Expand Down Expand Up @@ -391,19 +364,12 @@ moduleFor(
}) })
); );


this.addTemplate( this.addTemplate('home', '<ul>{{#each this.hours as |entry|}}<li>{{entry}}</li>{{/each}}</ul>');
'home',
'<ul>{{#each this.hours as |entry|}}<li>{{entry}}</li>{{/each}}</ul>'
);


return this.visit('/').then(() => { return this.visit('/').then(() => {
let text = this.$('ul li:nth-child(3)').text(); let text = this.$('ul li:nth-child(3)').text();


assert.equal( assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
text,
'Sunday: Noon to 6pm',
'The template was rendered with the hours context'
);
}); });
} }


Expand Down Expand Up @@ -863,11 +829,7 @@ moduleFor(
run(() => router.send('showPost', { id: '2' })); run(() => router.send('showPost', { id: '2' }));
run(() => router.send('editPost')); run(() => router.send('editPost'));
assert.equal(editCount, 2, 'set up the edit route twice without failure'); assert.equal(editCount, 2, 'set up the edit route twice without failure');
assert.deepEqual( assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context');
editedPostIds,
['1', '2'],
'modelFor posts.post returns the right context'
);
}); });
} }


Expand All @@ -891,11 +853,7 @@ moduleFor(
return this.visit('/').then(() => { return this.visit('/').then(() => {
let routerService = this.applicationInstance.lookup('service:router'); let routerService = this.applicationInstance.lookup('service:router');
assert.equal(routerService.currentRouteName, 'index', 'currentPath is index'); assert.equal(routerService.currentRouteName, 'index', 'currentPath is index');
assert.equal( assert.equal('currentPath' in model, false, 'should have defined currentPath on controller');
'currentPath' in model,
false,
'should have defined currentPath on controller'
);
}); });
} }


Expand Down Expand Up @@ -984,4 +942,50 @@ moduleFor(
}); });
} }
} }

moduleFor('Route - model loading', LoadingTests);

moduleFor(
'Route - model loading (simulated within lazy engine)',
class extends LoadingTests {
get routerOptions() {
return {
location: 'none',
setupRouter() {
this._super(...arguments);
let getRoute = this._routerMicrolib.getRoute;
this._enginePromises = Object.create(null);
this._resolvedEngines = Object.create(null);

let routes = new Map();
let routePromises = new Map();
this._routerMicrolib.getRoute = (name) => {
if (routes.has(name)) {
return routes.get(name);
}

if (routePromises.has(name)) {
return routePromises.get(name);
}

let promise = new RSVP.Promise((resolve) => {
setTimeout(() => {
if (isDestroying(this)) {
return;
}

let route = getRoute(name);

routes.set(name, route);
resolve(route);
}, 10);
});
routePromises.set(name, promise);

return promise;
};
},
};
}
}
); );