Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/libs/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const accountIDToNameMap: Record<string, string> = {};

const reportIDToNameMap: Record<string, string> = {};
Onyx.connect({

Check warning on line 10 in src/libs/Parser.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -24,7 +24,7 @@
},
});

Onyx.connect({

Check warning on line 27 in src/libs/Parser.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (personalDetailsList) => {
for (const personalDetails of Object.values(personalDetailsList ?? {})) {
Expand Down Expand Up @@ -61,6 +61,10 @@
});
}

isHTML(text: string): boolean {
return /<[^>]+>/.test(text) || /&[#\w]+;/.test(text);
}

truncateHTML(htmlString: string, limit: number, extras?: {ellipsis: string | undefined}): string {
return super.truncateHTML(htmlString, limit, extras);
}
Expand Down
4 changes: 3 additions & 1 deletion src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

Onyx.connect({

Check warning on line 143 in src/libs/ReportNameUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value;
Expand Down Expand Up @@ -776,7 +776,9 @@
}

if (isTaskReport(report)) {
return Parser.htmlToText(report?.reportName ?? '').trim();
const taskName = report?.reportName ?? '';

return Parser.isHTML(taskName) ? Parser.htmlToText(taskName).trim() : taskName.trim();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it worth moving the Parser.isHTML check into the Parser.htmlToText method? Or should we maintain the separation of concerns between those methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should always target to maintain the separation of concerns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make senses 👍

}

const privateIsArchivedValue = privateIsArchived ?? allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1016 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1021,7 +1021,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1024 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1039,7 +1039,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1042 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1051,7 +1051,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1054 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1060,7 +1060,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1063 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1071,7 +1071,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1074 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1079,7 +1079,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1082 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -5757,7 +5757,8 @@
}

if (isTaskReport(report)) {
return Parser.htmlToText(report?.reportName ?? '').trim();
const taskName = report?.reportName ?? '';
return Parser.isHTML(taskName) ? Parser.htmlToText(taskName).trim() : taskName.trim();
}

if (isChatThread(report)) {
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/ParserTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Parser from '@libs/Parser';

describe('Parser', () => {
describe('isHTML', () => {
test('returns true for strings containing HTML tags', () => {
expect(Parser.isHTML('<b>bold</b>')).toBe(true);
expect(Parser.isHTML('<a href="https://example.com">link</a>')).toBe(true);
expect(Parser.isHTML('<h1>heading</h1>')).toBe(true);
expect(Parser.isHTML('text with <em>emphasis</em> inside')).toBe(true);
expect(Parser.isHTML('<br/>')).toBe(true);
expect(Parser.isHTML('<p>paragraph</p>')).toBe(true);
});

test('returns false for plain text', () => {
expect(Parser.isHTML('just plain text')).toBe(false);
expect(Parser.isHTML('Fix the login bug')).toBe(false);
expect(Parser.isHTML('')).toBe(false);
expect(Parser.isHTML('100 > 50 and 20 < 30')).toBe(false);
});

test('returns false for strings with angle brackets that are not HTML', () => {
expect(Parser.isHTML('a > b')).toBe(false);
expect(Parser.isHTML('x < y')).toBe(false);
expect(Parser.isHTML('<>')).toBe(false);
});
});
});
58 changes: 58 additions & 0 deletions tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,64 @@ describe('ReportNameUtils', () => {
);
expect(name).toBe('heading with link');
});

test('Returns plain text title without HTML conversion', () => {
const plainTaskTitle = 'Fix the login bug on Android';
const report: Report = {
...createRegularTaskReport(41, currentUserAccountID),
reportName: plainTaskTitle,
};

const name = computeReportName(
report,
emptyCollections.reports,
emptyCollections.policies,
undefined,
undefined,
participantsPersonalDetails,
emptyCollections.reportActions,
currentUserAccountID,
);
expect(name).toBe('Fix the login bug on Android');
});

test('Trims whitespace from plain text title', () => {
const report: Report = {
...createRegularTaskReport(42, currentUserAccountID),
reportName: ' Expense report review ',
};

const name = computeReportName(
report,
emptyCollections.reports,
emptyCollections.policies,
undefined,
undefined,
participantsPersonalDetails,
emptyCollections.reportActions,
currentUserAccountID,
);
expect(name).toBe('Expense report review');
});

test('Returns empty string for undefined reportName', () => {
const report: Report = {
...createRegularTaskReport(43, currentUserAccountID),
reportName: undefined,
};

const name = computeReportName(
report,
emptyCollections.reports,
emptyCollections.policies,
undefined,
undefined,
participantsPersonalDetails,
emptyCollections.reportActions,
currentUserAccountID,
);
expect(name).toBe('');
});
});

describe('computeReportName - Thread report action names', () => {
Expand Down
Loading