-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(portable-text-editor): test the value normalization of style prop
Test that when editing a block without a style prop, the result will have a default style prop.
- Loading branch information
1 parent
ad91bf2
commit 03b206c
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
packages/@sanity/portable-text-editor/src/utils/__tests__/valueNormalization.test.tsx
This file contains 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,76 @@ | ||
/** | ||
* @jest-environment ./test/setup/jsdom.jest.env.ts | ||
*/ | ||
// eslint-disable-next-line import/no-unassigned-import | ||
import '@testing-library/jest-dom/extend-expect' | ||
import {act} from 'react-dom/test-utils' | ||
import {render} from '@testing-library/react' | ||
|
||
import React from 'react' | ||
import {PortableTextEditor} from '../../editor/PortableTextEditor' | ||
import {PortableTextEditorTester, type} from '../../editor/__tests__/PortableTextEditorTester' | ||
|
||
describe('values: normalization', () => { | ||
it("accepts incoming value with blocks without a style or markDefs prop, but doesn't leave them without them when editing them", () => { | ||
const editorRef: React.RefObject<PortableTextEditor> = React.createRef() | ||
const initialValue = [ | ||
{ | ||
_key: '5fc57af23597', | ||
_type: 'myTestBlockType', | ||
children: [ | ||
{ | ||
_key: 'be1c67c6971a', | ||
_type: 'span', | ||
marks: [], | ||
text: 'Hello', | ||
}, | ||
], | ||
markDefs: [], | ||
}, | ||
] | ||
const onChange = jest.fn() | ||
act(() => { | ||
render( | ||
<PortableTextEditorTester | ||
onChange={onChange} | ||
ref={editorRef} | ||
type={type} | ||
value={initialValue} | ||
/> | ||
) | ||
}) | ||
if (!editorRef.current) { | ||
throw new Error('No editor') | ||
} | ||
act(() => { | ||
if (editorRef.current) { | ||
PortableTextEditor.focus(editorRef.current) | ||
PortableTextEditor.select(editorRef.current, { | ||
focus: {path: [{_key: '5fc57af23597'}, 'children', {_key: 'be1c67c6971a'}], offset: 0}, | ||
anchor: {path: [{_key: '5fc57af23597'}, 'children', {_key: 'be1c67c6971a'}], offset: 5}, | ||
}) | ||
} | ||
}) | ||
act(() => { | ||
if (editorRef.current) { | ||
PortableTextEditor.toggleMark(editorRef.current, 'strong') | ||
} | ||
}) | ||
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([ | ||
{ | ||
_key: '5fc57af23597', | ||
_type: 'myTestBlockType', | ||
children: [ | ||
{ | ||
_key: 'be1c67c6971a', | ||
_type: 'span', | ||
marks: ['strong'], | ||
text: 'Hello', | ||
}, | ||
], | ||
markDefs: [], | ||
style: 'normal', | ||
}, | ||
]) | ||
}) | ||
}) |
03b206c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
studio-workshop – ./dev/workshop
studio-workshop.sanity.build
studio-workshop-git-next.sanity.build
03b206c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
test-studio – ./
test-studio.sanity.build
test-studio-git-next.sanity.build
03b206c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
perf-studio – ./
perf-studio-git-next.sanity.build
perf-studio.sanity.build