Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32392152
D9057.1765336373.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D9057.1765336373.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
Wed, Dec 10, 3:12 AM (9 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5859997
Default Alt Text
D9057.1765336373.diff (2 KB)
Attached To
Mode
D9057: [web] Add webMentionTypeaheadRegex tests
Attached
Detach File
Event Timeline
Log In to Comment