-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Autotracking -- make the model property on the controller 'tr…
…acked'
- Loading branch information
1 parent
3c4bca4
commit f2d49c7
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/ember/tests/routing/route_controller_integration_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
EMBER_NATIVE_DECORATOR_SUPPORT, | ||
EMBER_METAL_TRACKED_PROPERTIES, | ||
} from '@ember/canary-features'; | ||
import { Route } from '@ember/-internals/routing'; | ||
import Controller from '@ember/controller'; | ||
import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; | ||
|
||
if (EMBER_METAL_TRACKED_PROPERTIES && EMBER_NATIVE_DECORATOR_SUPPORT) { | ||
moduleFor( | ||
'Route <-> Controller Integration', | ||
class extends ApplicationTestCase { | ||
['@test properties that autotrack the model update when the model changes'](assert) { | ||
assert.expect(2); | ||
|
||
this.router.map(function() { | ||
this.route('home', { path: '/home/:id' }); | ||
}); | ||
|
||
class HomeRoute extends Route { | ||
async model({ id }) { | ||
return { value: id }; | ||
} | ||
} | ||
|
||
class HomeController extends Controller { | ||
get derivedProperty() { | ||
return this.model.value || 'value is unset'; | ||
} | ||
} | ||
|
||
this.add('route:home', HomeRoute); | ||
this.add('controller:home', HomeController); | ||
this.addTemplate('home', '<h3 class="derivedProperty">{{this.derivedProperty}}</h3>'); | ||
|
||
return this.visit('/home/2') | ||
.then(() => { | ||
assert.equal( | ||
document.querySelector('h3').innerText, | ||
'2', | ||
'the derived property matches the id' | ||
); | ||
}) | ||
.then(() => { | ||
return this.visit('/home/3').then(() => { | ||
assert.equal( | ||
document.querySelector('h3').innerText, | ||
'3', | ||
'the derived property matches the id' | ||
); | ||
}); | ||
}); | ||
} | ||
} | ||
); | ||
} |