Skip to content
Extraits de code Groupes Projets
Valider 10609c36 rédigé par Florian Staudacher's avatar Florian Staudacher
Parcourir les fichiers

fix jasmine and add some specs for direction detection

parent be860145
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -18,7 +18,7 @@
return false;
}
var charCode = str.charCodeAt(0);
var charCode = this._fixedCharCodeAt(str, 0);
if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ...
return true;
......@@ -34,6 +34,12 @@
else if(charCode>=64256 && charCode<=64335) // Hebrew present
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
return true;
......@@ -47,6 +53,39 @@
return true;
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) {
/* we return here if person.avatar is blank, because this happens when a
* 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;
if( !avatar ) return;
var name = ( person.name ) ? person.name : 'avatar';
size = ( !_.isString(size) ) ? "small" : size;
......
......@@ -6,6 +6,5 @@
//= require inbox
//= require mobile
//= require profile
//= require people
//= require contact-list
//= require sinon
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
describe("app.views.AspectsDropdown", function(){
beforeEach(function() {
spec.loadFixture("bookmarklet");
Diaspora.I18n.load({
Diaspora.I18n.reset({
'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')});
});
......
......@@ -29,7 +29,7 @@ describe("app.views.Poll", function(){
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_answer_id).toBe(answer.id);
})
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter