describe("app.helpers.textFormatter", function(){
beforeEach(function(){
this.statusMessage = factory.post();
this.formatter = app.helpers.textFormatter;
});
// Some basic specs. For more detailed specs see
// https://github.com/svbergerem/markdown-it-hashtag/tree/master/test
context("hashtags", function() {
beforeEach(function() {
this.goodTags = [
"tag",
"diaspora",
"PARTIES",
"<3",
"diaspora-dev",
"diaspora_dev",
// issue #5765
"മലയാണ്മ",
// issue #5815
"ինչո՞ւ",
"այո՜ո",
"սեւ֊սպիտակ",
"գժանո՛ց"
];
this.badTags = [
"tag.tag",
"hash:tag",
"hash*tag"
];
});
it("renders good tags as links", function() {
var self = this;
this.goodTags.forEach(function(tag) {
var formattedText = self.formatter("#newhashtag #" + tag + " test");
var link = "#" + tag.replace("<", "<") + "";
expect(formattedText).toContain(link);
});
});
it("doesn't render bad tags as links", function() {
var self = this;
this.badTags.forEach(function(tag) {
var formattedText = self.formatter("#newhashtag #" + tag + " test");
var link = "#" + tag.replace("<", "<") + "";
expect(formattedText).not.toContain(link);
});
});
});
// Some basic specs. For more detailed specs see
// https://github.com/diaspora/markdown-it-diaspora-mention/tree/master/test
context("mentions", function() {
beforeEach(function(){
this.alice = factory.author({
name : "Alice Smith",
diaspora_id : "alice@example.com",
guid: "555",
id : "555"
});
this.bob = factory.author({
name : "Bob Grimm",
diaspora_id : "bob@example.com",
guid: "666",
id : "666"
});
this.statusMessage.set({text: "hey there @{Alice Smith; alice@example.com} and @{Bob Grimm; bob@example.com}"});
this.statusMessage.set({mentioned_people : [this.alice, this.bob]});
});
it("matches mentions", function(){
var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people"));
var wrapper = $("
").html(formattedText);
_.each([this.alice, this.bob], function(person) {
expect(wrapper.find("a[href='/people/" + person.guid + "']").text()).toContain(person.name);
});
});
it("returns mentions for on posts that haven't been saved yet (framer posts)", function(){
var freshBob = factory.author({
name : "Bob Grimm",
handle : "bob@example.com",
url : 'googlebot.com',
id : "666"
});
this.statusMessage.set({'mentioned_people' : [freshBob] });
var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people"));
var wrapper = $("
").html(formattedText);
expect(wrapper.find("a[href='googlebot.com']").text()).toContain(freshBob.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(text, []);
expect(formattedText.match(/
").html(formattedText);
expect(wrapper.find("a[href='/people/" + this.alice.guid + "']")).not.toHaveClass('hovercardable');
expect(wrapper.find("a[href='/people/" + this.bob.guid + "']")).toHaveClass('hovercardable');
});
it("supports mentions without a given name", function() {
this.statusMessage.set({text: "hey there @{alice@example.com} and @{bob@example.com}"});
var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people"));
var wrapper = $("").html(formattedText);
_.each([this.alice, this.bob], function(person) {
expect(wrapper.find("a[href='/people/" + person.guid + "']").text()).toContain(person.name);
});
});
it("it uses the name given in the mention if it exists", function() {
this.statusMessage.set({text: "hey there @{Alice Awesome; alice@example.com} and @{bob@example.com}"});
var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people"));
var wrapper = $("
").html(formattedText);
expect(wrapper.find("a[href='/people/" + this.alice.guid + "']").text()).toContain("Alice Awesome");
expect(wrapper.find("a[href='/people/" + this.bob.guid + "']").text()).toContain(this.bob.name);
});
});
context("highlight", function(){
it("works with javascript code", function(){
var code = "```js\nfunction test() { return; } //test\n```";
expect(this.formatter(code)).toContain("");
expect(this.formatter(code)).toContain("