@ -224,4 +224,64 @@ describe('Mention Server', () => {
expect ( result ) . to . be . deep . equal ( expected ) ;
} ) ;
} ) ;
describe ( 'getUserMentions' , ( ) => {
describe ( 'for message with only an md link' , ( ) => {
const result = [ ] ;
[
'[@rocket.cat](https://rocket.chat)' ,
'[@rocket.cat](https://rocket.chat) hello' ,
'[@rocket.cat](https://rocket.chat) hello how are you?' ,
'[test](https://rocket.chat)' ,
] . forEach ( ( text ) => {
it ( ` should return " ${ JSON . stringify ( result ) } " from " ${ text } " ` , ( ) => {
expect ( result ) . to . be . deep . equal ( mention . getUserMentions ( text ) ) ;
} ) ;
} ) ;
} ) ;
describe ( 'for message with md link and text' , ( ) => {
const result = [ '@sauron' ] ;
[
'@sauron please work on [user@password](https://rocket.chat)' ,
'@sauron hello [user@password](https://rocket.chat) hello' ,
'[user@password](https://rocket.chat) hello @sauron' ,
'@sauron please work on [user@password](https://rocket.chat) hello' ,
] . forEach ( ( text ) => {
it ( ` should return " ${ JSON . stringify ( result ) } " from " ${ text } " ` , ( ) => {
expect ( result ) . to . be . deep . equal ( mention . getUserMentions ( text ) ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'getChannelMentions' , ( ) => {
describe ( 'for message with md link' , ( ) => {
const result = [ ] ;
[
'[#general](https://rocket.chat)' ,
'[#general](https://rocket.chat) hello' ,
'[#general](https://rocket.chat) hello how are you?' ,
'[test #general #other](https://rocket.chat)' ,
] . forEach ( ( text ) => {
it ( ` should return " ${ JSON . stringify ( result ) } " from " ${ text } " ` , ( ) => {
expect ( result ) . to . be . deep . equal ( mention . getChannelMentions ( text ) ) ;
} ) ;
} ) ;
} ) ;
describe ( 'for message with md link and text' , ( ) => {
const result = [ '#somechannel' ] ;
[
'#somechannel please [user#password](https://rocket.chat)' ,
'#somechannel hello [user#password](https://rocket.chat) hello' ,
'[user#password](https://rocket.chat) hello #somechannel' ,
'#somechannel join [#general on #other](https://rocket.chat)' ,
] . forEach ( ( text ) => {
it ( ` should return " ${ JSON . stringify ( result ) } " from " ${ text } " ` , ( ) => {
expect ( result ) . to . be . deep . equal ( mention . getChannelMentions ( text ) ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;