Skip to content

Commit

Permalink
Adds failing test to same route dif param bug
Browse files Browse the repository at this point in the history
> The first one is thrown when transitioning between routes with the same name but different params (e.g. from /articles/1 to /articles/2). The error is:

mike-north#83
  • Loading branch information
ryanlabouve committed Apr 17, 2018
1 parent fb7d288 commit d227442
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
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 d227442

Please sign in to comment.