Skip to content

Commit

Permalink
Adding some test cases for autolink replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Jan 26, 2019
1 parent 45bd92e commit d6a0388
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions server/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func TestSpecialCases(t *testing.T) {
}, &Link{
Pattern: "(Example)",
Template: "[Example](https://example.com)",
}, &Link{
Pattern: "(https://mattermost.atlassian.net/browse/)(MM)(-)(?P<jira_id>\\d+)",
Template: "[MM-$jira_id](https://mattermost.atlassian.net/browse/MM-$jira_id)",
}, &Link{
Pattern: "(foo!bar)",
Template: "fb",
Expand Down Expand Up @@ -160,16 +163,27 @@ func TestSpecialCases(t *testing.T) {
}, {
"foo!bar & foo!bar\nfoo!bar & foo!bar\nfoo!bar & foo!bar",
"fb & fb\nfb & fb\nfb & fb",
}, {
"https://mattermost.atlassian.net/browse/MM-12345",
"[MM-12345](https://mattermost.atlassian.net/browse/MM-12345)",
}, {
"Welcome https://mattermost.atlassian.net/browse/MM-12345",
"Welcome [MM-12345](https://mattermost.atlassian.net/browse/MM-12345)",
}, {
"text https://mattermost.atlassian.net/browse/MM-12345 other text",
"text [MM-12345](https://mattermost.atlassian.net/browse/MM-12345) other text",
},
}

for _, tt := range tests {
post := &model.Post{
Message: tt.inputMessage,
}
t.Run(tt.inputMessage, func(t *testing.T) {
post := &model.Post{
Message: tt.inputMessage,
}

rpost, _ := p.MessageWillBePosted(&plugin.Context{}, post)
rpost, _ := p.MessageWillBePosted(&plugin.Context{}, post)

assert.Equal(t, tt.expectedMessage, rpost.Message)
assert.Equal(t, tt.expectedMessage, rpost.Message)
})
}
}

0 comments on commit d6a0388

Please sign in to comment.