Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
feat(test): setup unit test structure for i18n attribute
Browse files Browse the repository at this point in the history
this sets up the necessary infrastructure to test the i18n attribute implementation
  • Loading branch information
zewa666 committed Aug 19, 2015
1 parent f899747 commit 62742d1
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 18 deletions.
7 changes: 6 additions & 1 deletion dist/amd/base-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(['exports', './i18n', 'aurelia-event-aggregator'], function (exports, _i1
this.i18n = i18n;
this.element = element;

ea.subscribe('i18n:locale:changed', function (payload) {
this.__i18nDisposer = ea.subscribe('i18n:locale:changed', function (payload) {
_this.i18n.updateTranslations(_this.element);
});
}
Expand All @@ -28,6 +28,11 @@ define(['exports', './i18n', 'aurelia-event-aggregator'], function (exports, _i1
value: function attached() {
this.i18n.updateTranslations(this.element);
}
}, {
key: 'detached',
value: function detached() {
this.__i18nDisposer();
}
}], [{
key: 'inject',
value: [_i18n.I18N, Element, _aureliaEventAggregator.EventAggregator],
Expand Down
9 changes: 6 additions & 3 deletions dist/amd/t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['exports', './i18n'], function (exports, _i18n) {
define(['exports', './i18n', 'aurelia-templating'], function (exports, _i18n, _aureliaTemplating) {
'use strict';

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
Expand Down Expand Up @@ -35,13 +35,15 @@ define(['exports', './i18n'], function (exports, _i18n) {

var TCustomAttribute = (function () {
function TCustomAttribute(element, i18n) {
_classCallCheck(this, TCustomAttribute);
_classCallCheck(this, _TCustomAttribute);

this.element = element;
this.service = i18n;
}

_createClass(TCustomAttribute, [{
var _TCustomAttribute = TCustomAttribute;

_createClass(_TCustomAttribute, [{
key: 'valueChanged',
value: function valueChanged() {
if (this.element.parentElement !== undefined) {
Expand All @@ -54,6 +56,7 @@ define(['exports', './i18n'], function (exports, _i18n) {
enumerable: true
}]);

TCustomAttribute = _aureliaTemplating.customAttribute('t')(TCustomAttribute) || TCustomAttribute;
return TCustomAttribute;
})();

Expand Down
7 changes: 6 additions & 1 deletion dist/commonjs/base-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var BaseI18N = (function () {
this.i18n = i18n;
this.element = element;

ea.subscribe('i18n:locale:changed', function (payload) {
this.__i18nDisposer = ea.subscribe('i18n:locale:changed', function (payload) {
_this.i18n.updateTranslations(_this.element);
});
}
Expand All @@ -31,6 +31,11 @@ var BaseI18N = (function () {
value: function attached() {
this.i18n.updateTranslations(this.element);
}
}, {
key: 'detached',
value: function detached() {
this.__i18nDisposer();
}
}], [{
key: 'inject',
value: [_I18N.I18N, Element, _EventAggregator.EventAggregator],
Expand Down
9 changes: 7 additions & 2 deletions dist/commonjs/t.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Object.defineProperty(exports, '__esModule', {

var _I18N = require('./i18n');

var _customAttribute = require('aurelia-templating');

var TValueConverter = (function () {
function TValueConverter(i18n) {
_classCallCheck(this, TValueConverter);
Expand All @@ -36,13 +38,15 @@ exports.TValueConverter = TValueConverter;

var TCustomAttribute = (function () {
function TCustomAttribute(element, i18n) {
_classCallCheck(this, TCustomAttribute);
_classCallCheck(this, _TCustomAttribute);

this.element = element;
this.service = i18n;
}

_createClass(TCustomAttribute, [{
var _TCustomAttribute = TCustomAttribute;

_createClass(_TCustomAttribute, [{
key: 'valueChanged',
value: function valueChanged() {
if (this.element.parentElement !== undefined) {
Expand All @@ -55,6 +59,7 @@ var TCustomAttribute = (function () {
enumerable: true
}]);

TCustomAttribute = _customAttribute.customAttribute('t')(TCustomAttribute) || TCustomAttribute;
return TCustomAttribute;
})();

Expand Down
6 changes: 5 additions & 1 deletion dist/es6/base-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export class BaseI18N {
this.i18n = i18n;
this.element = element;

ea.subscribe('i18n:locale:changed', payload => {
this.__i18nDisposer = ea.subscribe('i18n:locale:changed', payload => {
this.i18n.updateTranslations(this.element);
});
}

attached(){
this.i18n.updateTranslations(this.element);
}

detached() {
this.__i18nDisposer();
}
}
3 changes: 3 additions & 0 deletions dist/es6/t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {I18N} from './i18n';
import {customAttribute} from 'aurelia-templating';


export class TValueConverter {
static inject() { return [I18N]; }
Expand All @@ -11,6 +13,7 @@ export class TValueConverter {
}
}

@customAttribute('t')
export class TCustomAttribute {

static inject = [Element, I18N];
Expand Down
7 changes: 6 additions & 1 deletion dist/system/base-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ System.register(['./i18n', 'aurelia-event-aggregator'], function (_export) {
this.i18n = i18n;
this.element = element;

ea.subscribe('i18n:locale:changed', function (payload) {
this.__i18nDisposer = ea.subscribe('i18n:locale:changed', function (payload) {
_this.i18n.updateTranslations(_this.element);
});
}
Expand All @@ -33,6 +33,11 @@ System.register(['./i18n', 'aurelia-event-aggregator'], function (_export) {
value: function attached() {
this.i18n.updateTranslations(this.element);
}
}, {
key: 'detached',
value: function detached() {
this.__i18nDisposer();
}
}], [{
key: 'inject',
value: [I18N, Element, EventAggregator],
Expand Down
13 changes: 9 additions & 4 deletions dist/system/t.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
System.register(['./i18n'], function (_export) {
var I18N, _classCallCheck, _createClass, TValueConverter, TCustomAttribute;
System.register(['./i18n', 'aurelia-templating'], function (_export) {
var I18N, customAttribute, _classCallCheck, _createClass, TValueConverter, TCustomAttribute;

return {
setters: [function (_i18n) {
I18N = _i18n.I18N;
}, function (_aureliaTemplating) {
customAttribute = _aureliaTemplating.customAttribute;
}],
execute: function () {
'use strict';
Expand Down Expand Up @@ -38,13 +40,15 @@ System.register(['./i18n'], function (_export) {

TCustomAttribute = (function () {
function TCustomAttribute(element, i18n) {
_classCallCheck(this, TCustomAttribute);
_classCallCheck(this, _TCustomAttribute);

this.element = element;
this.service = i18n;
}

_createClass(TCustomAttribute, [{
var _TCustomAttribute = TCustomAttribute;

_createClass(_TCustomAttribute, [{
key: 'valueChanged',
value: function valueChanged() {
if (this.element.parentElement !== undefined) {
Expand All @@ -57,6 +61,7 @@ System.register(['./i18n'], function (_export) {
enumerable: true
}]);

TCustomAttribute = customAttribute('t')(TCustomAttribute) || TCustomAttribute;
return TCustomAttribute;
})();

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-i18next",
"version": "0.6.2",
"version": "0.7.0",
"description": "An Aurelia-Wrapper for the library i18next",
"keywords": [
"aurelia",
Expand Down Expand Up @@ -51,11 +51,11 @@
"Intl.js": "github:andyearnshaw/Intl.js@^0.1.4",
"aurelia-event-aggregator": "github:aurelia/event-aggregator@^0.7.0",
"aurelia-loader-default": "github:aurelia/loader-default@^0.9.5",
"aurelia-templating": "github:aurelia/templating@^0.14.4",
"i18next": "github:i18next/i18next@^1.9.0"
},
"devDependencies": {
"aurelia-dependency-injection": "github:aurelia/dependency-injection@^0.9.2",
"aurelia-templating": "github:aurelia/templating@^0.14.4",
"babel": "npm:babel-core@^5.1.13",
"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^0.9.4",
Expand Down
6 changes: 5 additions & 1 deletion src/base-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export class BaseI18N {
this.i18n = i18n;
this.element = element;

ea.subscribe('i18n:locale:changed', payload => {
this.__i18nDisposer = ea.subscribe('i18n:locale:changed', payload => {
this.i18n.updateTranslations(this.element);
});
}

attached(){
this.i18n.updateTranslations(this.element);
}

detached() {
this.__i18nDisposer();
}
}
3 changes: 3 additions & 0 deletions src/t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {I18N} from './i18n';
import {customAttribute} from 'aurelia-templating';


export class TValueConverter {
static inject() { return [I18N]; }
Expand All @@ -11,6 +13,7 @@ export class TValueConverter {
}
}

@customAttribute('t')
export class TCustomAttribute {

static inject = [Element, I18N];
Expand Down
4 changes: 2 additions & 2 deletions test/unit/i18n-attribute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe('testing i18n attributes', () => {
});


it('should raise value change on simple custom attribute', done => {
it('should raise value change on i18n custom attribute', done => {
var i18nAttribute = BehaviorInstance.createForUnitTest(TCustomAttribute);
spyOn(i18nAttribute, 'valueChanged');

i18nAttribute.value = 'foo';

setTimeout(() => {
expect(att.valueChanged).toHaveBeenCalledWith('foo', undefined);
expect(i18nAttribute.valueChanged).toHaveBeenCalledWith('foo', undefined);
done();
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/unit/mocks/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class I18N {
updateTranslations() {

}
}

0 comments on commit 62742d1

Please sign in to comment.