hubot-slack
Version:
A Slack adapter for hubot
111 lines (81 loc) • 4.28 kB
text/coffeescript
should = require 'should'
describe 'incoming()', ->
it 'Should do nothing if there are no user links', ->
foo = @formatter.incoming {text: 'foo'}
foo.should.equal 'foo'
describe 'links()', ->
it 'Should decode entities', ->
foo = @formatter.links 'foo > & < >&<'
foo.should.equal 'foo > & < >&<'
it 'Should change <@U123> links to @name', ->
foo = @formatter.links 'foo <@U123> bar'
foo.should.equal 'foo @name bar'
it 'Should change <@U123|label> links to @label', ->
foo = @formatter.links 'foo <@U123|label> bar'
foo.should.equal 'foo @label bar'
it 'Should change <#C123> links to #general', ->
foo = @formatter.links 'foo <#C123> bar'
foo.should.equal 'foo #general bar'
it 'Should change <#C123|label> links to #label', ->
foo = @formatter.links 'foo <#C123|label> bar'
foo.should.equal 'foo #label bar'
it 'Should change links to @everyone', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo @everyone bar'
it 'Should change links to @channel', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo @channel bar'
it 'Should change links to @group', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo @group bar'
it 'Should change links to @here', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo @here bar'
it 'Should change links to @subteam', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo @subteam bar'
it 'Should change links to hello', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo hello bar'
it 'Should leave links as-is when no label is provided', ->
foo = @formatter.links 'foo bar'
foo.should.equal 'foo bar'
it 'Should remove formatting around <http> links', ->
foo = @formatter.links 'foo <http://www.example.com> bar'
foo.should.equal 'foo http://www.example.com bar'
it 'Should remove formatting around <https> links', ->
foo = @formatter.links 'foo <https://www.example.com> bar'
foo.should.equal 'foo https://www.example.com bar'
it 'Should remove formatting around <skype> links', ->
foo = @formatter.links 'foo <skype:echo123?call> bar'
foo.should.equal 'foo skype:echo123?call bar'
it 'Should remove formatting around <https> links with a label', ->
foo = @formatter.links 'foo <https://www.example.com|label> bar'
foo.should.equal 'foo label (https://www.example.com) bar'
it 'Should remove formatting around <https> links with a substring label', ->
foo = @formatter.links 'foo <https://www.example.com|example.com> bar'
foo.should.equal 'foo https://www.example.com bar'
it 'Should remove formatting around <https> links with a label containing entities', ->
foo = @formatter.links 'foo <https://www.example.com|label > & <> bar'
foo.should.equal 'foo label > & < (https://www.example.com) bar'
it 'Should remove formatting around <mailto> links', ->
foo = @formatter.links 'foo <mailto:name@example.com> bar'
foo.should.equal 'foo name@example.com bar'
it 'Should remove formatting around <mailto> links with an email label', ->
foo = @formatter.links 'foo <mailto:name@example.com|name@example.com> bar'
foo.should.equal 'foo name@example.com bar'
it 'Should change multiple links at once', ->
foo = @formatter.links 'foo <@U123|label> bar <#C123> <https://www.example.com|label>'
foo.should.equal 'foo @label bar #general @channel label (https://www.example.com)'
describe 'flatten()', ->
it 'Should return a basic message passed untouched', ->
foo = @formatter.flatten {text: 'foo'}
foo.should.equal 'foo'
it 'Should concatenate attachments', ->
foo = @formatter.flatten {text: 'foo', attachments: [{fallback: 'bar'}, {fallback: 'baz'}, {fallback: 'qux'}]}
foo.should.equal 'foo\nbar\nbaz\nqux'
describe 'warnForDeprecation()', ->
it 'Should warn of deprecation', ->
{logger} = @slackbot.robot
@formatter.warnForDeprecation()
@stubs.robot.logger.logs?.warning.length.should.equal 1