lime-elements icon indicating copy to clipboard operation
lime-elements copied to clipboard

Create text editor test suite

Open john-traas opened this issue 10 months ago • 2 comments

Adds a test suite that can be used to setup test environments for the text-editor.

Summary by CodeRabbit

  • New Features
    • Improved table styling robustness in the text editor.
  • Tests
    • Added comprehensive test coverage for schema setup, editor state/view creation, content generation, command execution, event simulation, and table behavior to enhance reliability.
  • Documentation
    • Introduced detailed guides for text-editor testing utilities with usage examples and best practices.
  • Chores
    • Centralized exports for text-editor testing utilities to streamline imports.

john-traas avatar Mar 25 '25 10:03 john-traas

📝 Walkthrough

Walkthrough

This change set adds a comprehensive ProseMirror testing toolkit: schema builders, editor state/view builders, content generators, command testing utilities, and event simulators, along with corresponding Jest test suites and documentation. Additionally, a table plugin helper (createStyleAttribute) is now exported to support testing.

Changes

Cohort / File(s) Summary
Table Plugin
src/components/text-editor/prosemirror-adapter/plugins/table-plugin.ts, .../plugins/table-plugin.spec.ts
Exported createStyleAttribute; added tests for table plugins, node specs, and style attribute behavior.
Command Testing Utilities
src/components/text-editor/test-setup/command-tester.ts, .../command-tester.spec.ts
Introduced CommandResult interface and helpers: getCommandResult, testCommand, testCommandWithView, createCommandTester; added tests covering success/failure cases and view-driven commands.
Content Generators
src/components/text-editor/test-setup/content-generator.ts, .../content-generator.spec.ts
Added helpers to create EditorState from text, HTML, formatted text, bullet lists, headings, blockquotes, and code blocks; tests validate structure and schema interactions.
Editor State Builder
src/components/text-editor/test-setup/editor-state-builder.ts, .../editor-state-builder.spec.ts
Added createEditorState, createEditorStateWithSelection, setTextSelection; tests verify empty/content/custom schema scenarios and selections.
Editor View Builder
src/components/text-editor/test-setup/editor-view-builder.ts, .../editor-view-builder.spec.ts
Added createEditorView, createDispatchSpy, cleanupEditorView, mockProseMirrorDOMEnvironment; tests cover creation, dispatch behavior, cleanup, and DOM mocking.
Event Simulator
src/components/text-editor/test-setup/event-simulator.ts, .../event-simulator.spec.ts
Added MockDataTransfer and simulators for keypress, paste, click, and drag-and-drop; tests validate event dispatching and payloads.
Schema Builder
src/components/text-editor/test-setup/schema-builder.ts, .../schema-builder.spec.ts
Added createTestSchema and createCustomTestSchema with configurable nodes/marks; tests verify defaults and customization.
Test Utils Barrel
src/components/text-editor/test-setup/editor-test-utils.ts
Re-exported all test utilities from schema, state/view builders, content generators, command tester, and event simulator.
Documentation
src/components/text-editor/test-setup/text-editor-test-suite-guide.md, .../text-editor-test-utils.md
Added guides documenting the testing utilities, usage examples, and best practices.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Tester
  participant State as EditorState
  participant View as EditorView
  participant Cmd as Command
  participant PM as ProseMirror

  rect rgba(224,240,255,0.5)
  note right of Tester: testCommand / getCommandResult
  Tester->>PM: Create State (optional content/plugins)
  PM-->>State: EditorState
  Tester->>Cmd: invoke(state, dispatch[, view])
  Cmd-->>Tester: boolean result
  alt result is true
    Cmd->>Tester: dispatch(tr)
    Tester->>State: state.apply(tr)
    State-->>Tester: newState
    Tester->>Tester: assertions (docContentAfter / size / includes)
  else result is false
    Tester-->>Tester: assertions on failure
  end
  end

  rect rgba(232,255,232,0.5)
  note over Tester,View: testCommandWithView
  Tester->>PM: create EditorView(state)
  PM-->>View: EditorView
  Tester->>Cmd: invoke(state, dispatch, view)
  Cmd->>Tester: dispatch(tr)
  Tester->>View: view.updateState(state.apply(tr))
  Tester-->>Tester: assertions on view.state
  end
sequenceDiagram
  autonumber
  actor Tester
  participant ES as EventSimulator
  participant View as EditorView
  participant DOM as view.dom

  rect rgba(255,245,225,0.6)
  note over Tester,View: simulateDragAndDrop
  Tester->>ES: simulateDragAndDrop(view, start, end, data?)
  ES->>DOM: mousedown
  ES->>DOM: dragstart (dataTransfer?)
  ES->>DOM: dragover
  ES->>DOM: drop
  ES->>DOM: mouseup
  DOM-->>Tester: dispatched events (handled flags)
  end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jgroth
  • omaralweli

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Create text editor test suite" accurately and concisely summarizes the main change in the diff — the addition of a comprehensive test suite and supporting test utilities for the text editor. It is short, specific to the primary intent, and clear for teammates scanning PR history. The wording avoids noise and matches the files and objectives described in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch create-text-editor-test-suite

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Mar 25 '25 10:03 coderabbitai[bot]

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3508/

github-actions[bot] avatar Mar 25 '25 10:03 github-actions[bot]