Skip to content

Commit

Permalink
Cleanup and fix short-mentions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicu committed Dec 30, 2024
1 parent e4c39fb commit c9e41a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
8 changes: 3 additions & 5 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ test('Test url replacements', () => {
'@test.com <a href="https://test.com" target="_blank" rel="noreferrer noopener">test.com</a> ' +
'@test.com @test.com ';

// Fixme [short-mention] this errors on "test.com</a> @test.com @test.com <a" - probably @test.com should be a legit short-mention candidate
expect(parser.replace(urlTestStartString)).toBe(urlTestReplacedString);
});

Expand Down Expand Up @@ -931,7 +932,7 @@ test('Test urls autolinks correctly', () => {
},
];

// Fixme @expensify.com is a now correct "possible" short mention
// Fixme [short-mention] @expensify.com should now be considered a short-mention "candidate"
testCases.forEach((testCase) => {
expect(parser.replace(testCase.testString)).toBe(testCase.resultString);
});
Expand Down Expand Up @@ -1321,10 +1322,6 @@ test('Test for user mention with @[email protected]', () => {
const resultString = '<mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);
});
// Todo
// popraw psujący się @here testy
// Todo wszystkie edge kejsy w których short mention jest ambiguous
// short-mention -> possible-short-mention

test('Test for short mention mention with @[email protected]', () => {
const testString = '@john.doe';
Expand Down Expand Up @@ -1515,6 +1512,7 @@ test('Test for @here mention with italic, bold and strikethrough styles', () =>
' @here!' +
' @here?';

// Fixme [short-mention] these should now be short-mention candidates
const resultString =
'<mention-here>@here</mention-here>' +
' <em><mention-here>@here</mention-here></em>' +
Expand Down
47 changes: 24 additions & 23 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,29 +414,6 @@ export default class ExpensiMark {
},
},

{
name: 'shortMentions',
regex: new RegExp(
"(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?<end>.*))\\S{3,254}(?=\\k<end>$))(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))",
'gim',
),
replacement: (_extras, match, g1, g2) => {
if (!Str.isValidMention(match)) {
return match;
}
return `${g1}<mention-short>${g2}</mention-short>`;
},
// rawInputReplacement: (_extras, match, g1, g2) => {
// const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`);
// const mention = g2.slice(1);
// const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention);
// if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) {
// return match;
// }
// return `${g1}<mention-user>${g2}</mention-user>`;
// },
},

{
name: 'quote',

Expand Down Expand Up @@ -504,6 +481,30 @@ export default class ExpensiMark {
rawInputReplacement: '$1<a href="mailto:$2" data-raw-href="$2" data-link-variant="auto">$2</a>',
},

{
name: 'shortMentions',

regex: new RegExp(
"(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?<end>.*))\\S{3,254}(?=\\k<end>$))(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))",
'gim',
),
replacement: (_extras, match, g1, g2) => {
if (!Str.isValidMention(match)) {
return match;
}
return `${g1}<mention-short>${g2}</mention-short>`;
},
// rawInputReplacement: (_extras, match, g1, g2) => {
// const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`);
// const mention = g2.slice(1);
// const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention);
// if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) {
// return match;
// }
// return `${g1}<mention-user>${g2}</mention-user>`;
// },
},

{
// Use \B in this case because \b doesn't match * or ~.
// \B will match everything that \b doesn't, so it works
Expand Down

0 comments on commit c9e41a1

Please sign in to comment.