|
1 | 1 | import Controller from 'ember-runtime/controllers/controller';
|
| 2 | +import RSVP from 'ember-runtime/ext/rsvp'; |
2 | 3 | import Route from 'ember-routing/system/route';
|
3 | 4 | import run from 'ember-metal/run_loop';
|
4 | 5 | import get from 'ember-metal/property_get';
|
@@ -2491,11 +2492,13 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
|
2491 | 2492 | });
|
2492 | 2493 |
|
2493 | 2494 | QUnit.test('queryParams are updated when a controller property is set and the route is refreshed. Issue #13263 ', function() {
|
2494 |
| - Ember.TEMPLATES.application = compile( |
2495 |
| - '<button id="test-button" {{action \'increment\'}}>Increment</button>' + |
2496 |
| - '<span id="test-value">{{foo}}</span>' + |
2497 |
| - '{{outlet}}' |
2498 |
| - ); |
| 2495 | + setTemplates({ |
| 2496 | + application: compile( |
| 2497 | + '<button id="test-button" {{action \'increment\'}}>Increment</button>' + |
| 2498 | + '<span id="test-value">{{foo}}</span>' + |
| 2499 | + '{{outlet}}' |
| 2500 | + ) |
| 2501 | + }); |
2499 | 2502 | App.ApplicationController = Controller.extend({
|
2500 | 2503 | queryParams: ['foo'],
|
2501 | 2504 | foo: 1,
|
@@ -3222,6 +3225,132 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
|
3222 | 3225 | equal(get(controller, 'foo'), undefined);
|
3223 | 3226 | });
|
3224 | 3227 | }
|
| 3228 | +QUnit.test('when refreshModel is true and loading action returns false, model hook will rerun when QPs change even if previous did not finish', function() { |
| 3229 | + expect(6); |
| 3230 | + |
| 3231 | + var appModelCount = 0; |
| 3232 | + var promiseResolve; |
| 3233 | + |
| 3234 | + App.ApplicationRoute = Route.extend({ |
| 3235 | + queryParams: { |
| 3236 | + 'appomg': { |
| 3237 | + defaultValue: 'applol' |
| 3238 | + } |
| 3239 | + }, |
| 3240 | + model(params) { |
| 3241 | + appModelCount++; |
| 3242 | + } |
| 3243 | + }); |
| 3244 | + |
| 3245 | + App.IndexController = Controller.extend({ |
| 3246 | + queryParams: ['omg'] |
| 3247 | + // uncommon to not support default value, but should assume undefined. |
| 3248 | + }); |
| 3249 | + |
| 3250 | + var indexModelCount = 0; |
| 3251 | + App.IndexRoute = Route.extend({ |
| 3252 | + queryParams: { |
| 3253 | + omg: { |
| 3254 | + refreshModel: true |
| 3255 | + } |
| 3256 | + }, |
| 3257 | + actions: { |
| 3258 | + loading: function() { |
| 3259 | + return false; |
| 3260 | + } |
| 3261 | + }, |
| 3262 | + model(params) { |
| 3263 | + indexModelCount++; |
| 3264 | + if (indexModelCount === 2) { |
| 3265 | + deepEqual(params, { omg: 'lex' }); |
| 3266 | + return new RSVP.Promise(function(resolve) { |
| 3267 | + promiseResolve = resolve; |
| 3268 | + return; |
| 3269 | + }); |
| 3270 | + } else if (indexModelCount === 3) { |
| 3271 | + deepEqual(params, { omg: 'hello' }, 'Model hook reruns even if the previous one didnt finish'); |
| 3272 | + } |
| 3273 | + } |
| 3274 | + }); |
| 3275 | + |
| 3276 | + bootApplication(); |
| 3277 | + |
| 3278 | + equal(indexModelCount, 1); |
| 3279 | + |
| 3280 | + var indexController = container.lookup('controller:index'); |
| 3281 | + setAndFlush(indexController, 'omg', 'lex'); |
| 3282 | + equal(indexModelCount, 2); |
| 3283 | + |
| 3284 | + setAndFlush(indexController, 'omg', 'hello'); |
| 3285 | + equal(indexModelCount, 3); |
| 3286 | + run(function() { |
| 3287 | + promiseResolve(); |
| 3288 | + }); |
| 3289 | + equal(get(indexController, 'omg'), 'hello', 'At the end last value prevails'); |
| 3290 | +}); |
| 3291 | + |
| 3292 | +QUnit.test('when refreshModel is true and loading action does not return false, model hook will not rerun when QPs change even if previous did not finish', function() { |
| 3293 | + expect(7); |
| 3294 | + |
| 3295 | + var appModelCount = 0; |
| 3296 | + var promiseResolve; |
| 3297 | + |
| 3298 | + App.ApplicationRoute = Route.extend({ |
| 3299 | + queryParams: { |
| 3300 | + 'appomg': { |
| 3301 | + defaultValue: 'applol' |
| 3302 | + } |
| 3303 | + }, |
| 3304 | + model(params) { |
| 3305 | + appModelCount++; |
| 3306 | + } |
| 3307 | + }); |
| 3308 | + |
| 3309 | + App.IndexController = Controller.extend({ |
| 3310 | + queryParams: ['omg'] |
| 3311 | + // uncommon to not support default value, but should assume undefined. |
| 3312 | + }); |
| 3313 | + |
| 3314 | + var indexModelCount = 0; |
| 3315 | + App.IndexRoute = Route.extend({ |
| 3316 | + queryParams: { |
| 3317 | + omg: { |
| 3318 | + refreshModel: true |
| 3319 | + } |
| 3320 | + }, |
| 3321 | + model(params) { |
| 3322 | + indexModelCount++; |
| 3323 | + |
| 3324 | + if (indexModelCount === 2) { |
| 3325 | + deepEqual(params, { omg: 'lex' }); |
| 3326 | + return new RSVP.Promise(function(resolve) { |
| 3327 | + promiseResolve = resolve; |
| 3328 | + return; |
| 3329 | + }); |
| 3330 | + } else if (indexModelCount === 3) { |
| 3331 | + ok(false, 'shouldnt get here'); |
| 3332 | + } |
| 3333 | + } |
| 3334 | + }); |
| 3335 | + |
| 3336 | + bootApplication(); |
| 3337 | + |
| 3338 | + equal(appModelCount, 1); |
| 3339 | + equal(indexModelCount, 1); |
| 3340 | + |
| 3341 | + var indexController = container.lookup('controller:index'); |
| 3342 | + setAndFlush(indexController, 'omg', 'lex'); |
| 3343 | + |
| 3344 | + equal(appModelCount, 1); |
| 3345 | + equal(indexModelCount, 2); |
| 3346 | + |
| 3347 | + setAndFlush(indexController, 'omg', 'hello'); |
| 3348 | + equal(get(indexController, 'omg'), 'hello', ' value was set'); |
| 3349 | + equal(indexModelCount, 2); |
| 3350 | + run(function() { |
| 3351 | + promiseResolve(); |
| 3352 | + }); |
| 3353 | +}); |
3225 | 3354 |
|
3226 | 3355 | QUnit.test('warn user that routes query params configuration must be an Object, not an Array', function() {
|
3227 | 3356 | expect(1);
|
|
0 commit comments