[fix] Make route-idle helper functionality like whenRouteIdle
MODIFY
addon/scheduler.ts
addon/scheduler.ts
@@ -55,6 +55,7 @@ export function beginTransition(): void {
waiter.endAsync(scheduledWorkToken);
mark('appSchedulerEnd');
measure('appScheduler', 'appSchedulerStart', 'appSchedulerEnd');
+ scheduler.isIdle = true;
});
});
scheduler.isIdle = false;
@@ -70,7 +71,6 @@ export function beginTransition(): void {
*/
export function endTransition(): void {
_whenRouteDidChange.resolve();
- scheduler.isIdle = true;
mark('appSchedulerStart');
}

MODIFY
tests/acceptance/deferred-render-test.js
tests/acceptance/deferred-render-test.js
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
-import { visit, currentRouteName, click } from '@ember/test-helpers';
-import { setupRouter } from 'ember-app-scheduler';
+import {
+ visit,
+ currentRouteName,
+ click,
+ settled,
+ waitFor,
+} from '@ember/test-helpers';
+import {
+ beginTransition,
+ endTransition,
+ setupRouter,
+} from 'ember-app-scheduler';
['router:main', 'service:router'].forEach((dependencyKey) => {
module(
@@ -43,6 +53,47 @@ import { setupRouter } from 'ember-app-scheduler';
assert.strictEqual(currentRouteName(), 'content-paint');
assert.dom('.only-when-route-idle').exists();
});
+
+ module('Helper | route-idle', function () {
+ test('visiting route renders deferred content via route-idle helper', async function (assert) {
+ assert.expect(3);
+
+ await visit('/route-idle-helper');
+
+ beginTransition();
+ await waitFor('.only-when-route-not-idle');
+ assert.dom('.only-when-route-not-idle').exists();
+ endTransition();
+ await settled();
+
+ assert.strictEqual(currentRouteName(), 'route-idle-helper');
+
+ await waitFor('.only-when-route-idle');
+
+ assert.dom('.only-when-route-idle').exists();
+ });
+
+ test('visiting route and refresh renders deferred content via route-idle helper', async function (assert) {
+ assert.expect(5);
+
+ const controller = this.owner.lookup('controller:route-idle-helper');
+
+ await visit('/route-idle-helper');
+
+ await waitFor('.only-when-route-idle');
+ assert.dom('.only-when-route-idle').exists();
+
+ assert.strictEqual(controller.refresh, 0);
+
+ await click('.refresh-button');
+ assert.strictEqual(currentRouteName(), 'route-idle-helper');
+
+ assert.strictEqual(controller.refresh, 1);
+
+ await waitFor('.only-when-route-idle');
+ assert.dom('.only-when-route-idle').exists();
+ });
+ });
}
);
});

MODIFY
tests/integration/helpers/route-idle-test.js
tests/integration/helpers/route-idle-test.js
-import { render, settled } from '@ember/test-helpers';
+import { render, settled, waitFor } from '@ember/test-helpers';
import { beginTransition, endTransition } from 'ember-app-scheduler';
import { setupRenderingTest } from 'ember-qunit';
import { hbs } from 'ember-cli-htmlbars';
@@ -24,6 +24,8 @@ module('Integration | Helper | route-idle', function (hooks) {
await settled();
+ await waitFor('#i-exist');
+
assert.dom('#i-exist').exists();
await settled();
@@ -51,6 +53,8 @@ module('Integration | Helper | route-idle', function (hooks) {
await settled();
+ await waitFor('#i-exist');
+
assert
.dom('#i-exist')
.exists('deferred content is rendered after initial transition finishes');
@@ -74,6 +78,8 @@ module('Integration | Helper | route-idle', function (hooks) {
await settled();
+ await waitFor('#i-exist');
+
assert
.dom('#i-exist')
.exists('deferred content is rendered after second transition finishes');

[fix] Make route-idle helper functionality like whenRouteIdle (#1208)