Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from ryanlabouve/ryanlabouve/fix-endtime
Browse files Browse the repository at this point in the history
Fixes routing bug with same route, different params
  • Loading branch information
ryanlabouve authored Apr 24, 2018
2 parents 42de747 + 4428988 commit a14b3a4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
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

0 comments on commit a14b3a4

Please sign in to comment.