forked from ianstormtaylor/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stale decorations (ianstormtaylor#4876)
* test changes * fix decoration not updating * Add changeset * Fix lint issues * Tests with earlier version of Node.js * Bump node version on CI The base typescript config uses ESNext as target, so presumably the latest node should be used. Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
- Loading branch information
1 parent
dc268bc
commit 08e5364
Showing
11 changed files
with
357 additions
and
87 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'slate-react': patch | ||
--- | ||
|
||
Fix decorations not getting applied for children unless parent changes |
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
const config = { | ||
testMatch: ['<rootDir>/packages/slate-react/test/**/*.{js,ts,tsx,jsx}'], | ||
preset: 'ts-jest', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/packages/slate-react/tsconfig.json', | ||
}, | ||
}, | ||
testEnvironment: 'jsdom', | ||
} | ||
|
||
module.exports = config |
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,101 @@ | ||
import React from 'react' | ||
import { createEditor, NodeEntry, Range } from 'slate' | ||
import { create, act, ReactTestRenderer } from 'react-test-renderer' | ||
import { | ||
Slate, | ||
withReact, | ||
DefaultEditable, | ||
RenderElementProps, | ||
DefaultElement, | ||
} from '../src' | ||
|
||
describe('slate-react', () => { | ||
describe('Editable', () => { | ||
describe('decorate', () => { | ||
const createNodeMock = () => ({ | ||
ownerDocument: global.document, | ||
getRootNode: () => global.document, | ||
}) | ||
|
||
it('should be called on all nodes in document', () => { | ||
const editor = withReact(createEditor()) | ||
const value = [{ type: 'block', children: [{ text: '' }] }] | ||
|
||
const decorate = jest.fn<Range[], [NodeEntry]>(entry => []) | ||
|
||
let el: ReactTestRenderer | ||
|
||
act(() => { | ||
el = create( | ||
<Slate editor={editor} value={value} onChange={() => {}}> | ||
<DefaultEditable decorate={decorate} /> | ||
</Slate>, | ||
{ createNodeMock } | ||
) | ||
}) | ||
|
||
expect(decorate).toHaveBeenCalledTimes(3) | ||
}) | ||
|
||
it('should rerender the part of the tree that received an updated decoration', () => { | ||
const editor = withReact(createEditor()) | ||
|
||
const value = [ | ||
{ type: 'block', children: [{ text: '' }] }, | ||
{ type: 'block', children: [{ text: '' }] }, | ||
] | ||
|
||
// initial render does not return | ||
const decorate = jest.fn<Range[], [NodeEntry]>(() => []) | ||
|
||
const renderElement = jest.fn<JSX.Element, [RenderElementProps]>( | ||
DefaultElement | ||
) | ||
|
||
const onChange = jest.fn<void, []>() | ||
|
||
let el: ReactTestRenderer | ||
|
||
act(() => { | ||
el = create( | ||
<Slate editor={editor} value={value} onChange={onChange}> | ||
<DefaultEditable | ||
decorate={decorate} | ||
renderElement={renderElement} | ||
/> | ||
</Slate>, | ||
{ createNodeMock } | ||
) | ||
}) | ||
|
||
expect(renderElement).toHaveBeenCalledTimes(2) | ||
|
||
decorate.mockImplementation(([node]) => { | ||
if (node !== value[0].children[0]) { | ||
return [] | ||
} | ||
|
||
return [ | ||
{ | ||
anchor: { path: [0, 0], offset: 0 }, | ||
focus: { path: [0, 0], offset: 0 }, | ||
}, | ||
] | ||
}) | ||
|
||
act(() => { | ||
el.update( | ||
<Slate editor={editor} value={value} onChange={onChange}> | ||
<DefaultEditable | ||
decorate={decorate} | ||
renderElement={renderElement} | ||
/> | ||
</Slate> | ||
) | ||
}) | ||
|
||
expect(renderElement).toHaveBeenCalledTimes(3) | ||
}) | ||
}) | ||
}) | ||
}) |
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,4 @@ | ||
{ | ||
"extends": "../../../config/typescript/tsconfig.json", | ||
"references": [{ "path": "../" }] | ||
} |
Oops, something went wrong.