From 6e79a6a1b0025f116936aa1eda38feace9d0072f Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Mon, 13 Mar 2023 02:05:23 -0700 Subject: [PATCH] feat: add tests for the refresh method --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 4 +- test-app/app/routes/application.js | 11 ++++ test-app/app/templates/application.hbs | 3 ++ .../addon/components/hello-name.hbs | 31 ++++++++++- .../ember-blog/addon/components/hello-name.js | 26 +++++++++- test-app/lib/ember-blog/addon/routes/new.js | 19 +++++++ .../lib/ember-blog/addon/templates/new.hbs | 4 ++ .../routeable-engine-demo-refresh-test.js | 48 ++++++++++++++++++ 9 files changed, 141 insertions(+), 5 deletions(-) delete mode 100644 .DS_Store create mode 100644 test-app/app/routes/application.js create mode 100644 test-app/lib/ember-blog/addon/routes/new.js create mode 100644 test-app/tests/acceptance/routeable-engine-demo-refresh-test.js diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 84e5802f02f5e79d99f22cf56e9de033d039c899..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK-EI;=6h2dET~JdrChg_kn0V0=8e4l|OprnhiGPu*7iuV5XuG=X5Lk*8G2HkL z>KphdK7kM71L${Vrp@jGx5k(`WX?A;`<>Y{-|X%%L?kN1_7+irh#VBgY#wfo@pUdU zwq$y)0fibPtOxSY3#2#0wH;OgtH8gf0KdD-)S@J$gcqX`h}^ohtMkwL01ls7PIEr=mZnqO-`_rvXJN z-metzI(0Cb2j8bnWEUW66YU`|z!*h(OM~PXYVKcRb9cZE!R^rdxqMb3&d<|B%w&&h zm`wwI-h5b%c+3^tL8^N+kuTSV$gh*mO|TBhxE@yKklw)`gRkZ@yPkq|iO1!jdX4T= zl^)H{kW~;)OobdpoR9L|MLHxRmM*MkE&d!Fry|X>paL2p5CDd=_tfCa@JMTQztN-%yE(aoXsIfeeq)%MmMd3Ss#HlhjW>ioDzjp>lMFh3Y1z0vX)rcOL{Ue}cu+A#*R~7gJ( diff --git a/.gitignore b/.gitignore index ee7f375..65fb729 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ node_modules/ # misc npm-debug.log* yarn-error.log -.DS_Store +/.DS_Store # yarn .pnp.* @@ -17,4 +17,4 @@ yarn-error.log !.yarn/plugins !.yarn/releases !.yarn/sdks -!.yarn/versions \ No newline at end of file +!.yarn/versions diff --git a/test-app/app/routes/application.js b/test-app/app/routes/application.js new file mode 100644 index 0000000..bf9934e --- /dev/null +++ b/test-app/app/routes/application.js @@ -0,0 +1,11 @@ +import Route from '@ember/routing/route'; + +let count = 0; + +export default class extends Route { + model() { + return { + count: count++, + }; + } +} diff --git a/test-app/app/templates/application.hbs b/test-app/app/templates/application.hbs index 671c7dd..0a3a51c 100644 --- a/test-app/app/templates/application.hbs +++ b/test-app/app/templates/application.hbs @@ -1,4 +1,7 @@

Ember Engines Demo

+ + {{@model.count}} + Routeless Engine | Routeable Engine | diff --git a/test-app/lib/ember-blog/addon/components/hello-name.hbs b/test-app/lib/ember-blog/addon/components/hello-name.hbs index 8910ec7..ef8a127 100644 --- a/test-app/lib/ember-blog/addon/components/hello-name.hbs +++ b/test-app/lib/ember-blog/addon/components/hello-name.hbs @@ -1,3 +1,30 @@ -
- Hello, {{@name}}! +
+ + Hello, + {{@name}}! + + + + + + +
\ No newline at end of file diff --git a/test-app/lib/ember-blog/addon/components/hello-name.js b/test-app/lib/ember-blog/addon/components/hello-name.js index 5d2a7da..04ec5d3 100644 --- a/test-app/lib/ember-blog/addon/components/hello-name.js +++ b/test-app/lib/ember-blog/addon/components/hello-name.js @@ -1,9 +1,14 @@ -import { later, cancel } from '@ember/runloop'; import Component from '@glimmer/component'; +import { later, cancel } from '@ember/runloop'; import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; +import { inject as service } from '@ember/service'; export default class extends Component { + @service router; + @tracked name = this.args.name; + @tracked clickCount = 0; constructor() { super(...arguments); @@ -20,4 +25,23 @@ export default class extends Component { cancel(this._later); super.willDestroy(...arguments); } + + @action click() { + this.clickCount++; + } + + @action + refresh() { + this.router.refresh(); + } + + @action + refreshRoute() { + this.router.refresh('new'); + } + + @action + refreshExternal() { + this.router.refreshExternal('home'); + } } diff --git a/test-app/lib/ember-blog/addon/routes/new.js b/test-app/lib/ember-blog/addon/routes/new.js new file mode 100644 index 0000000..77ec8b4 --- /dev/null +++ b/test-app/lib/ember-blog/addon/routes/new.js @@ -0,0 +1,19 @@ +import { inject as service } from '@ember/service'; +import Route from '@ember/routing/route'; + +let count = 0; + +export default class extends Route { + @service exampleService; + + model() { + // cause a service to be instantiated, so that our tests can + // confirm that it gets cleaned up + this.exampleService; + + return { + name: 'Derek Zoolander', + count: count++, + }; + } +} diff --git a/test-app/lib/ember-blog/addon/templates/new.hbs b/test-app/lib/ember-blog/addon/templates/new.hbs index eb39d4c..c54238c 100644 --- a/test-app/lib/ember-blog/addon/templates/new.hbs +++ b/test-app/lib/ember-blog/addon/templates/new.hbs @@ -1,6 +1,10 @@
New Route!! + + {{@model.count}} + + diff --git a/test-app/tests/acceptance/routeable-engine-demo-refresh-test.js b/test-app/tests/acceptance/routeable-engine-demo-refresh-test.js new file mode 100644 index 0000000..8abc3a8 --- /dev/null +++ b/test-app/tests/acceptance/routeable-engine-demo-refresh-test.js @@ -0,0 +1,48 @@ +import { module, test } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import { visit, find, click } from '@ember/test-helpers'; + +module('Acceptance | routeless engine demo', function (hooks) { + setupApplicationTest(hooks); + + module('Engine Router Service Refresh Method', function () { + test('refresh without params triggers refresh with current route', async function (assert) { + await visit('/routable-engine-demo/ember-blog/new'); + + let counter = await find('.route-refresh-counter').textContent; + assert.dom('.route-refresh-counter').hasText(counter); + await click('.refresh'); + + counter = parseInt(counter, 10); + counter = ++counter; + counter = counter.toString(); + assert.dom('.route-refresh-counter').hasText(counter); + }); + + test('refresh with params triggers refresh on provided route', async function (assert) { + await visit('/routable-engine-demo/ember-blog/new'); + + let counter = await find('.route-refresh-counter').textContent; + assert.dom('.route-refresh-counter').hasText(counter); + await click('.refresh-route'); + + counter = parseInt(counter, 10); + counter = ++counter; + counter = counter.toString(); + assert.dom('.route-refresh-counter').hasText(counter); + }); + + test('refresh external route', async function (assert) { + await visit('/routable-engine-demo/ember-blog/new'); + + let counter = await find('.route-refresh-counter').textContent; + assert.dom('.global-refresh-counter').hasText(counter); + await click('.refresh-external'); + + counter = parseInt(counter, 10); + counter = ++counter; + counter = counter.toString(); + assert.dom('.global-refresh-counter').hasText(counter); + }); + }); +});