657327edd7
* For some reason this file shows as modified, however I checked and it seems as though the same code chunk was 'deleted' and 'added' back in * Added in logic to take care of issue pertaining to usernames with underscores such as @_spider_ was not showing up in the proper username format * Added component test to test underscores in username issue * I accidentally forgot to change the expected result to be @_user_ * Fixed strange spacing issue in profile.vue to match the original * Another place where I needed to put _user_ * Accidentally left in describe.only in highlightUsers.spec.js,so removed .only * Added in suggestions from @benkelaar and added in support for fixing double underscore sandwiched usernames which is Markdown's way of bolding * Added component test to test that usernames sandwiched with double underscores are properly formatted * Added fixes to test case input and variable mismatch in function * Updated expect result statement to not be a user mention instance Co-authored-by: Kareen <kareenf@umich.edu>
58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
import habiticaMarkdown from 'habitica-markdown';
|
|
import { highlightUsers } from '@/libs/highlightUsers';
|
|
|
|
describe('highlightUserAndEmail', () => {
|
|
it('highlights displayname', () => {
|
|
const text = 'hello @displayedUser with text after';
|
|
|
|
const result = highlightUsers(text, 'user', 'displayedUser');
|
|
|
|
expect(result).to.contain('<span class="at-text at-highlight">@displayedUser</span>');
|
|
});
|
|
|
|
it('highlights username', () => {
|
|
const text = 'hello @user';
|
|
|
|
const result = highlightUsers(text, 'user', 'displayedUser');
|
|
expect(result).to.contain('<span class="at-text at-highlight">@user</span>');
|
|
});
|
|
|
|
it('highlights username sandwiched with underscores', () => {
|
|
const text = 'hello @<em>user</em>';
|
|
|
|
const result = highlightUsers(text, '_user_', 'displayedUser');
|
|
expect(result).to.contain('<span class="at-text at-highlight">@_user_</span>');
|
|
expect(result).to.not.contain('<em>');
|
|
expect(result).to.not.contain('</em>');
|
|
});
|
|
|
|
it('highlights username sandwiched with double underscores', () => {
|
|
const text = 'hello @<strong>user</strong>';
|
|
|
|
const result = highlightUsers(text, 'diffUser', 'displayDiffUser');
|
|
expect(result).to.contain('<span class="at-text ">@__user__</span>');
|
|
expect(result).to.not.contain('<strong>');
|
|
expect(result).to.not.contain('</strong>');
|
|
});
|
|
|
|
it('not highlights any email', () => {
|
|
const text = habiticaMarkdown.render('hello@example.com');
|
|
|
|
const result = highlightUsers(text, 'example', 'displayedUser');
|
|
expect(result).to.not.contain('<span class="at-highlight">@example</span>');
|
|
});
|
|
|
|
|
|
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');
|
|
|
|
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');
|
|
});
|
|
});
|