diff --git a/.editorconfig b/.editorconfig index 2fe4874..3ef6636 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,23 +11,24 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true indent_style = space -indent_size = 2 +indent_size = 4 [*.js] indent_style = space -indent_size = 2 +indent_size = 4 [*.hbs] +insert_final_newline = false indent_style = space -indent_size = 2 +indent_size = 4 [*.css] indent_style = space -indent_size = 2 +indent_size = 4 [*.html] indent_style = space -indent_size = 2 +indent_size = 4 [*.{diff,md}] trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli old mode 100755 new mode 100644 diff --git a/.npmignore b/.npmignore index 0533b91..a28e4ab 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,6 @@ bower_components/ tests/ +tmp/ .bowerrc .editorconfig diff --git a/.travis.yml b/.travis.yml index cf23938..70a305e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ --- language: node_js +node_js: + - "0.12" sudo: false diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100755 new mode 100644 diff --git a/CLA-CORPORATE.md b/CLA-CORPORATE.md old mode 100755 new mode 100644 diff --git a/CLA-INDIVIDUAL.md b/CLA-INDIVIDUAL.md old mode 100755 new mode 100644 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100755 new mode 100644 diff --git a/LICENSE.md b/LICENSE.md old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 6c7d5d1..b9fd357 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Latest Release](https://img.shields.io/github/release/softlayer/sl-ember-translate.svg)](https://github.com/softlayer/sl-ember-translate/releases) ![Ember CLI version](https://img.shields.io/badge/ember%20cli-0.1.15-orange.svg) [![License](https://img.shields.io/npm/l/sl-ember-translate.svg)](LICENSE.md) [![Downloads](https://img.shields.io/npm/dm/sl-ember-translate.svg)](https://www.npmjs.com/package/sl-ember-translate) +[![Latest Release](https://img.shields.io/github/release/softlayer/sl-ember-translate.svg)](https://github.com/softlayer/sl-ember-translate/releases) ![Ember CLI version](https://img.shields.io/badge/ember%20cli-0.2.3-orange.svg) [![License](https://img.shields.io/npm/l/sl-ember-translate.svg)](LICENSE.md) [![Downloads](https://img.shields.io/npm/dm/sl-ember-translate.svg)](https://www.npmjs.com/package/sl-ember-translate) [![Dependencies](https://img.shields.io/david/softlayer/sl-ember-translate.svg)](https://david-dm.org/softlayer/sl-ember-translate) [![Dev Dependencies](https://img.shields.io/david/dev/softlayer/sl-ember-translate.svg)](https://david-dm.org/softlayer/sl-ember-translate#info=devDependencies) @@ -57,7 +57,7 @@ For more information on using ember-cli, visit [http://www.ember-cli.com/](http: ## Install this addon as a Node module ``` -ember install:addon sl-ember-translate +ember install sl-ember-translate ``` @@ -107,18 +107,6 @@ where each "$x" parameter numerically corresponds to the tokens in the translati --- -### Binding - -If you need to pass parameters whose values are bound to other values rather than be hard-coded, use the following format: - -```handlebars -{{sl-translate key="ACCESSLOG_LIST_PAGINATION" $0Binding="examplePropertyBoundTo1" $1Binding="examplePropertyBoundTo2" $2Binding="examplePropertyBoundTo3"}} -``` - -The order of the parameters does not matter. - ---- - ### Used alongside other properties or attribute bindings You can still use the *sl-translate* component alongside other properties or attribute bindings as well: diff --git a/RELEASE-INSTRUCTIONS.md b/RELEASE-INSTRUCTIONS.md old mode 100755 new mode 100644 diff --git a/addon/components/sl-translate.js b/addon/components/sl-translate.js old mode 100755 new mode 100644 index 1a0d58f..2816cda --- a/addon/components/sl-translate.js +++ b/addon/components/sl-translate.js @@ -41,7 +41,8 @@ export default Ember.Component.extend({ /** * Filtered array of parameters passed to this component * - * Only contains those that are a number that begin with "$" and are to be bound to + * Only contains those that are a number that begin with "$" and are to be + * bound to * * @property {Ember.Array} observedParameters * @default null @@ -51,7 +52,8 @@ export default Ember.Component.extend({ /** * Filtered array of parameters passed to this component * - * Only contains those that are a number that begin with "$" and also do not end in "Binding" + * Only contains those that are a number that begin with "$" and also do not + * end in "Binding" * * @property {Ember.Array} parameters * @default null @@ -76,12 +78,11 @@ export default Ember.Component.extend({ * @observes "init" event * @returns {void} */ - extractParameterKeys: function() { + extractParameterKeys: Ember.on( 'init', function() { var parameters = [], - observedParameters = [], - self = this; + observedParameters = []; - Ember.keys( this ).map( function( key ) { + Ember.keys( this ).map( key => { // Is a number that begins with $ but doesn't also end with "Binding" if ( /^\$/.test( key ) && !/^\$.*(Binding)$/.test( key ) ) { @@ -89,38 +90,37 @@ export default Ember.Component.extend({ } // Is a number that begins with $ and was passed as a binding - if ( /^\$[0-9]*$/.test( key ) && self.hasOwnProperty( key + 'Binding' ) ) { + if ( /^\$[0-9]*$/.test( key ) && this.hasOwnProperty( key + 'Binding' ) ) { observedParameters.push( key ); } }); this.setProperties({ - 'parameters' : parameters, - 'observedParameters' : observedParameters + observedParameters, + parameters }); - }.on( 'init' ), + }), /** * Register observers on filtered parameter list * - * The reason observers have to be manually (de)registered rather than calling .property() on translateString() is - * because in order to support token replacement within a tranlsation string a user needs to be able to pass in a - * variable amount of (potentially) bound properties. There is not a way to specify such a dynamic list of - * properties in a .property() call. + * The reason observers have to be manually (de)registered rather than + * calling .property() on translateString() is because in order to support + * token replacement within a tranlsation string a user needs to be able to + * pass in a variable amount of (potentially) bound properties. There is not + * a way to specify such a dynamic list of properties in a .property() call. * * @function registerObservers * @observes "willInsertElement" event * @returns {void} */ - registerObservers: function() { - var self = this; - - this.get( 'observedParameters' ).map( function( key ) { - self.addObserver( key, self, self.setTranslatedString ); + registerObservers: Ember.on( 'willInsertElement', function() { + this.get( 'observedParameters' ).map( key => { + this.addObserver( key, this, this.setTranslatedString ); }); this.setTranslatedString(); - }.on( 'willInsertElement' ), + }), /** * Remove observers on filtered parameter list @@ -129,13 +129,11 @@ export default Ember.Component.extend({ * @observes "willClearRender" event * @returns {void} */ - unregisterObservers: function() { - var self = this; - - this.get( 'observedParameters' ).map( function( key ) { - self.removeObserver( key, self, self.setTranslatedString ); + unregisterObservers: Ember.on( 'willClearRender', function() { + this.get( 'observedParameters' ).map( key => { + this.removeObserver( key, this, this.setTranslatedString ); }); - }.on( 'willClearRender' ), + }), // ------------------------------------------------------------------------- // Methods @@ -146,7 +144,7 @@ export default Ember.Component.extend({ * @function setTranslatedString * @returns {void} */ - setTranslatedString: function() { + setTranslatedString() { this.set( 'translatedString', this.translateString() ); }, @@ -155,17 +153,17 @@ export default Ember.Component.extend({ * * Supports * - singular/plural string substitution - * - replacement of placeholder tokens in translation strings with passed parameters + * - replacement of placeholder tokens in translation strings with + * passed parameters * * @function translateString * @returns {Ember.String} Translated string */ - translateString: function() { - var parametersHash = {}, - self = this; + translateString() { + var parametersHash = {}; - this.get( 'parameters' ).map( function( key ) { - parametersHash[key] = self.get( key ); + this.get( 'parameters' ).map( key => { + parametersHash[key] = this.get( key ); }); return this.get( 'translateService' ).translateKey({ diff --git a/addon/initializers/translate-service.js b/addon/initializers/translate-service.js old mode 100755 new mode 100644 index db3982c..cab3624 --- a/addon/initializers/translate-service.js +++ b/addon/initializers/translate-service.js @@ -5,11 +5,14 @@ import TranslateService from '../services/translate'; * @class translate-service */ export default function( container, app ) { - var translateService = TranslateService.create(); + var translateService = TranslateService.create(); // Inject Translate Service - container.register( 'translateService:main', translateService, { instantiate: false } ); + container.register( 'translateService:main', translateService, { + instantiate: false + }); + app.inject( 'view', 'translateService', 'translateService:main' ); app.inject( 'controller', 'translateService', 'translateService:main' ); app.inject( 'component', 'translateService', 'translateService:main' ); -} \ No newline at end of file +} diff --git a/addon/mixins/sl-get-translation.js b/addon/mixins/sl-get-translation.js old mode 100755 new mode 100644 index 2aad03b..c70dcd1 --- a/addon/mixins/sl-get-translation.js +++ b/addon/mixins/sl-get-translation.js @@ -34,7 +34,7 @@ export default Ember.Mixin.create({ * @argument {Ember.String} key property to retrieve * @returns {Ember.String} */ - get: function( key ) { + get( key ) { var translationsRegex = /translate\.(.*)/, matches = key.match( translationsRegex ); @@ -48,7 +48,7 @@ export default Ember.Mixin.create({ * @argument {Ember.String} key key to translate * @returns {Ember.String} translated key */ - translate: function( key ) { + translate( key ) { return this.translateService.getKeyValue( key ); } -}); \ No newline at end of file +}); diff --git a/addon/services/translate.js b/addon/services/translate.js old mode 100755 new mode 100644 index 08207d6..5394e3a --- a/addon/services/translate.js +++ b/addon/services/translate.js @@ -43,8 +43,7 @@ export default Ember.Object.extend({ * @throws {Ember.assert} * @returns {void} */ - setDictionary: function( translations ) { - + setDictionary( translations ) { Ember.assert( 'services/translation.setDictionary() expects parameter to be an object', 'object' === typeof translations && !Array.isArray( translations ) @@ -60,7 +59,7 @@ export default Ember.Object.extend({ * @argument {Ember.String} key Dictionary key to retrieve value for * @returns {Ember.String} */ - getKeyValue: function( key ) { + getKeyValue( key ) { var defaultKeyValue = 'KEY__NOT__PRESENT', retrievedKey = this.get( 'dictionary' ).getWithDefault( key, defaultKeyValue ), returnValue; @@ -97,18 +96,17 @@ export default Ember.Object.extend({ * } * @return {Ember.String} Translated string */ - translateKey: function( data ) { + translateKey( data ) { Ember.assert( 'Argument must be an object', 'object' === typeof data && !Array.isArray( data ) ); data.parameters = data.parameters || {}; var pluralErrorTracker = 0, - self = this, token = data.key, - getTokenValue = function( value ) { + getTokenValue = ( value ) => { try { - value = self.getKeyValue( value ); + value = this.getKeyValue( value ); } catch ( e ) { Ember.warn( 'Unable to translate key "' + value + '".' ); } @@ -141,7 +139,7 @@ export default Ember.Object.extend({ translatedString = getTokenValue( token ); // Parameter replacement - Ember.keys( data.parameters ).map( function( key ) { + Ember.keys( data.parameters ).map( key => { translatedString = translatedString.replace( '{' + key.replace( '$', '' ) + '}' , data.parameters[key] ); }); diff --git a/addon/templates/components/sl-translate.hbs b/addon/templates/components/sl-translate.hbs old mode 100755 new mode 100644 index 9e99a92..0419f13 --- a/addon/templates/components/sl-translate.hbs +++ b/addon/templates/components/sl-translate.hbs @@ -1 +1 @@ -{{translatedString}} \ No newline at end of file +{{translatedString}} \ No newline at end of file diff --git a/bower.json b/bower.json old mode 100755 new mode 100644 index ac5831b..f03e86b --- a/bower.json +++ b/bower.json @@ -1,18 +1,16 @@ { "name": "sl-ember-translate", "dependencies": { - "handlebars": "~1.3.0", - "jquery": "^1.11.1", - "ember": "1.8.1", - "ember-data": "1.0.0-beta.14.1", - "ember-resolver": "~0.1.11", - "loader.js": "ember-cli/loader.js#1.0.1", + "blanket": "~1.1.5", + "ember": "1.11.1", "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", - "ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.1", - "ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2", - "ember-qunit": "0.2.8", + "ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.3", + "ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4", + "ember-qunit": "0.3.1", "ember-qunit-notifications": "0.0.7", - "qunit": "~1.17.1", - "blanket": "~1.1.5" + "ember-resolver": "~0.1.15", + "jquery": "^1.11.1", + "loader.js": "ember-cli/loader.js#3.2.0", + "qunit": "~1.17.1" } } diff --git a/index.js b/index.js old mode 100755 new mode 100644 diff --git a/package.json b/package.json index 0592809..b24c280 100644 --- a/package.json +++ b/package.json @@ -28,25 +28,23 @@ "author": "Jeremy Brown (http://www.notmessenger.com)", "license": "MIT", "dependencies": { + "ember-cli-babel": "^5.0.0", + "ember-cli-htmlbars": "0.7.4", "rimraf": "2.3.0" }, "devDependencies": { - "broccoli-asset-rev": "^2.0.0", - "broccoli-ember-hbs-template-compiler": "^1.6.1", + "broccoli-asset-rev": "^2.0.2", "broccoli-string-replace": "0.0.2", - "ember-cli": "0.1.15", - "ember-cli-app-version": "0.3.1", - "ember-cli-babel": "^4.0.0", - "ember-cli-blanket": "0.3.2", - "ember-cli-dependency-checker": "0.0.7", + "ember-cli": "0.2.3", + "ember-cli-app-version": "0.3.3", + "ember-cli-blanket": "0.4.0", + "ember-cli-dependency-checker": "0.0.8", "ember-cli-ic-ajax": "0.1.1", "ember-cli-inject-live-reload": "^1.3.0", - "ember-cli-qunit": "0.3.7", + "ember-cli-qunit": "0.3.10", "ember-cli-uglify": "1.0.1", - "ember-data": "1.0.0-beta.14.1", "ember-export-application-global": "^1.0.2", - "express": "^4.8.5", - "glob": "^4.5.1", - "sl-ember-test-helpers": "1.3.0" + "ember-disable-prototype-extensions": "^1.0.0", + "sl-ember-test-helpers": "1.4.0" } } diff --git a/tests/.jshintrc b/tests/.jshintrc old mode 100755 new mode 100644 diff --git a/tests/blanket-options.js b/tests/blanket-options.js index 65db42d..ad544fe 100644 --- a/tests/blanket-options.js +++ b/tests/blanket-options.js @@ -1,9 +1,9 @@ /* globals blanket */ blanket.options({ - modulePrefix: "dummy", - filter: "//.*dummy/.*/", - antifilter: "//.*(tests|template).*/", - loaderExclusions: [], - enableCoverage: true -}); \ No newline at end of file + modulePrefix : 'dummy', + filter : '//.*dummy/.*/', + antifilter : '//.*(tests|template).*/', + loaderExclusions : [], + enableCoverage : true +}); diff --git a/tests/dummy/.jshintrc b/tests/dummy/.jshintrc old mode 100755 new mode 100644 diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js old mode 100755 new mode 100644 index 757df38..8d66b95 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -3,9 +3,11 @@ import Resolver from 'ember/resolver'; import loadInitializers from 'ember/load-initializers'; import config from './config/environment'; +var App; + Ember.MODEL_FACTORY_INJECTIONS = true; -var App = Ember.Application.extend({ +App = Ember.Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, Resolver: Resolver diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html old mode 100755 new mode 100644 diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js old mode 100755 new mode 100644 index 87b2ecb..73b0b27 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -5,9 +5,7 @@ var Router = Ember.Router.extend({ location: config.locationType }); -Router.map(function() { +export default Router.map(function() { this.route( 'index', { path: '/' }); this.route( 'demo' ); }); - -export default Router; diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs old mode 100755 new mode 100644 index 25b13f0..a8c76fa --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -24,7 +24,7 @@

-

ember install:addon sl-ember-translate

+

ember install sl-ember-translate

MIT Licensed

diff --git a/tests/dummy/app/templates/demo.hbs b/tests/dummy/app/templates/demo.hbs old mode 100755 new mode 100644 index a88be68..0553092 --- a/tests/dummy/app/templates/demo.hbs +++ b/tests/dummy/app/templates/demo.hbs @@ -20,7 +20,7 @@ Replaced String: {{sl-translate key="REPLACED_KEY" $0="First" $1="Unicorn"}}

Bound Replacement Values In Keys

-String Will Update: {{sl-translate key="REPLACED_KEY" $0="First" $1Binding="valueToDisplay"}} +String Will Update: {{sl-translate key="REPLACED_KEY" $0="First" $1=valueToDisplay}}

diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs old mode 100755 new mode 100644 diff --git a/tests/index.html b/tests/index.html old mode 100755 new mode 100644 diff --git a/tests/test-helper.js b/tests/test-helper.js index e6cfb70..f591ea1 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -1,6 +1,4 @@ import resolver from './helpers/resolver'; -import { - setResolver -} from 'ember-qunit'; +import { setResolver } from 'ember-qunit'; -setResolver(resolver); +setResolver( resolver ); diff --git a/tests/unit/components/sl-translate-test.js b/tests/unit/components/sl-translate-test.js old mode 100755 new mode 100644 index 413e806..56507a4 --- a/tests/unit/components/sl-translate-test.js +++ b/tests/unit/components/sl-translate-test.js @@ -1,43 +1,39 @@ import Ember from 'ember'; -import { test, moduleForComponent } from 'ember-qunit'; +import { moduleForComponent, test } from 'ember-qunit'; var translateService = Ember.Object.create({ - translateKey: function( data ) { - this.set( 'key', data.key ); - this.set( 'pluralKey', data.pluralKey ); - this.set( 'pluralCount', data.pluralCount ); - this.set( 'parameters', data.parameters ); - - return 'TRANSLATE: ' + data.key; - } - }); + translateKey( data ) { + this.set( 'key', data.key ); + this.set( 'pluralKey', data.pluralKey ); + this.set( 'pluralCount', data.pluralCount ); + this.set( 'parameters', data.parameters ); + + return 'TRANSLATE: ' + data.key; + } +}); moduleForComponent( 'sl-translate', 'Unit - component:sl-translate' ); /** - * Ensures that the template is wrapping the content in a span tag and not in any block-level tags. While it appears - * that core Ember functionality is being tested this test is ensuring that the implied contract about how this non-UI + * Ensures that the template is wrapping the content in a span tag and not in + * any block-level tags. While it appears that core Ember functionality is being + * tested this test is ensuring that the implied contract about how this non-UI * component is rendered into the DOM is adhered to. */ test( 'Renders as a span tag with no classes', function( assert ) { - var component = this.subject({ translateService: translateService }), - $component = this.render(); + this.subject({ translateService }); - assert.equal( $component.prop( 'tagName' ), 'SPAN' ); - assert.equal( $component.prop( 'class'), 'ember-view' ); + assert.equal( this.$().prop( 'tagName' ), 'SPAN' ); + assert.equal( this.$().prop( 'class' ), 'ember-view' ); }); /** * That it renders and functions as expected */ test( 'DOM and content of rendered translation', function( assert ) { - var component = this.subject({ - key : 'the_key', - translateService : translateService - }), - $component = this.render(); + this.subject({ key: 'the_key', translateService }); - assert.equal( $component.text(), 'TRANSLATE: the_key' ); + assert.equal( Ember.$.trim( this.$().text() ), 'TRANSLATE: the_key' ); }); /** @@ -45,17 +41,16 @@ test( 'DOM and content of rendered translation', function( assert ) { * A side effect of this test is the appearance that core Ember functionality is being tested */ test( 'Can be used alongside other properties or attribute bindings', function( assert ) { - var component = this.subject({ - translateService : translateService, - key : 'key_alongside', - tagName : 'h1', - classNames : [ 'testClass' ] - }), - $component = this.render(); + this.subject({ + translateService, + key : 'key_alongside', + tagName : 'h1', + classNames : [ 'testClass' ] + }); - assert.equal( $component.prop( 'tagName' ), 'H1' ); - assert.equal( $component.text(), 'TRANSLATE: key_alongside' ); - assert.equal( $component.prop( 'class'), ['ember-view testClass'] ); + assert.equal( this.$().prop( 'tagName' ), 'H1' ); + assert.equal( Ember.$.trim( this.$().text() ), 'TRANSLATE: key_alongside' ); + assert.equal( this.$().prop( 'class'), ['ember-view testClass'] ); }); test( 'On initialization, extractParameterKeys() filters passed parameters', function( assert ) { @@ -97,16 +92,16 @@ test( 'setTranslatedString() sets translatedString property with value from tran }); test( 'translateString() calls translateKey() on the translation service', function( assert ) { - var component = this.subject({ - translateService : translateService, - key : 'the_key', - pluralKey : 'plural_key', - pluralCount : 'plural_count', - $0 : 'a', - $1 : 'b' - }); + this.subject({ + translateService, + key : 'the_key', + pluralKey : 'plural_key', + pluralCount : 'plural_count', + $0 : 'a', + $1 : 'b' + }); - this.render(); + this.render(); assert.equal( translateService.get( 'key' ), 'the_key' ); assert.equal( translateService.get( 'pluralKey' ), 'plural_key' ); @@ -130,10 +125,10 @@ test( 'willInsertElement event causes setTranslatedString() to be called', funct test( 'willInsertElement event causes observers to be added to each entry in observedParameters property', function( assert ) { var component = this.subject({ - translateService : translateService, - key : 'the_key', - $0Binding : 'a', - $1 : 'b' + translateService, + key : 'the_key', + $0Binding : 'a', + $1 : 'b' }), setTranslatedStringWasCalled = false; @@ -156,14 +151,14 @@ test( 'willInsertElement event causes observers to be added to each entry in obs test( 'willClearRender event causes observers to be removed', function( assert ) { var component = this.subject({ - translateService : translateService, - key : 'the_key', - $0Binding : 'a', - $1 : 'b' + translateService, + key : 'the_key', + $0Binding : 'a', + $1 : 'b' }), setTranslatedStringWasCalled = false; - component.setTranslatedString = function() { + component.setTranslatedString = () => { setTranslatedStringWasCalled = true; }; @@ -175,7 +170,7 @@ test( 'willClearRender event causes observers to be removed', function( assert ) component.trigger( 'willClearRender' ); - Ember.run( function(){ + Ember.run( () => { component.set( '$0', 'c' ); }); diff --git a/tests/unit/initializers/translate-service-test.js b/tests/unit/initializers/translate-service-test.js index dd12df2..fad923c 100755 --- a/tests/unit/initializers/translate-service-test.js +++ b/tests/unit/initializers/translate-service-test.js @@ -5,38 +5,61 @@ import startApp from '../../helpers/start-app'; var App; module( 'Unit - initializer:translate-service', { - beforeEach: function() { + beforeEach() { App = startApp(); }, - afterEach: function() { + afterEach() { Ember.run( App, App.destroy ); } }); test( 'Registered on container as a singleton', function( assert ) { - assert.equal( typeof App.__container__.lookup( 'translateService:main' ), 'object' ); - assert.notEqual( App.__container__._options['translateService:main'].instantiate, 'undefined' ); - assert.equal( App.__container__._options['translateService:main'].instantiate, false ); + assert.equal( + typeof App.__container__.lookup( 'translateService:main' ), + 'object', + 'The translateService is an object' + ); + + assert.notEqual( + App.registry._options[ 'translateService:main' ].instantiate, + 'undefined', + "The service's instantiate value is defined" + ); + + assert.equal( + App.registry._options[ 'translateService:main' ].instantiate, + false, + 'The service is registered as a singleton' + ); }); test( 'Injected on controllers', function( assert ) { - var findBy = App.__container__.typeInjections.controller.findBy( 'fullName', 'translateService:main' ); + assert.expect( 1 ); - assert.notEqual( findBy, 'undefined' ); - assert.equal( findBy.property, 'translateService' ); + App.registry._typeInjections[ 'controller' ].map( type => { + if ( type[ 'property' ] === 'translateService' ) { + assert.ok( true, 'Service is available to controllers' ); + } + }); }); test( 'Injected on views', function( assert ) { - var findBy = App.__container__.typeInjections.view.findBy( 'fullName', 'translateService:main' ); + assert.expect( 1 ); - assert.notEqual( findBy, 'undefined' ); - assert.equal( findBy.property, 'translateService' ); + App.registry._typeInjections[ 'view' ].map( type => { + if ( type[ 'property' ] === 'translateService' ) { + assert.ok( true, 'Service is available to views' ); + } + }); }); test( 'Injected on components', function( assert ) { - var findBy = App.__container__.typeInjections.component.findBy( 'fullName', 'translateService:main' ); + assert.expect( 1 ); - assert.notEqual( findBy, 'undefined' ); - assert.equal( findBy.property, 'translateService' ); -}); \ No newline at end of file + App.registry._typeInjections[ 'component' ].map( type => { + if ( type[ 'property' ] === 'translateService' ) { + assert.ok( true, 'Service is available to components' ); + } + }); +}); diff --git a/tests/unit/services/translate-test.js b/tests/unit/services/translate-test.js old mode 100755 new mode 100644 index 3616a4b..7a22395 --- a/tests/unit/services/translate-test.js +++ b/tests/unit/services/translate-test.js @@ -6,20 +6,16 @@ import { requires } from '../../helpers/sl/synchronous'; var TS; module( 'Unit - services:translate', { - beforeEach: function() { + beforeEach() { TS = TranslateService.create(); } }); test( 'container property defaults to null', function( assert ) { - assert.expect(1); - assert.equal( TS.get( 'container' ), null ); }); test( 'dictionary property defaults to null', function( assert ) { - assert.expect(1); - assert.equal( TS.get( 'dictionary' ), null ); }); @@ -111,8 +107,6 @@ test( 'setDictionary() accepts only an object as a parameter', function( assert }); test( 'setDictionary() sets data on the dictionary property', function( assert ) { - assert.expect(1); - var testDictionary = Ember.Object.create( { 'the_key': 'my value' } ); TS.setDictionary( testDictionary ); @@ -121,16 +115,12 @@ test( 'setDictionary() sets data on the dictionary property', function( assert ) }); test( 'getKeyValue() returns requested key if not found in dictionary', function( assert ) { - assert.expect(1); - TS.setDictionary( Ember.Object.create( { 'the_key': 'my value' } ) ); assert.notEqual( TS.getKeyValue( 'wrong_key' ), 'the_key' ); }); test( 'getKeyValue() returns requested key\'s translated string', function( assert ) { - assert.expect(1); - TS.setDictionary( Ember.Object.create( { 'the_key': 'my value' } ) ); assert.equal( TS.getKeyValue( 'the_key' ), 'my value' ); @@ -143,23 +133,17 @@ test( 'translateKey() accepts only an object as a parameter', function( assert ) }); test( 'translateKey() returns translated string for specified key', function( assert ) { - assert.expect(1); - TS.setDictionary( Ember.Object.create( { 'the_key': 'my value' } ) ); assert.equal( TS.getKeyValue( 'the_key' ), 'my value' ); }); test( 'If either "pluralKey" or "pluralCount" are provided to translateKey() then both must be', function( assert ) { - assert.expect(2); - assert.equal( TS.translateKey( { key: 'singular_key', pluralKey: 'plural_key' } ), 'singular_key' ); assert.equal( TS.translateKey( { key: 'singular_key', pluralCount: 3 } ), 'singular_key' ); }); test( 'Pluralization only works if "pluralCount" is a number', function( assert ) { - assert.expect(1); - TS.setDictionary( Ember.Object.create( { 'the_singular_key' : 'Singular translated value', 'the_plural_key' : 'Plural translated value' @@ -169,8 +153,6 @@ test( 'Pluralization only works if "pluralCount" is a number', function( assert }); test( 'Pluralization occurs when provided the necessary information', function( assert ) { - assert.expect(2); - TS.setDictionary( Ember.Object.create( { 'the_singular_key' : 'Singular translated value', 'the_plural_key' : 'Plural translated value' @@ -181,8 +163,6 @@ test( 'Pluralization occurs when provided the necessary information', function( }); test( 'Token replacement in translation string', function( assert ) { - assert.expect(1); - TS.setDictionary( Ember.Object.create( { 'the_key': 'Replaced values: {0} and {1}' })); @@ -194,4 +174,4 @@ test( 'Token replacement in translation string', function( assert ) { $1: 1234 } }), 'Replaced values: ASDF and 1234' ); -}); \ No newline at end of file +});