Skip to content

Commit d227442

Browse files
committedApr 17, 2018
Adds failing test to same route dif param bug
> 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
1 parent fb7d288 commit d227442

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed
 

‎tests/acceptance/event-body-test.js

+38
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,44 @@ test('Initial load, then drilling in, then pivoting', function(assert) {
136136
});
137137
});
138138

139+
test('Nested resource with the same name ', function(assert) {
140+
// This test covers the bug here: https://github.com/mike-north/ember-perf/issues/83
141+
142+
let datas = [];
143+
let testStartTime = performanceNow();
144+
145+
application.perfService.on('transitionComplete', (data) => {
146+
datas.push(data);
147+
});
148+
149+
visit('/articles/1');
150+
151+
andThen(function() {
152+
assert.ok(datas, 'Data is present');
153+
let [data] = datas;
154+
validateEvent(assert, testStartTime, data);
155+
assert.equal(datas.length, 1, 'Only one event fired');
156+
});
157+
158+
click('a[href=\'/articles/2\']');
159+
160+
andThen(function() {
161+
assert.equal(datas.length, 2, 'Only two events fired');
162+
let data = datas[datas.length - 1];
163+
assert.equal(data.destURL, '/articles/2', 'Intent URL is correct');
164+
assert.equal(data.destRoute, 'articles.article', 'Intent route is correct');
165+
});
166+
167+
click('a[href=\'/articles/3\']');
168+
169+
andThen(function() {
170+
assert.equal(datas.length, 3, 'Only three events fired');
171+
let data = datas[datas.length - 1];
172+
assert.equal(data.destURL, '/articles/3', 'Intent URL is correct');
173+
assert.equal(data.destRoute, 'articles.article', 'Intent route is correct');
174+
});
175+
});
176+
139177
test('Initial measureRender', function(assert) {
140178
let datas = [];
141179
let testStartTime = performanceNow();

‎tests/dummy/app/router.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const Router = EmberRouter.extend({
77
});
88

99
Router.map(function() {
10+
this.route('articles', function() {
11+
this.route('article', { path: ':article_id' });
12+
});
1013
this.route('companies', function() {
1114
this.route('info');
1215
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// import Ember from 'ember';
2+
import BaseRoute from '../base';
3+
4+
export default BaseRoute.extend({ });

‎tests/dummy/app/routes/base.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import Object from '@ember/object';
12
import Route from '@ember/routing/route';
23

34
export default Route.extend({
4-
5-
});
5+
model(params) {
6+
return Object.create({id: params.article_id});
7+
}
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1>Availible Articles</h1>
2+
3+
<ul>
4+
<li>{{#link-to 'articles.article' '1'}}Article 1{{/link-to}}</li>
5+
<li>{{#link-to 'articles.article' '2'}}Article 2{{/link-to}}</li>
6+
<li>{{#link-to 'articles.article' '3'}}Article 3{{/link-to}}</li>
7+
</ul>
8+
9+
<h2>Article {{model.id}}</h2>

‎tests/helpers/validate-event.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ export default function(assert, now, data, eventType = 'transition') {
1212

1313
if (eventType === 'transition') {
1414
assert.equal(typeOf(data.routes), 'array', 'data.routes is an array');
15-
assert.deepEqual(data.routes.map((r) => r.name), ['application', 'loading', 'company', 'company.loading', 'company.buildings'], 'Proper routes load');
15+
16+
17+
let rs = data.routes.map((r) => r.name)
18+
19+
if (rs.includes('articles')) {
20+
assert.deepEqual(rs, ['application', 'articles', 'articles.article'], 'Proper routes load for articles resource');
21+
22+
} else {
23+
assert.deepEqual(rs, ['application', 'loading', 'company', 'company.loading', 'company.buildings'], 'Proper routes load for companies/buildings resource');
24+
}
25+
1626
assert.equal(data.routes
1727
.map((r) => r.startTime)
1828
.filter((x) => typeOf(x) !== 'number'), 0, 'All route startTimes are numbers');

0 commit comments

Comments
 (0)