Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3149471
D9057.id31371.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9057.id31371.diff
View Options
diff --git a/web/utils/typeahead-utils.test.js b/web/utils/typeahead-utils.test.js
--- a/web/utils/typeahead-utils.test.js
+++ b/web/utils/typeahead-utils.test.js
@@ -1,6 +1,9 @@
// @flow
-import { getTypeaheadOverlayScroll } from './typeahead-utils.js';
+import {
+ getTypeaheadOverlayScroll,
+ webMentionTypeaheadRegex,
+} from './typeahead-utils.js';
import { typeaheadStyle } from '../chat/chat-constants.js';
describe('getTypeaheadOverlayScroll', () => {
@@ -30,3 +33,68 @@
),
);
});
+
+describe('webMentionTypeaheadRegex', () => {
+ const validMatches = [
+ {
+ textPrefix: '',
+ mentionText: 'mention123',
+ },
+ {
+ textPrefix: '',
+ mentionText: 'mention with space',
+ },
+ {
+ textPrefix: 'text prefix ',
+ mentionText: 'mention with space',
+ },
+ {
+ textPrefix: 'This is a test ',
+ mentionText: 'mention',
+ },
+ {
+ textPrefix: '',
+ mentionText: '',
+ },
+ {
+ textPrefix: 'A multi-line\nmention with\nnewlines ',
+ mentionText: 'mention',
+ },
+ {
+ textPrefix: 'text @first mention ',
+ mentionText: 'second mention',
+ },
+ {
+ textPrefix: 'text text \n@first \n',
+ mentionText: 'second mention',
+ },
+ ];
+
+ it('should match webMentionTypeaheadRegex', () =>
+ validMatches.forEach(validMatchObject => {
+ const text = `${validMatchObject.textPrefix}@${validMatchObject.mentionText}`;
+ const match = text.match(webMentionTypeaheadRegex);
+ expect(match).toBeTruthy();
+ expect(match?.groups?.textPrefix ?? '').toEqual(
+ validMatchObject.textPrefix,
+ );
+ expect(match?.groups?.mentionText ?? '').toEqual(
+ validMatchObject.mentionText,
+ );
+ }));
+
+ const invalidMatches = [
+ 'This is not a valid text with mention',
+ `@${'a'.repeat(200)} `,
+ 'text prefix\\@mention',
+ '@mention\nnewline \\@mention with space',
+ '\\@',
+ '\\@username',
+ '\\@thread with spaces',
+ ];
+
+ it('should not match webMentionTypeaheadRegex', () =>
+ invalidMatches.forEach(text =>
+ expect(text.match(webMentionTypeaheadRegex)).toBeFalsy(),
+ ));
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 5, 2:10 PM (15 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2426172
Default Alt Text
D9057.id31371.diff (2 KB)
Attached To
Mode
D9057: [web] Add webMentionTypeaheadRegex tests
Attached
Detach File
Event Timeline
Log In to Comment