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 Jan 7, 2025
1 parent 3c69bbe commit bb4cc97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
10 changes: 4 additions & 6 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 @@ -1325,12 +1326,8 @@ test('Test for user mention with @username@domain.com', () => {
const resultString = '<mention-user>@username@expensify.com</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 @username@domain.com', () => {
test('Test for short mention mention with @username', () => {
const testString = '@john.doe';
const resultString = '<mention-short>@john.doe</mention-short>';
expect(parser.replace(testString)).toBe(resultString);
Expand Down Expand Up @@ -1519,6 +1516,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
1 change: 0 additions & 1 deletion __tests__/ExpensiMark-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable max-len */
import ExpensiMark from '../lib/ExpensiMark';
import * as Utils from '../lib/utils';
import {any, string} from "prop-types";

const parser = new ExpensiMark();

Expand Down
47 changes: 24 additions & 23 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,29 +417,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 @@ -507,6 +484,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 bb4cc97

Please sign in to comment.