2015-11-26 10:29:59 +08:00
|
|
|
Autolinker = require 'autolinker'
|
|
|
|
AutolinkerExtension = require '../lib/plugins/autolinker-extension'
|
|
|
|
|
|
|
|
describe "AutolinkerExtension", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(Autolinker, 'link').andCallFake (txt) => txt
|
|
|
|
|
|
|
|
it "should call through to Autolinker", ->
|
2015-12-31 00:36:47 +08:00
|
|
|
AutolinkerExtension.formatMessageBody(message: {body:'body'})
|
2015-11-26 10:29:59 +08:00
|
|
|
expect(Autolinker.link).toHaveBeenCalledWith('body', {twitter: false})
|
|
|
|
|
|
|
|
it "should add a title to everything with an href", ->
|
|
|
|
message =
|
|
|
|
body: """
|
|
|
|
<a href="apple.com">hello world!</a>
|
|
|
|
<a href = "http://apple.com">hello world!</a>
|
|
|
|
<a href ='http://apple.com'>hello world!</a>
|
|
|
|
<a href ='mailto://'>hello world!</a>
|
|
|
|
"""
|
|
|
|
expected =
|
|
|
|
body: """
|
|
|
|
<a href="apple.com" title="apple.com" >hello world!</a>
|
|
|
|
<a href = "http://apple.com" title="http://apple.com" >hello world!</a>
|
2016-02-24 10:20:26 +08:00
|
|
|
<a href ='http://apple.com' title="http://apple.com" >hello world!</a>
|
|
|
|
<a href ='mailto://' title="mailto://" >hello world!</a>
|
2015-11-26 10:29:59 +08:00
|
|
|
"""
|
2015-12-31 00:36:47 +08:00
|
|
|
AutolinkerExtension.formatMessageBody({message})
|
2015-11-26 10:29:59 +08:00
|
|
|
expect(message.body).toEqual(expected.body)
|