-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
86 lines (68 loc) · 2.98 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Test Gulp Plugin
*
* I'm not going to write tests for traverse, but instead focus on the actual pseudo translating code
*
* @todo write more tests, angular specific stuff (once code written)
*/
var assert = require('assert');
var pseudoTranslator = require('./');
describe('gulp-pseudo-translate-angular-json', function() {
// Simple Test (Text Conversion to Pseudo)
describe('Text to Pseudo conversion', function() {
it('converts a regular line of text into its pseudo version', function(done) {
// Create a prefixer plugin stream
var testJSON = {
'helloWorld': 'Hello World'
};
// Translate it with no padding
var translatedJson = pseudoTranslator(testJSON, {increasePercent: 0}); // 0 padding
// It should equal this
assert.equal(translatedJson.helloWorld, 'Hèℓℓô Wôřℓδ');
done();
});
});
// Test for skipping Angular Expressions but still pseudo translate text outside
describe('Text to Pseudo Conversion but Skip Angular Expressions', function(){
it('converts a regular line of text with an Angular Expression into pseudo while maintaining the integrity of the Angular Expression', function(done){
var testJSON = {
'angularExpressionTest': '{{cobrandName}} is awesome!'
};
// Translate it with no padding
var translatedJson = pseudoTranslator(testJSON, {increasePercent: 0}); // 0 padding
// It should equal this
assert.equal(translatedJson.angularExpressionTest, '{{cobrandName}} ïƨ áωèƨô₥è!');
done();
});
});
// Test for skipping linked ID's (an Angular-Translate feature, supported by this plugin)
describe('Do not convert ID links for Angular-Translate', function() {
it('recognizes an ID link and skips it from pseudo conversion', function(done){
var testJSON = {
'common': {
'welcomeToTheSite': 'Welcome to the Site'
},
'pointToAnotherID': '@:common.welcomeToTheSite'
};
// Pseudo translate
var translatedJson = pseudoTranslator(testJSON, {increasePercent: 0});
// The link should be the same, but the another key value pair should be converted
assert.equal(translatedJson.common.welcomeToTheSite, 'Wèℓçô₥è ƭô ƭλè §ïƭè');
assert.equal(translatedJson.pointToAnotherID, '@:common.welcomeToTheSite');
done();
});
});
// Test for Skipping Angular Expressions but translated ngMessageFormat Copy
describe('Text to Pseudo Conversion, Maintain Integrity of ngMessageFormat Expressions while converting only copy of those expressions to Pseudo', function() {
it('recognizes the ngMessageFormat and only translates the copy to be displayed, not the code', function(done){
var testJSON = {
'count': '{{count, select, 1{One} other{Many}}}'
};
// pseudo translate
var translatedJson = pseudoTranslator(testJSON, {increasePercent: 0});
// Assertions
assert.equal(translatedJson.count, '{{count, select, 1{Óñè} other{Máñ¥}}}');
done();
});
});
});