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

Fixes routing bug with same route, different params #4

Merged
merged 2 commits into from
Apr 24, 2018
Merged
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
2 changes: 1 addition & 1 deletion addon/ext/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Mixin from '@ember/object/mixin';

export default Mixin.create({
activate() {
setupController() {
this.get('perfService').routeActivated(this);
this._super(...arguments);
},
Expand Down
38 changes: 38 additions & 0 deletions tests/acceptance/event-body-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,44 @@ test('Initial load, then drilling in, then pivoting', function(assert) {
});
});

test('Nested resource with the same name ', function(assert) {
// This test covers the bug here: https://github.com/mike-north/ember-perf/issues/83

let datas = [];
let testStartTime = performanceNow();

application.perfService.on('transitionComplete', (data) => {
datas.push(data);
});

visit('/articles/1');

andThen(function() {
assert.ok(datas, 'Data is present');
let [data] = datas;
validateEvent(assert, testStartTime, data);
assert.equal(datas.length, 1, 'Only one event fired');
});

click('a[href=\'/articles/2\']');

andThen(function() {
assert.equal(datas.length, 2, 'Only two events fired');
let data = datas[datas.length - 1];
assert.equal(data.destURL, '/articles/2', 'Intent URL is correct');
assert.equal(data.destRoute, 'articles.article', 'Intent route is correct');
});

click('a[href=\'/articles/3\']');

andThen(function() {
assert.equal(datas.length, 3, 'Only three events fired');
let data = datas[datas.length - 1];
assert.equal(data.destURL, '/articles/3', 'Intent URL is correct');
assert.equal(data.destRoute, 'articles.article', 'Intent route is correct');
});
});

test('Initial measureRender', function(assert) {
let datas = [];
let testStartTime = performanceNow();
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const Router = EmberRouter.extend({
});

Router.map(function() {
this.route('articles', function() {
this.route('article', { path: ':article_id' });
});
this.route('companies', function() {
this.route('info');
});
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/routes/articles/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// import Ember from 'ember';
import BaseRoute from '../base';

export default BaseRoute.extend({ });
7 changes: 5 additions & 2 deletions tests/dummy/app/routes/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Object from '@ember/object';
import Route from '@ember/routing/route';

export default Route.extend({

});
model(params) {
return Object.create({id: params.article_id});
}
});
9 changes: 9 additions & 0 deletions tests/dummy/app/templates/articles/article.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Availible Articles</h1>

<ul>
<li>{{#link-to 'articles.article' '1'}}Article 1{{/link-to}}</li>
<li>{{#link-to 'articles.article' '2'}}Article 2{{/link-to}}</li>
<li>{{#link-to 'articles.article' '3'}}Article 3{{/link-to}}</li>
</ul>

<h2>Article {{model.id}}</h2>
12 changes: 11 additions & 1 deletion tests/helpers/validate-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ export default function(assert, now, data, eventType = 'transition') {

if (eventType === 'transition') {
assert.equal(typeOf(data.routes), 'array', 'data.routes is an array');
assert.deepEqual(data.routes.map((r) => r.name), ['application', 'loading', 'company', 'company.loading', 'company.buildings'], 'Proper routes load');


let rs = data.routes.map((r) => r.name)

if (rs.includes('articles')) {
assert.deepEqual(rs, ['application', 'articles', 'articles.article'], 'Proper routes load for articles resource');

} else {
assert.deepEqual(rs, ['application', 'loading', 'company', 'company.loading', 'company.buildings'], 'Proper routes load for companies/buildings resource');
}

assert.equal(data.routes
.map((r) => r.startTime)
.filter((x) => typeOf(x) !== 'number'), 0, 'All route startTimes are numbers');
Expand Down