208 add tests for a richeditor#308
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds DOM-level testing infrastructure for the ChangesRichEditor Testing Setup and Coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsx (1)
44-46: 💤 Low valueConsider simplifying the initial render.
React Testing Library's
renderfunction already wraps updates inactinternally, so the explicitawait act(async () => render(...))wrapper is redundant. Theasynccallback wrapper serves no purpose here sincerenderis synchronous.♻️ Simplified version
- // Use `act` to wait for all editor updates to complete before making assertions; - // otherwise, some asynchronous updates may not have been applied to the DOM yet. - const result = await act(async () => render(renderEditor(props))); + const result = render(renderEditor(props));Note: The custom
rerender,insert, andformatmethods correctly useactsince they trigger state updates outside of RTL's automatic wrapping.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsx` around lines 44 - 46, The initial render in renderRichEditor.tsx wraps render(renderEditor(props)) in an unnecessary await act(...) call; replace the explicit await act(async () => render(renderEditor(props))) with a direct call to render(renderEditor(props)) and assign its return to result (since RTL's render already handles act), while leaving the custom rerender, insert, and format helpers that explicitly use act unchanged; locate the call around renderEditor and act imports and update accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/app/scripts/vitest.setup.ts`:
- Around line 17-22: Element.prototype.getClientRects currently sets
Symbol.iterator to an empty function which returns undefined and breaks
iteration; update the mock returned by Element.prototype.getClientRects (the
DOMRectList stub) so its [Symbol.iterator] property is a function that returns
an iterator object with a next() method (e.g., returning { done: true }
immediately or iterating over an internal array), ensuring the returned object
conforms to the iterator protocol and matches DOMRectList behavior for for...of
and spread usage.
---
Nitpick comments:
In `@packages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsx`:
- Around line 44-46: The initial render in renderRichEditor.tsx wraps
render(renderEditor(props)) in an unnecessary await act(...) call; replace the
explicit await act(async () => render(renderEditor(props))) with a direct call
to render(renderEditor(props)) and assign its return to result (since RTL's
render already handles act), while leaving the custom rerender, insert, and
format helpers that explicitly use act unchanged; locate the call around
renderEditor and act imports and update accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b7501d73-29c8-475e-96a6-79c0b93d9557
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonpackages/app/src/core/storage/interop/export/__snapshots__/NotesExporter.dom.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (8)
package.jsonpackages/app/scripts/vitest.setup.tspackages/app/src/core/storage/interop/export/NotesExporter.dom.test.tspackages/app/src/features/NoteEditor/tests/richEditor.dom.test.tspackages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsxpackages/app/src/features/NoteEditor/tests/utils/utils.tsxpackages/app/vitest.config.mtswords.txt
💤 Files with no reviewable changes (1)
- packages/app/src/core/storage/interop/export/NotesExporter.dom.test.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsx`:
- Around line 51-60: The test helper functions insert and format are declared
async but do not await anything, misleading callers who use await
editor.insert(...) / await editor.format(...); update the helper implementations
in renderRichEditor.tsx by removing the async keyword from the insert and format
functions (the ones calling onInserting(payload) and onFormatting(format)) so
they are plain synchronous helpers, ensuring tests do not falsely rely on
awaiting them for Lexical/React DOM flushes.
In `@packages/app/src/features/NoteEditor/tests/utils/utils.tsx`:
- Line 34: The error message in utils.tsx is using the wrong variable: when
endNode is null the thrown Error interpolates endNode (null) instead of the
search string endText; update the throw in the code that checks if (!endNode) to
reference endText (or the correct search variable) so the Error reads something
like "Text node not found for \"<searched text>\"" to show what was being looked
for (locate the check that throws when endNode is falsy and replace the
interpolated variable).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b06610c8-eaf5-45e1-a4c2-29930f203051
📒 Files selected for processing (4)
packages/app/scripts/vitest.setup.tspackages/app/src/features/NoteEditor/tests/richEditor.dom.test.tspackages/app/src/features/NoteEditor/tests/utils/renderRichEditor.tsxpackages/app/src/features/NoteEditor/tests/utils/utils.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/app/scripts/vitest.setup.ts
- packages/app/src/features/NoteEditor/tests/richEditor.dom.test.ts
e145c11 to
b31cb56
Compare
fa800ff to
b3d1a58
Compare
Closes #208
I added Vitest projects to separate tests by environment. Projects allow us to use different setup files and test settings for different groups of tests. To distinguish tests that require a DOM environment, I suggest using the
.dom.test.tssuffix.Changes:
Update
NotesExporter.test.tsto make the tests deterministic. The snapshots changed in this pull request because it have to non-deterministic order in result, so i added sorting before creating the snapshots to prevent this in the future.Summary by CodeRabbit
Tests
Chores