-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show current user mention in MarkdownTextInput with green outline
- Loading branch information
Showing
2 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type {MarkdownRange} from '@expensify/react-native-live-markdown'; | ||
import {decorateRangesWithCurrentUser} from '@components/RNMarkdownTextInput'; | ||
|
||
describe('decorateRangesWithCurrentUser', () => { | ||
test('returns empty list for empty text', () => { | ||
const result = decorateRangesWithCurrentUser([], '', ''); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('returns empty list when there are no mentions', () => { | ||
const text = 'Lorem ipsum'; | ||
const result = decorateRangesWithCurrentUser([], text, ''); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('returns unchanged ranges when there are other markups than user-mentions', () => { | ||
const text = 'Lorem ipsum'; | ||
const ranges: MarkdownRange[] = [ | ||
{ | ||
type: 'bold', | ||
start: 5, | ||
length: 3, | ||
}, | ||
]; | ||
const result = decorateRangesWithCurrentUser(ranges, text, ''); | ||
expect(result).toEqual([ | ||
{ | ||
type: 'bold', | ||
start: 5, | ||
length: 3, | ||
}, | ||
]); | ||
}); | ||
|
||
test('returns ranges with current user type changed to "mention-here"', () => { | ||
const text = 'Lorem ipsum @myUser'; | ||
const ranges: MarkdownRange[] = [ | ||
{ | ||
type: 'bold', | ||
start: 5, | ||
length: 3, | ||
}, | ||
{ | ||
type: 'mention-user', | ||
start: 12, | ||
length: 8, | ||
}, | ||
]; | ||
const result = decorateRangesWithCurrentUser(ranges, text, 'myUser'); | ||
expect(result).toEqual([ | ||
{ | ||
type: 'bold', | ||
start: 5, | ||
length: 3, | ||
}, | ||
{ | ||
type: 'mention-here', | ||
start: 12, | ||
length: 8, | ||
}, | ||
]); | ||
}); | ||
}); |