mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
https://github.com/Human-Connection/Human-Connection/pull/952#pullrequestreview-269406016
31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
import extractMentionedUsers from './extractMentionedUsers'
|
|
|
|
const contentWithMentions =
|
|
'<p>Something inspirational about <a href="/profile/u2" class="not-a-mention" data-mention-id="bobs-id" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock" class="mention" data-mention-id="u3" target="_blank">@jenny-rostock</a>.</p>'
|
|
const contentEmptyMentions =
|
|
'<p>Something inspirational about <a href="/profile/u2" data-mention-id="" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock" class="mention" data-mention-id target="_blank">@jenny-rostock</a>.</p>'
|
|
const contentWithPlainLinks =
|
|
'<p>Something inspirational about <a class="mention" href="/profile/u2" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3" target="_blank">@jenny-rostock</a>.</p>'
|
|
|
|
describe('extractMentionedUsers', () => {
|
|
describe('content undefined', () => {
|
|
it('returns empty array', () => {
|
|
expect(extractMentionedUsers()).toEqual([])
|
|
})
|
|
})
|
|
|
|
it('ignores links without .mention class', () => {
|
|
expect(extractMentionedUsers(contentWithPlainLinks)).toEqual([])
|
|
})
|
|
|
|
describe('given a link with .mention class and `data-mention-id` attribute ', () => {
|
|
it('extracts ids', () => {
|
|
expect(extractMentionedUsers(contentWithMentions)).toEqual(['u3'])
|
|
})
|
|
|
|
it('ignores empty `data-mention-id` attributes', () => {
|
|
expect(extractMentionedUsers(contentEmptyMentions)).toEqual([])
|
|
})
|
|
})
|
|
})
|