Skip to content

Commit 02b442a

Browse files
committed
Add htmlToMarkdown tests pinning the Split details rendering contract
1 parent 605f86b commit 02b442a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/unit/ParserTest.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,28 @@ describe('Parser', () => {
2424
expect(Parser.isHTML('<>')).toBe(false);
2525
});
2626
});
27+
28+
describe('htmlToMarkdown', () => {
29+
// These cases pin the contract relied on by DescriptionField.tsx, where the description of a saved
30+
// transaction is stored as HTML (because `getParsedComment()` runs ExpensiMark at save time) and must
31+
// be normalized back to markdown before being handed to the `shouldParseTitle` MenuItem and the
32+
// `type="markdown"` TextInput. Without this normalization, the Split details page renders raw `<a>`
33+
// tags as visible text — see https://github.com/Expensify/App/issues/87519.
34+
test('converts an autolinked URL anchor back to a markdown link', () => {
35+
expect(Parser.htmlToMarkdown('<a href="https://google.com" target="_blank" rel="noreferrer noopener">google.com</a>')).toBe('[google.com](https://google.com)');
36+
});
37+
38+
test('converts ExpensiMark-emitted bold tags back to markdown asterisks', () => {
39+
expect(Parser.htmlToMarkdown('<strong>hello</strong> world')).toBe('*hello* world');
40+
});
41+
42+
test('is a no-op for plain text descriptions used by draft transactions', () => {
43+
expect(Parser.htmlToMarkdown('lunch')).toBe('lunch');
44+
expect(Parser.htmlToMarkdown('google.com')).toBe('google.com');
45+
});
46+
47+
test('returns an empty string for an empty input', () => {
48+
expect(Parser.htmlToMarkdown('')).toBe('');
49+
});
50+
});
2751
});

0 commit comments

Comments
 (0)