TT MS; fix a bug when the mention string is not actually in the mentions

This commit is contained in:
Maxwell Salzberg 2012-01-16 15:59:40 -08:00
parent 5d01904231
commit d5563d8802
2 changed files with 11 additions and 5 deletions

View file

@ -25,11 +25,11 @@
textFormatter.mentionify = function mentionify(text, mentions) {
var mentionRegex = /@\{([^;]+); ([^\}]+)\}/g
return text.replace(mentionRegex, function(mentionText, fullName, diasporaId) {
var personId = _.find(mentions, function(person){
var person = _.find(mentions, function(person){
return person.diaspora_id == diasporaId
}).id
return "<a href='/people/" + personId + "' class='mention'>" + fullName + "</a>"
})
return person ? "<a href='/people/" + person.id + "' class='mention'>" + fullName + "</a>" : fullName;
})
}

View file

@ -103,7 +103,13 @@ describe("app.helpers.textFormatter", function(){
_.each([this.alice, this.bob], function(person) {
expect(wrapper.find("a[href='/people/" + person.id + "']").text()).toContain(person.name)
})
})
});
it('returns the name of the mention if the mention does not exist in the array', function(){
var text = "hey there @{Chris Smith; chris@example.com}"
var formattedText = this.formatter.mentionify(text, [])
expect(formattedText.match(/\<a/)).toBeNull();
});
})
})
})