Skip to content

feat(jest): support onLinkPress, onLinkLongPress, and onTaskListItemPress in mock - #712

Merged
hryhoriiK97 merged 2 commits into
software-mansion:mainfrom
hryhoriiK97:feat/jest-mock-interactive-elements
Aug 26, 2026
Merged

feat(jest): support onLinkPress, onLinkLongPress, and onTaskListItemPress in mock#712
hryhoriiK97 merged 2 commits into
software-mansion:mainfrom
hryhoriiK97:feat/jest-mock-interactive-elements

Conversation

@hryhoriiK97

Copy link
Copy Markdown
Collaborator

Summary

The Jest mock for EnrichedMarkdownText currently discards all interaction callbacks (onLinkPress, onLinkLongPress, onTaskListItemPress), rendering markdown as a flat string. This forces consumers to write per-file mock overrides just to test link press handlers or task list interactions.

This PR adds a composable transform pipeline to the mock that:

  • Links — Parses [text](url) into pressable <Text accessibilityRole="link"> elements that fire onLinkPress/onLinkLongPress with { url }
  • Task lists — Parses GFM task items (- [x] / - [ ]) into pressable checkbox elements that fire onTaskListItemPress with { index, checked, text }
  • Inline formatting — Strips **, *, __, _ markers from link display text so queries match visible content
  • Backward-compatible — Transforms only activate when their callbacks are provided; without them, behavior is identical to before

Architecture

A shared splitByPattern(segment, regex, renderMatch) utility handles the iteration boilerplate. Each feature is a small factory function (createLinkTransform, createTaskListTransform) that returns a TransformFn. Adding future features (e.g. bold rendering, mentions) requires only appending a new factory to the buildChildren array.

Test plan

  • Added 8 new test cases to __tests__/jest-mock.test.tsx covering:
    • Link rendering with accessibilityRole="link"
    • onLinkPress callback with { url }
    • onLinkLongPress callback with { url }
    • Inline formatting stripping from link text
    • No-op when callbacks are absent (backward compat)
    • Task list checkbox rendering with accessibilityState
    • onTaskListItemPress with toggled state
  • All 13 tests pass (yarn test)
  • TypeScript strict mode passes (yarn typecheck)

Made with Cursor

…ress in mock

The Jest mock for EnrichedMarkdownText previously discarded all interaction
callbacks, rendering markdown as a flat string. This made it impossible to
test link press handlers or task list interactions without per-file mock
overrides.

This change adds a composable transform pipeline that:
- Parses [text](url) patterns into pressable <Text accessibilityRole="link">
  elements that fire onLinkPress/onLinkLongPress with { url }
- Parses GFM task list items (- [x] / - [ ]) into pressable checkbox elements
  that fire onTaskListItemPress with { index, checked, text }
- Strips inline formatting markers from link display text
- Only activates transforms when their callbacks are provided (zero overhead
  when not used, backward-compatible)

The architecture uses a shared splitByPattern utility so adding future
transforms (e.g. bold rendering, mentions) requires only a small factory
function.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the Jest mock for EnrichedMarkdownText so tests can exercise interaction callbacks (link press/long-press and task list item toggles) instead of treating markdown as a flat string.

Changes:

  • Added a small transform pipeline in the Jest mock to turn link/task-list syntax into pressable React Native <Text> children.
  • Added link and task-list interaction test cases for the mock behavior.
  • Added basic inline-formatting stripping for link display text in the mock.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/react-native-enriched-markdown/src/jest/index.tsx Adds transform utilities and renders links/task items as pressable elements in the Jest mock.
packages/react-native-enriched-markdown/tests/jest-mock.test.tsx Adds test coverage for link and task-list interactions in the mock.
Suppressed comments (2)

packages/react-native-enriched-markdown/src/jest/index.tsx:335

  • Task list interaction is documented as GitHub-flavor-only (src/types/MarkdownTextProps.ts:161-162). The Jest mock currently enables task-list parsing whenever onTaskListItemPress is provided, regardless of flavor (the mock destructures flavor but doesn’t use it). This can make Jest tests pass while the real component (default flavor='commonmark') would never emit task events. Consider plumbing flavor into buildChildren and only enabling the task-list transform when flavor === 'github'.
      {buildChildren(markdown, {
        onLinkPress,
        onLinkLongPress,
        onTaskListItemPress,
      })}

packages/react-native-enriched-markdown/tests/jest-mock.test.tsx:258

  • This task-list test also relies on task lists without setting flavor="github", even though the API contract specifies task-list events only in GitHub flavor. Adding flavor="github" keeps the test representative of real usage.
      <EnrichedMarkdownText
        testID="display"
        markdown={'- [ ] First task\n- [x] Second task'}
        onTaskListItemPress={onTaskListItemPress}
      />

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/react-native-enriched-markdown/src/jest/index.tsx
Comment thread packages/react-native-enriched-markdown/src/jest/index.tsx
… tests

- Reorder transforms so task-list runs first, preventing link parsing
  from splitting task lines before TASK_ITEM_RE can match
- Add flavor="github" to task list tests to align with public contract

Co-authored-by: Cursor <cursoragent@cursor.com>
@hryhoriiK97
hryhoriiK97 requested a review from eszlamczyk August 26, 2026 14:03
@hryhoriiK97
hryhoriiK97 merged commit e24c661 into software-mansion:main Aug 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants