Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing default value to extras #696

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/ExpensiMark-HTMLToText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ test('Mention user html to text', () => {
testString = '<mention-user>@user@DOMAIN.com</mention-user>';
expect(parser.htmlToText(testString)).toBe('@user@DOMAIN.com');

// When there is `accountID` and no `extras`, `@Hidden` should be returned
testString = '<mention-user accountID="1234"/>';
expect(parser.htmlToText(testString)).toBe('@Hidden');

const extras = {
accountIdToName: {
'1234': 'user@domain.com',
Expand All @@ -171,6 +175,10 @@ test('Mention report html to text', () => {
testString = '<mention-report>#room-NAME</mention-report>';
expect(parser.htmlToText(testString)).toBe('#room-NAME');

// When there is `reportID` and no `extras`, `#Hidden` should be returned
testString = '<mention-report reportID="1234"/>';
expect(parser.htmlToText(testString)).toBe('#Hidden');

const extras = {
reportIdToName: {
'1234': '#room-name',
Expand Down
8 changes: 8 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ test('Mention user html to markdown', () => {
testString = '<mention-user>@user@DOMAIN.com</mention-user>';
expect(parser.htmlToMarkdown(testString)).toBe('@user@DOMAIN.com');

// When there is `accountID` and no `extras`, `@Hidden` should be returned
testString = '<mention-user accountID="1234"/>';
expect(parser.htmlToMarkdown(testString)).toBe('@Hidden');

const extras = {
accountIdToName: {
'1234': 'user@domain.com',
Expand All @@ -781,6 +785,10 @@ test('Mention report html to markdown', () => {
testString = '<mention-report>#room-NAME</mention-report>';
expect(parser.htmlToMarkdown(testString)).toBe('#room-NAME');

// When there is `reportID` and no `extras`, `#Hidden` should be returned
testString = '<mention-report reportID="1234"/>';
expect(parser.htmlToText(testString)).toBe('#Hidden');

const extras = {
reportIdToName: {
'1234': '#room-name',
Expand Down
18 changes: 13 additions & 5 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ export default class ExpensiMark {
replacement: (match, g1, offset, string, extras) => {
const reportToNameMap = extras.reportIdToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
return '';
// eslint-disable-next-line no-console
console.warn(`[ExpensiMark] Missing report name for ID: ${ g1}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is not what I meant, we don't use console like this (as the linter is telling you). You should log using the Log class. Also please change them all to alert instead of warn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places in ExpensiMark.js there is no Log class usages - only console.warn is used twice. That's why we have done it this way. I can change it though if you think that Log is more suitable in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we use. In expensimark there are some console.warn s. That's why I've used it. Can change if you want :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm not sure why we do that, but in this case, we want the log to go to our servers or we will never know it happened, since we don't have access to user's consoles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked quickly and I don't see any usage of Log from expensify-common in E/App as well . Can we for now stay with the console.warn and check it as followup so we will fix the issue with missing extras quicker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not be using it yet, but it exists, no? Is it causing any problems if you use it? Not sure I understand the pushback...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't want to introduce any regression as Log is not yet used in ExpensiMark.
It's not a problem to change it, let me check more extensively in E/App. I'll ping you once I'll do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine, but tests are failing - I'm on it right now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwiznia I've pushed remaining changes. Tests were failing due to wrong test environment (as now we need window to be defined - this is used in log implementation)

return '#Hidden';
}

return reportToNameMap[g1];
Expand All @@ -485,7 +487,9 @@ export default class ExpensiMark {
replacement: (match, g1, offset, string, extras) => {
const accountToNameMap = extras.accountIdToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
return '';
// eslint-disable-next-line no-console
console.warn(`[ExpensiMark] Missing account name for ID: ${ g1}`);
return '@Hidden';
}

return `@${extras.accountIdToName[g1]}`;
Expand Down Expand Up @@ -540,7 +544,9 @@ export default class ExpensiMark {
replacement: (match, g1, offset, string, extras) => {
const reportToNameMap = extras.reportIdToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
return '';
// eslint-disable-next-line no-console
console.warn(`[ExpensiMark] Missing report name for ID: ${ g1}`);
return '#Hidden';
}

return reportToNameMap[g1];
Expand All @@ -552,7 +558,9 @@ export default class ExpensiMark {
replacement: (match, g1, offset, string, extras) => {
const accountToNameMap = extras.accountIdToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
return '';
// eslint-disable-next-line no-console
console.warn(`[ExpensiMark] Missing account name for ID: ${ g1}`);
return '@Hidden';
}

return `@${extras.accountIdToName[g1]}`;
Expand Down Expand Up @@ -895,7 +903,7 @@ export default class ExpensiMark {
*
* @returns {String}
*/
htmlToText(htmlString, extras) {
htmlToText(htmlString, extras = {}) {
let replacedText = htmlString;
const processRule = (rule) => {
// if replacement is a function, we want to pass optional extras to it
Expand Down
Loading