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 #3 from ryanlabouve/ryanlabouve/fix-routing-issues
Browse files Browse the repository at this point in the history
Fix routing bug with QP's
  • Loading branch information
ryanlabouve authored Apr 24, 2018
2 parents 054a505 + bc52e8b commit 42de747
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
5 changes: 4 additions & 1 deletion addon/services/ember-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export default Base.extend(Evented, {
return;
}
transitionInfo.promise._emberPerfTransitionId = transitionCounter++;
let transitionRoute = transitionInfo.promise.targetName || get(transitionInfo.promise, 'intent.name');
let transitionRoute = transitionInfo.promise.targetName ||
get(transitionInfo.promise, 'intent.name') ||
[...get(transitionInfo.promise, 'state.handlerInfos')].slice(-1)[0].name

let transitionCtxt = get(transitionInfo.promise, 'intent.contexts');
let hasTransitionCtxt = transitionCtxt && transitionCtxt[0];
let transitionUrl = get(transitionInfo.promise, 'intent.url');
Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance/customization-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,43 @@ test('Initial load, then toggling additional views', function(assert) {
assert.equal(transitionData.viewData.length, viewsCountWhenEventFired, 'transitionData should not be mutated');
});
});

test('Initial load, then refreshing the model via QP', function(assert) {
assert.expect(9);

let dataCount = 0;
let lastDestURL;

application.perfService.on('transitionComplete', (data) => {
dataCount++;
lastDestURL = data.destURL;
});

visit('/company/1/buildings');

andThen(function() {
assert.equal(dataCount, 1, 'Only one event has been fired for the initial load');
assert.equal(currentURL(), '/company/1/buildings', 'We are on the correct initial URL');
assert.equal(lastDestURL, '/company/1/buildings', 'We are sending the correct route as a destination');
});

click('.btn-useless-qp');

andThen(function() {
assert.equal(currentURL(), '/company/1/buildings?uselessQP=alpha');
assert.equal(dataCount, 2, 'The second event has been recorded for the QP model refresh');
assert.equal(lastDestURL, '/company/1/buildings', 'We are sending the correct route as a destination');
});

// This would cause an error to be thrown because there
// was no targetName or intent for the transition
// see https://github.com/mike-north/ember-perf/issues/22
click('.btn-useless-qp');
click('.btn-useless-qp');

andThen(function() {
assert.equal(currentURL(), '/company/1/buildings?uselessQP=alpha', 'The URL is correct');
assert.equal(dataCount, 4, 'Four events have been fired');
assert.equal(lastDestURL, '/company/1/buildings', 'We are sending the correct route as a destination');
});
});
11 changes: 11 additions & 0 deletions tests/dummy/app/controllers/company/buildings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Controller from '@ember/controller';

export default Controller.extend({
queryParams: ['uselessQP'],

actions: {
toggleUselessQP() {
this.set('uselessQP', this.get('uselessQP') === 'alpha' ? 'beta' : 'alpha');
}
}
});
6 changes: 6 additions & 0 deletions tests/dummy/app/routes/company/buildings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const {
} = Ember;

export default Route.extend({
queryParams: {
uselessQP: {
refreshModel: true
}
},

model() {
let buildingIds = get(this.modelFor('company'), 'buildings');
return randomWait(testing ? 4 : 2400, testing ? 2 : 300).then(() => {
Expand Down
4 changes: 3 additions & 1 deletion tests/dummy/app/templates/company/buildings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
{{/each}}
</ul>


{{outlet}}

<button class="btn-useless-qp" {{action "toggleUselessQP"}}>Bloop</button>

0 comments on commit 42de747

Please sign in to comment.