Skip to content

Commit

Permalink
test(portable-text-editor): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed May 6, 2024
1 parent d6c2166 commit 8acfbe1
Showing 1 changed file with 58 additions and 0 deletions.
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',
},
])
}
})
})
})

0 comments on commit 8acfbe1

Please sign in to comment.