-
Notifications
You must be signed in to change notification settings - Fork 430
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): add test
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/@sanity/portable-text-editor/src/utils/__tests__/pteWarningsSelfSolving.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,58 @@ | ||
import {describe, expect, it, jest} from '@jest/globals' | ||
import {render, waitFor} from '@testing-library/react' | ||
import {createRef, type RefObject} from 'react' | ||
|
||
import {PortableTextEditorTester, schemaType} from '../../editor/__tests__/PortableTextEditorTester' | ||
import {PortableTextEditor} from '../../editor/PortableTextEditor' | ||
|
||
describe('when PTE would display warnings, instead it self solves', () => { | ||
it('when child at index is missing required _key in block with _key', async () => { | ||
const editorRef: RefObject<PortableTextEditor> = createRef() | ||
const initialValue = [ | ||
{ | ||
_key: '1', | ||
_type: 'myTestBlockType', | ||
children: [ | ||
{ | ||
_type: 'span', | ||
marks: [], | ||
text: 'Hello with a new key', | ||
}, | ||
], | ||
markDefs: [], | ||
style: 'normal', | ||
}, | ||
] | ||
|
||
const onChange = jest.fn() | ||
render( | ||
<PortableTextEditorTester | ||
onChange={onChange} | ||
ref={editorRef} | ||
schemaType={schemaType} | ||
value={initialValue} | ||
/>, | ||
) | ||
await waitFor(() => { | ||
if (editorRef.current) { | ||
PortableTextEditor.focus(editorRef.current) | ||
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([ | ||
{ | ||
_key: '1', | ||
_type: 'myTestBlockType', | ||
children: [ | ||
{ | ||
_key: '3', | ||
_type: 'span', | ||
text: 'Hello with a new key', | ||
marks: [], | ||
}, | ||
], | ||
markDefs: [], | ||
style: 'normal', | ||
}, | ||
]) | ||
} | ||
}) | ||
}) | ||
}) |