ember.js - "Missing translation" when running an Ember acceptance test related to ember-i18n package -


i'm writing acceptance tests ember component allows user toggle i18n settings via dropdown provided ember-select-list package. i'm using ember-i18n package i18n settings. dropdown component looks this:

import ember 'ember';  export default ember.component.extend({   i18n: ember.inject.service(),   languagepreference: ember.inject.service(),    classnames: ['language-dropdown'],    languageoptions: ember.computed('i18n.locale', function() {     let i18n = this.get('i18n');     return i18n.get('locales').map((item) => {       return {         id: item,         name: i18n.t(`languages.${item}`)       };     });   }),    onfinish: null,    actions: {     selectlanguage(i18n) {       this.get('languagepreference').setuseri18npreference(i18n);       this.get('onfinish')();     }   }  }); 

the language-preference service looks this:

import ember 'ember';  export default ember.service.extend({    i18n: ember.inject.service(),   config: ember.inject.service(),    setsessioni18npreference() {     let setsessioni18n = (results) => {       let { preferences, username } = results;       if (username && preferences[username]) {         this.set('i18n.locale', preferences[username].i18n);       }     };     this._fetchuserpreferencesdb().then(setsessioni18n);   },    setuseri18npreference(i18n) {     let setuseri18n = (results) => {       let { preferences, username } = results;       if (preferences[username] === undefined) {         preferences[username] = {};       }       preferences[username].i18n = i18n;       this.get('config.configdb').put(preferences);       this.set('i18n.locale', i18n);     };     this._fetchuserpreferencesdb().then(setuseri18n);   },    _fetchuserpreferencesdb() {     let configdb = this.get('config.configdb');     let username;     return configdb.get('current_user').then((user) => {       username = this._fetchusername(user);       let preferences = configdb.get('preferences');       return ember.rsvp.hash({ username, preferences });     }).catch((err) => {       console.log(err);       if (err.status === 404) {         this._initpreferencesdb(username, 'en');       }     });   },    _fetchusername(user) {     switch (typeof user.value) {       case 'string':         return user.value;       case 'object':         return user.value.name;       default:         return undefined;     }   },    _initpreferencesdb(username, i18n) {     let doc = {       _id: 'preferences'     };     if (username != undefined) {       doc[username] = {         i18n: i18n || 'en'       };     }     this.get('config.configdb').put(doc);   } }); 

for acceptance test, far have this:

import ember 'ember'; import { module, test } 'qunit'; import startapp 'hospitalrun/tests/helpers/start-app';  module('acceptance | language dropdown', {   beforeeach() {     this.application = startapp();   },    aftereach() {     ember.run(this.application, 'destroy');   } });  test('setting language preference persists after logout', (assert) => {   runwithpouchdump('default', () => {   authenticateuser({ name: 'foobar', prefix: 'p2' });   visit('/');    andthen(() => {     assert.equal(currenturl(), '/');     assert.equal(find('.view-current-title').text(), 'welcome hospitalrun!');     });     andthen(() => {       click('a.settings-trigger');       waittoappear('.settings-nav');       // andthen(() => {       //   select('.language-dropdown', 'french');       //   andthen(() => {       //     debugger;       //   });       // });     });   }); }); 

this works fine , tests pass. when un-comment block that's commented-out, , re-run tests, see multiple test failures, starting global error:

not ok 66 phantomjs 2.1 - global error: error: missing translation: navigation.subnav.textreplacements @ http://localhost:7357/assets/tests.js, line 12058 ---     log: |         { type: 'error',           text: 'error: missing translation: navigation.subnav.textreplacements @ http://localhost:7357/assets/tests.js, line 12058\n' } ... not ok 67 phantomjs 2.1 - acceptance | language dropdown: setting language preference persists after logout ---     actual: >         null     expected: >         null     stack: >         http://localhost:7357/assets/tests.js:12058     message: >         error: missing translation: navigation.subnav.textreplacements     log: | ... 

the app works fine in browser (the translation files in place , can see correct i18n output in browser when toggling i18n). ember-i18n docs should work fine tests call startapp(), test does. what's weird me commented-out line, when uncommented, breaks not test tests in other files too. i'm guessing it's affecting global (within test process) i18n setting, , setting not getting torn down after test finishes, can't sure.

code lives here- https://github.com/richiethomas/hospitalrun-frontend/tree/debug

the latest commit represents failing test.

edit: when put debugger in _fetchuserpreferencesdb function inside language-preference, i'm able call this.get('i18n.locales') , see locales expect, know cause not different locales in different environments (i.e. development vs test). called this.get('i18n').t('navigation.subnav.textreplacements'), same translation value failing test says missing, , correct translation. i'm not sure why test fails.

so apparently test trying use german translations file (which didn't have navigation.subnav.textreplacements key), though acceptance test specified french. verified running tests in chrome console, putting debugger before failing line, , inspecting this.get('i18n._locale') object's translations attribute. found in german reason.

so mystery of missing translation elements masking mystery, why acceptance test defaulting german after phantomjs has selected french i18n option. that's topic post.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -