-
Notifications
You must be signed in to change notification settings - Fork 1
208 add tests for a richeditor #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vitonsky
merged 65 commits into
DeepinkApp:master
from
katsyuta:208-add-tests-for-a-richeditor
Jun 30, 2026
Merged
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
c3c0a52
feat: add test fro rich editor
katsyuta 1125545
refactor: use dom api for text selected
katsyuta a2779d1
test: add tests for image
katsyuta 3394b17
test: update setup
katsyuta 30081a9
refactor: remove editor, it do not necessary
katsyuta 2781d07
test: remove snapshot test
katsyuta ec3230c
chore: rename
katsyuta 0d13492
chore: rename
katsyuta 19518e3
chore: update snapshot
katsyuta 8f01bbd
test: add cases
katsyuta 88638ec
refactor: use async api only when it necessary
katsyuta 545123a
chore: improve helper func
katsyuta 6b25738
chore: remove unnecessary package
katsyuta c05f19b
chore: remove
katsyuta 77ef6ea
refactor: improve helper api
katsyuta 47b9982
chore: docs
katsyuta e874e13
chore: fix typo
katsyuta b18507a
fix: wait before check image
katsyuta 412d8bf
fix: improve checks
katsyuta 8c74246
chore: style
katsyuta aa0dfed
fix: use iterator in mock, remove act
katsyuta 5d06adc
chore: improve the searching text node in utils
katsyuta 2c8902b
chore: fix typo, remove only
katsyuta 110acb6
fix: ts error
katsyuta 5d4cc0c
chore: remove comment
katsyuta 0b5d66d
chore: rename
katsyuta b3d1a58
fix: add chakra provider
katsyuta 825ae4e
chore: rename folder
katsyuta f1a6de8
refactor: utils must receive the node
katsyuta c864910
refactor: set position for cursor
katsyuta 0e85f5b
test: add test for few editors
katsyuta d45539b
chore: rename, fix error
katsyuta 05ddeb6
test: improve test, add lib for trigger event
katsyuta efbff64
refactor: improve basic md test
katsyuta 6ee1625
refactor: vitest settings, rename
katsyuta 3b8e1c9
chore: typo, remove unncessary file
katsyuta be2f358
refactor: mock only necessary deps in provider
katsyuta 9a9e43b
chore: rename
katsyuta 5b1c11d
test: update
katsyuta f4422d1
test: add
katsyuta a837265
test: add
katsyuta b2772d0
chore: rename file with md example
katsyuta f65e50b
chore: rename
katsyuta 69d627b
test: add. rename
katsyuta b3eb322
Merge branch 'master' into 208-add-tests-for-a-richeditor
katsyuta 1e072ee
fix: import error
katsyuta 6550eb2
Merge branch 'master' into 208-add-tests-for-a-richeditor
katsyuta 8d3f295
chore: rename, update comment
katsyuta df2f60e
chore: typo
katsyuta 897c478
chore: rename
katsyuta a3518d2
chore: update expectations
katsyuta e46dec6
chore: rename
katsyuta d261fab
chore: fix
katsyuta 0b8a1b3
chore: improve checks
katsyuta ffaa9f4
chore: define node mock not global
katsyuta a30d29e
Merge branch 'master' into 208-add-tests-for-a-richeditor
katsyuta 57bbc78
chore: move deps
katsyuta 1118932
test: update checks
katsyuta f72de2b
test: update checks
katsyuta bf6c002
chore: remove unnecessary dep
katsyuta 483ef76
refactor: sort before snapshot
katsyuta 641639b
chore: rename
katsyuta e577ae0
Merge branch 'master' into 208-add-tests-for-a-richeditor
katsyuta a80f07c
chore: update snapshot
katsyuta f0095c5
chore: update checks
katsyuta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/app/src/features/NoteEditor/__tests__/behavior.dom.test.ts
|
vitonsky marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { screen, within } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import { renderRichEditor } from './utils/renderRichEditor'; | ||
| import { selectContent } from './utils/utils'; | ||
|
|
||
| test('Editor updates when value changes', async () => { | ||
| const editor = await renderRichEditor({ value: `# Big text` }); | ||
|
|
||
| expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Big text'); | ||
|
|
||
| // Run component rerender with new value | ||
| await editor.rerender({ value: `### Not so big text` }); | ||
|
|
||
| expect(screen.getByRole('heading', { level: 3 })).toHaveTextContent( | ||
| 'Not so big text', | ||
| ); | ||
|
|
||
| // The old header was removed | ||
| expect(screen.queryByRole('heading', { level: 1 })).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Editor is not editable in readonly mode', async () => { | ||
| const user = userEvent.setup(); | ||
| await renderRichEditor({ | ||
| value: '# Hello', | ||
| isReadOnly: true, | ||
| }); | ||
|
|
||
| expect(screen.getByRole('textbox')).toHaveAttribute('contenteditable', 'false'); | ||
|
|
||
| // Cannot enter text | ||
| await user.click(screen.getByRole('heading')); | ||
| await user.keyboard('Some text'); | ||
|
|
||
| expect(screen.getByRole('textbox')).toHaveTextContent('Hello'); | ||
| expect(screen.getByRole('textbox')).not.toHaveTextContent('Some text'); | ||
|
katsyuta marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test('Formatting text in one editor does not affect the other editor', async () => { | ||
| const editorA = await renderRichEditor({ value: 'Big text' }); | ||
| const editorB = await renderRichEditor({ value: 'Small text' }); | ||
|
|
||
| const textBoxes = screen.getAllByRole('textbox'); | ||
| expect(textBoxes).toHaveLength(2); | ||
|
|
||
| // initial state | ||
| expect(within(textBoxes[0]).queryByRole('paragraph')).toHaveTextContent('Big text'); | ||
| expect(within(textBoxes[1]).queryByRole('paragraph')).toHaveTextContent('Small text'); | ||
|
|
||
| // apply italic in editorA | ||
| selectContent(textBoxes[0], 'Big text'); | ||
| await editorA.format('italic'); | ||
|
|
||
| expect(within(textBoxes[0]).getByRole('emphasis')).toHaveTextContent('Big text'); | ||
| expect(within(textBoxes[1]).queryByRole('emphasis')).not.toBeInTheDocument(); | ||
|
|
||
| // apply strikethrough in editorB | ||
| selectContent(textBoxes[1], 'Small text'); | ||
| await editorB.format('strikethrough'); | ||
|
|
||
| expect(within(textBoxes[1]).getByRole('deletion')).toHaveTextContent('Small text'); | ||
| expect(within(textBoxes[1]).queryByRole('emphasis')).not.toBeInTheDocument(); | ||
|
|
||
| expect(within(textBoxes[0]).getByRole('emphasis')).toHaveTextContent('Big text'); | ||
| expect(within(textBoxes[0]).queryByRole('deletion')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('ReadOnly editor is not editable while the other editor remains editable', async () => { | ||
| const user = userEvent.setup(); | ||
| await renderRichEditor({ value: 'Editable text' }); | ||
| await renderRichEditor({ value: 'ReadOnly text', isReadOnly: true }); | ||
|
|
||
| const textBoxes = screen.getAllByRole('textbox'); | ||
| expect(textBoxes).toHaveLength(2); | ||
|
|
||
| expect(textBoxes[0]).toHaveAttribute('contenteditable', 'true'); | ||
| expect(textBoxes[1]).toHaveAttribute('contenteditable', 'false'); | ||
|
|
||
| // editorA is editable — editing works | ||
| await user.click(within(textBoxes[0]).getByText('Editable text')); | ||
| await user.keyboard('New text '); | ||
|
|
||
| expect(textBoxes[0]).toHaveTextContent('New text Editable text'); | ||
|
|
||
| // editorB is readOnly — editing must be ignored | ||
| await user.click(within(textBoxes[1]).getByText('ReadOnly text')); | ||
| await user.keyboard('Some text'); | ||
|
|
||
| expect(textBoxes[1]).toHaveTextContent('ReadOnly text'); | ||
| expect(textBoxes[1]).not.toHaveTextContent('Some text'); | ||
| expect(textBoxes[1]).toHaveAttribute('contenteditable', 'false'); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.