Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
better test of helper
Browse files Browse the repository at this point in the history
Previously, we were setting the locale by navigating to
`/in/:locale`. Unfortunately, that's not a very good test of the
`{{t}}` helper because it causes the whole template to be
rerendered. Instead, we use an `{{action}}` to trigger the locale
change and ensure that the *same* template gets updated.
  • Loading branch information
jamesarosen committed Jun 13, 2015
1 parent f2c3168 commit a42a845
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
8 changes: 5 additions & 3 deletions tests/acceptance/t-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var app;
module('Acceptance: {{t}} Helper', {
beforeEach: function() {
app = startApp();
visit('/in/en');
visit('/');
},

afterEach: function() {
Expand Down Expand Up @@ -44,7 +44,9 @@ test('updates when dynamic interpolations change', function(assert) {
});

test('updates when the locale changes', function(assert) {
visit('/in/es');
click('.switch-to-es');

assert.textIs('.no-interpolations', 'texto sin interpolaciones');
andThen(function() {
assert.textIs('.no-interpolations', 'texto sin interpolaciones');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import $ from "jquery";

export default Ember.Controller.extend({

i18n: Ember.inject.service(),
clickCount: 0,
dynamicKey: 'no.interpolations',

actions: {
increment: function() {
Expand All @@ -12,6 +14,10 @@ export default Ember.Controller.extend({

changeDynamicKey(newKey) {
this.set('dynamicKey', newKey);
},

switchLocale(locale) {
this.set('i18n.locale', locale);
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var Router = Ember.Router.extend({
});

Router.map(function() {
this.route('translate', { path: '/in/:locale' });
});

export default Router;
20 changes: 0 additions & 20 deletions tests/dummy/app/routes/translate.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@

<span class='dynamic-key'>{{t dynamicKey}}</span>
</section>

<section>
<button class='switch-to-es' {{action "switchLocale" "es"}}>Switch to Spanish</button>
</section>

0 comments on commit a42a845

Please sign in to comment.