UNPKG

hubot-slack

Version:
193 lines (184 loc) 7.02 kB
// Generated by CoffeeScript 1.10.0 (function() { var should; should = require('should'); describe('incoming()', function() { return it('Should do nothing if there are no user links', function() { var foo; foo = this.formatter.incoming({ text: 'foo' }); return foo.should.equal('foo'); }); }); describe('links()', function() { it('Should decode entities', function() { var foo; foo = this.formatter.links('foo &gt; &amp; &lt; &gt;&amp;&lt;'); return foo.should.equal('foo > & < >&<'); }); it('Should change <@U123> links to @name', function() { var foo; foo = this.formatter.links('foo <@U123> bar'); return foo.should.equal('foo @name bar'); }); it('Should change <@U123|label> links to label', function() { var foo; foo = this.formatter.links('foo <@U123|label> bar'); return foo.should.equal('foo label bar'); }); it('Should change <#C123> links to #general', function() { var foo; foo = this.formatter.links('foo <#C123> bar'); return foo.should.equal('foo #general bar'); }); it('Should change <#C123|label> links to label', function() { var foo; foo = this.formatter.links('foo <#C123|label> bar'); return foo.should.equal('foo label bar'); }); it('Should change <!everyone> links to @everyone', function() { var foo; foo = this.formatter.links('foo <!everyone> bar'); return foo.should.equal('foo @everyone bar'); }); it('Should change <!channel> links to @channel', function() { var foo; foo = this.formatter.links('foo <!channel> bar'); return foo.should.equal('foo @channel bar'); }); it('Should change <!group> links to @group', function() { var foo; foo = this.formatter.links('foo <!group> bar'); return foo.should.equal('foo @group bar'); }); it('Should change <!here> links to @here', function() { var foo; foo = this.formatter.links('foo <!here> bar'); return foo.should.equal('foo @here bar'); }); it('Should remove formatting around <http> links', function() { var foo; foo = this.formatter.links('foo <http://www.example.com> bar'); return foo.should.equal('foo http://www.example.com bar'); }); it('Should remove formatting around <https> links', function() { var foo; foo = this.formatter.links('foo <https://www.example.com> bar'); return foo.should.equal('foo https://www.example.com bar'); }); it('Should remove formatting around <skype> links', function() { var foo; foo = this.formatter.links('foo <skype:echo123?call> bar'); return foo.should.equal('foo skype:echo123?call bar'); }); it('Should remove formatting around <https> links with a label', function() { var foo; foo = this.formatter.links('foo <https://www.example.com|label> bar'); return foo.should.equal('foo label (https://www.example.com) bar'); }); it('Should remove formatting around <https> links with a substring label', function() { var foo; foo = this.formatter.links('foo <https://www.example.com|example.com> bar'); return foo.should.equal('foo https://www.example.com bar'); }); it('Should remove formatting around <https> links with a label containing entities', function() { var foo; foo = this.formatter.links('foo <https://www.example.com|label &gt; &amp; &lt;> bar'); return foo.should.equal('foo label > & < (https://www.example.com) bar'); }); it('Should remove formatting around <mailto> links', function() { var foo; foo = this.formatter.links('foo <mailto:name@example.com> bar'); return foo.should.equal('foo name@example.com bar'); }); it('Should remove formatting around <mailto> links with an email label', function() { var foo; foo = this.formatter.links('foo <mailto:name@example.com|name@example.com> bar'); return foo.should.equal('foo name@example.com bar'); }); return it('Should change multiple links at once', function() { var foo; foo = this.formatter.links('foo <@U123|label> bar <#C123> <!channel> <https://www.example.com|label>'); return foo.should.equal('foo label bar #general @channel label (https://www.example.com)'); }); }); describe('flatten()', function() { it('Should return a basic message passed untouched', function() { var foo; foo = this.formatter.flatten({ text: 'foo' }); return foo.should.equal('foo'); }); return it('Should concatenate attachments', function() { var foo; foo = this.formatter.flatten({ text: 'foo', attachments: [ { fallback: 'bar' }, { fallback: 'baz' }, { fallback: 'qux' } ] }); return foo.should.equal('foo\nbar\nbaz\nqux'); }); }); describe('mentions()', function() { it('Should do nothing with null text', function() { var foo; foo = this.formatter.mentions() || 'die'; return foo.should.equal('die'); }); it('Should replace @name with <@U123>', function() { var foo; foo = this.formatter.mentions('Hello @name how are you?'); return foo.should.equal('Hello <@U123> how are you?'); }); it('Should replace @ keywords with <!keyword>', function() { var foo, i, keyword, len, ref, results; ref = ['channel', 'group', 'everyone', 'here']; results = []; for (i = 0, len = ref.length; i < len; i++) { keyword = ref[i]; foo = this.formatter.mentions("Hello @" + keyword + " how are you?"); results.push(foo.should.equal("Hello <!" + keyword + "> how are you?")); } return results; }); it('Should ignore @-names it doesnt recognize', function() { var foo; foo = this.formatter.mentions('Hello @thisisnotavalidatname how are you?'); return foo.should.equal('Hello @thisisnotavalidatname how are you?'); }); return it('Should replace @name with <@U123> in message objects too', function() { var foo; foo = this.formatter.mentions({ text: 'Hello @name how are you?' }); return foo.text.should.equal('Hello <@U123> how are you?'); }); return it('Should do the right thing with message objects that have as_user set too', function() { var foo; foo = this.formatter.mentions({ text: '', as_user: true }); return foo.text.should.equal('') && foo.as_user.should.equal(true);; }); }); describe('outgoing()', function() { return it('Should just pass things to mentions', function() { var foo; foo = this.formatter.mentions({ text: 'Hello @name how are you?' }); return foo.text.should.equal('Hello <@U123> how are you?'); }); }); }).call(this); //# sourceMappingURL=formatter.js.map