fix jasmine and add some specs for direction detection
This commit is contained in:
parent
be86014540
commit
10609c3692
6 changed files with 88 additions and 7 deletions
|
|
@ -18,7 +18,7 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var charCode = str.charCodeAt(0);
|
var charCode = this._fixedCharCodeAt(str, 0);
|
||||||
if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ...
|
if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ...
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -34,6 +34,12 @@
|
||||||
else if(charCode>=64256 && charCode<=64335) // Hebrew present
|
else if(charCode>=64256 && charCode<=64335) // Hebrew present
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
else if(charCode>=68096 && charCode<=68184) // Kharoshthi
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if(charCode>=67840 && charCode<=67871) // Phoenician
|
||||||
|
return true;
|
||||||
|
|
||||||
else if(charCode>=1792 && charCode<=1871) // Syriac
|
else if(charCode>=1792 && charCode<=1871) // Syriac
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -47,6 +53,39 @@
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
|
||||||
|
_fixedCharCodeAt: function(str, idx) {
|
||||||
|
str += '';
|
||||||
|
var code,
|
||||||
|
end = str.length;
|
||||||
|
|
||||||
|
var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||||
|
while ((surrogatePairs.exec(str)) != null) {
|
||||||
|
var li = surrogatePairs.lastIndex;
|
||||||
|
if (li - 2 < idx) {
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx >= end || idx < 0) {
|
||||||
|
return NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = str.charCodeAt(idx);
|
||||||
|
|
||||||
|
var hi, low;
|
||||||
|
if (0xD800 <= code && code <= 0xDBFF) {
|
||||||
|
hi = code;
|
||||||
|
low = str.charCodeAt(idx+1);
|
||||||
|
// Go one further, since one of the "characters" is part of a surrogate pair
|
||||||
|
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,9 @@ Handlebars.registerHelper('hovercardable', function(person) {
|
||||||
Handlebars.registerHelper('personImage', function(person, size, imageClass) {
|
Handlebars.registerHelper('personImage', function(person, size, imageClass) {
|
||||||
/* we return here if person.avatar is blank, because this happens when a
|
/* we return here if person.avatar is blank, because this happens when a
|
||||||
* user is unauthenticated. we don't know why this happens... */
|
* user is unauthenticated. we don't know why this happens... */
|
||||||
|
if( !person.avatar &&
|
||||||
|
!(person.profile && person.profile.avatar) ) return;
|
||||||
var avatar = person.avatar || person.profile.avatar;
|
var avatar = person.avatar || person.profile.avatar;
|
||||||
if( !avatar ) return;
|
|
||||||
|
|
||||||
var name = ( person.name ) ? person.name : 'avatar';
|
var name = ( person.name ) ? person.name : 'avatar';
|
||||||
size = ( !_.isString(size) ) ? "small" : size;
|
size = ( !_.isString(size) ) ? "small" : size;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,5 @@
|
||||||
//= require inbox
|
//= require inbox
|
||||||
//= require mobile
|
//= require mobile
|
||||||
//= require profile
|
//= require profile
|
||||||
//= require people
|
|
||||||
//= require contact-list
|
//= require contact-list
|
||||||
//= require sinon
|
//= require sinon
|
||||||
|
|
|
||||||
37
spec/javascripts/app/helpers/direction_detector_spec.js
Normal file
37
spec/javascripts/app/helpers/direction_detector_spec.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
describe("app.helpers.txtDirection", function() {
|
||||||
|
context("#isRTL", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.samples = {
|
||||||
|
"ثم بغزو ناجازاكي الأوروبي بال, ": "rtl", // arabic
|
||||||
|
"אם ברית מחליטה זכר, צ'ט לשון": "rtl", // hebrew
|
||||||
|
"ߊߍߌߐߎ": "rtl", // n'ko
|
||||||
|
"𐨙𐨜𐨪𐨭𐨢": "rtl", // Kharoshthi
|
||||||
|
"𐤂𐤃𐤄𐤅𐤆𐤇𐤈𐤉𐤊": "rtl", // Phoenecian
|
||||||
|
"ܫܠܡܐ": "rtl", //syriac
|
||||||
|
"ހަށް ގޮސް އުޅޭ އިރު": "rtl", // thaana
|
||||||
|
"ⴻⴼⴽⵄⵅⵆⵇ": "rtl", // Tifinagh
|
||||||
|
"ᚳᚴᚵᚶᚷᚸᚹᛅᛆᛇᛈᛉᛊᛋ": "ltr", // Runes
|
||||||
|
"ΘΛΞΠΣΦΨΩέαβγζλφχψϖϗ": "ltr", // Greek
|
||||||
|
"経担裁洋府時話家": "ltr", // Chinese
|
||||||
|
"Анёмал зэнтынтиаэ": "ltr", // Cyrillic
|
||||||
|
"उपेक्ष सोफ़्टवेर विचारशिलता": "ltr", // Hindi
|
||||||
|
"選そ前制数えほ長春セ名": "ltr", // Japanese
|
||||||
|
"ascii text": "ltr",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("detects the right text direction", function() {
|
||||||
|
_.each(this.samples, function(dir, str) {
|
||||||
|
var result = app.helpers.txtDirection.isRTL(str);
|
||||||
|
if( result ) {
|
||||||
|
expect(dir).toEqual('rtl');
|
||||||
|
} else {
|
||||||
|
expect(dir).toEqual('ltr');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
101
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
describe("app.views.AspectsDropdown", function(){
|
describe("app.views.AspectsDropdown", function(){
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
spec.loadFixture("bookmarklet");
|
spec.loadFixture("bookmarklet");
|
||||||
Diaspora.I18n.load({
|
Diaspora.I18n.reset({
|
||||||
'aspect_dropdown': {
|
'aspect_dropdown': {
|
||||||
'select_aspects': "Select aspects"
|
'select_aspects': "Select aspects",
|
||||||
});
|
'all_aspects': "All Aspects",
|
||||||
|
'toggle': {
|
||||||
|
'zero': "Select aspects",
|
||||||
|
'one': "In <%= count %> aspect",
|
||||||
|
'other': "In <%= count %> aspects"
|
||||||
|
}}});
|
||||||
this.view = new app.views.AspectsDropdown({el: $('.aspect_dropdown')});
|
this.view = new app.views.AspectsDropdown({el: $('.aspect_dropdown')});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ describe("app.views.Poll", function(){
|
||||||
|
|
||||||
this.view.vote(answer.id);
|
this.view.vote(answer.id);
|
||||||
|
|
||||||
var obj = jasmine.Ajax.requests.mostRecent().params);
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
||||||
expect(obj.poll_id).toBe(poll.poll_id);
|
expect(obj.poll_id).toBe(poll.poll_id);
|
||||||
expect(obj.poll_answer_id).toBe(answer.id);
|
expect(obj.poll_answer_id).toBe(answer.id);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue