2019-02-07 16:55:36 +00:00
|
|
|
import habiticaMarkdown from 'habitica-markdown';
|
2019-10-09 18:08:36 +00:00
|
|
|
import { highlightUsers } from '@/libs/highlightUsers';
|
2019-02-07 16:55:36 +00:00
|
|
|
|
|
|
|
|
describe('highlightUserAndEmail', () => {
|
|
|
|
|
it('highlights displayname', () => {
|
2019-02-10 18:27:22 +00:00
|
|
|
const text = 'hello @displayedUser with text after';
|
2019-02-07 16:55:36 +00:00
|
|
|
|
|
|
|
|
const result = highlightUsers(text, 'user', 'displayedUser');
|
2019-02-10 18:27:22 +00:00
|
|
|
|
2019-02-15 22:01:33 +00:00
|
|
|
expect(result).to.contain('<span class="at-text at-highlight">@displayedUser</span>');
|
2019-02-07 16:55:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('highlights username', () => {
|
|
|
|
|
const text = 'hello @user';
|
|
|
|
|
|
|
|
|
|
const result = highlightUsers(text, 'user', 'displayedUser');
|
2019-02-15 22:01:33 +00:00
|
|
|
expect(result).to.contain('<span class="at-text at-highlight">@user</span>');
|
2019-02-07 16:55:36 +00:00
|
|
|
});
|
|
|
|
|
|
2019-02-10 18:27:22 +00:00
|
|
|
it('not highlights any email', () => {
|
|
|
|
|
const text = habiticaMarkdown.render('hello@example.com');
|
2019-02-07 16:55:36 +00:00
|
|
|
|
2019-02-10 18:27:22 +00:00
|
|
|
const result = highlightUsers(text, 'example', 'displayedUser');
|
|
|
|
|
expect(result).to.not.contain('<span class="at-highlight">@example</span>');
|
2019-02-07 16:55:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2019-02-10 18:27:22 +00:00
|
|
|
it('complex highlight', () => {
|
|
|
|
|
const plainText = 'a bit more @mentions to @use my@mentions.com broken.@mail.com';
|
|
|
|
|
|
|
|
|
|
const text = habiticaMarkdown.render(plainText);
|
|
|
|
|
|
|
|
|
|
const result = highlightUsers(text, 'use', 'mentions');
|
|
|
|
|
|
2019-02-15 22:01:33 +00:00
|
|
|
expect(result).to.contain('<span class="at-text at-highlight">@mentions</span>');
|
|
|
|
|
expect(result).to.contain('<span class="at-text at-highlight">@use</span>');
|
|
|
|
|
expect(result).to.not.contain('<span class="at-text at-highlight">@mentions</span>.com');
|
2019-02-07 16:55:36 +00:00
|
|
|
});
|
|
|
|
|
});
|