From 3a60328001164b6a67ec2a5465ce0ceb43110cf3 Mon Sep 17 00:00:00 2001 From: Ryan LaBouve Date: Mon, 16 Apr 2018 23:28:53 -0500 Subject: [PATCH 1/2] Failing tests --- tests/acceptance/customization-test.js | 40 +++++++++++++++++++ .../app/controllers/company/buildings.js | 11 +++++ tests/dummy/app/routes/company/buildings.js | 6 +++ .../dummy/app/templates/company/buildings.hbs | 4 +- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/dummy/app/controllers/company/buildings.js diff --git a/tests/acceptance/customization-test.js b/tests/acceptance/customization-test.js index e35cf1b7..0a5fc426 100644 --- a/tests/acceptance/customization-test.js +++ b/tests/acceptance/customization-test.js @@ -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'); + }); +}); diff --git a/tests/dummy/app/controllers/company/buildings.js b/tests/dummy/app/controllers/company/buildings.js new file mode 100644 index 00000000..eb8e31fb --- /dev/null +++ b/tests/dummy/app/controllers/company/buildings.js @@ -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'); + } + } +}); diff --git a/tests/dummy/app/routes/company/buildings.js b/tests/dummy/app/routes/company/buildings.js index cb41259a..6351b16b 100644 --- a/tests/dummy/app/routes/company/buildings.js +++ b/tests/dummy/app/routes/company/buildings.js @@ -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(() => { diff --git a/tests/dummy/app/templates/company/buildings.hbs b/tests/dummy/app/templates/company/buildings.hbs index f9171747..0525ab0a 100644 --- a/tests/dummy/app/templates/company/buildings.hbs +++ b/tests/dummy/app/templates/company/buildings.hbs @@ -5,5 +5,7 @@ {{/each}} - {{outlet}} + + + From bc52e8b9e580e976d2ae8de8a5778aa21b9edb01 Mon Sep 17 00:00:00 2001 From: Ryan LaBouve Date: Mon, 16 Apr 2018 23:29:06 -0500 Subject: [PATCH 2/2] Fix --- addon/services/ember-perf.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addon/services/ember-perf.js b/addon/services/ember-perf.js index aba899b1..feaaa8fc 100644 --- a/addon/services/ember-perf.js +++ b/addon/services/ember-perf.js @@ -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');