Skip to content

Commit

Permalink
[Glimmer2] Add tests for bound {{loc}} behavior
Browse files Browse the repository at this point in the history
Tests INUR cycle for bound params. Fixes emberjs#13132.
  • Loading branch information
code0100fun committed Mar 19, 2016
1 parent a358c59 commit 1de062d
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions packages/ember-glimmer/tests/integration/helpers/loc-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RenderingTest, moduleFor } from '../../utils/test-case';
import { set } from 'ember-metal/property_set';
import Ember from 'ember-metal/core';

moduleFor('Helpers test: {{loc}}', class extends RenderingTest {
Expand All @@ -7,7 +8,8 @@ moduleFor('Helpers test: {{loc}}', class extends RenderingTest {
super();
this.oldString = Ember.STRINGS;
Ember.STRINGS = {
'_Howdy Friend': 'Hallo Freund'
'Hello Friend': 'Hallo Freund',
'Hello': 'Hallo, %@'
};
}

Expand All @@ -23,7 +25,7 @@ moduleFor('Helpers test: {{loc}}', class extends RenderingTest {
}

['@test it localizes a simple string']() {
this.render(`{{loc "_Howdy Friend"}}`);
this.render(`{{loc "Hello Friend"}}`);
this.assertText('Hallo Freund', 'the localized string is correct');
this.runTask(() => this.rerender());
this.assertText('Hallo Freund', 'the localized string is correct after rerender');
Expand All @@ -36,4 +38,51 @@ moduleFor('Helpers test: {{loc}}', class extends RenderingTest {
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender');
}

['@test it updates when bound params change']() {
this.render(`{{loc simple}} - {{loc personal 'Mr. Pitkin'}}`, {
simple: 'Hello Friend',
personal: 'Hello'
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct');

this.runTask(() => this.rerender());
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct after rerender');

this.runTask(() => set(this.context, 'simple', 'G\'day mate'));
this.assertText('G\'day mate - Hallo, Mr. Pitkin',
'the bound value is correct after update');

this.runTask(() => set(this.context, 'simple', 'Hello Friend'));
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct after reset');
}

['@test it updates when nested bound params change']() {
this.render(`{{loc greetings.simple}} - {{loc greetings.personal 'Mr. Pitkin'}}`, {
greetings: {
simple: 'Hello Friend',
personal: 'Hello'
}
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct');

this.runTask(() => this.rerender());
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct after rerender');

this.runTask(() => set(this.context, 'greetings.simple', 'G\'day mate'));
this.assertText('G\'day mate - Hallo, Mr. Pitkin',
'the bound value is correct after interior mutation');

this.runTask(() => set(this.context, 'greetings', {
simple: 'Hello Friend',
personal: 'Hello'
}));
this.assertText('Hallo Freund - Hallo, Mr. Pitkin',
'the bound value is correct after replacement');
}

});

0 comments on commit 1de062d

Please sign in to comment.