-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unnecessary update of ra-input-rich-text on edit
- Loading branch information
Roy Choo
committed
Apr 11, 2019
1 parent
198fdf3
commit 661b8a1
Showing
5 changed files
with
67 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import debounce from 'lodash/debounce'; | ||
import {render, fireEvent, waitForElement, cleanup, getByTestId} from 'react-testing-library' | ||
|
||
import { RichTextInput } from './index'; | ||
|
||
let container; | ||
|
||
jest.mock('lodash/debounce'); | ||
describe('RichTextInput', () => { | ||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
document.getSelection = () => { | ||
return { | ||
removeAllRanges: () => {}, | ||
getRangeAt: function() {}, | ||
}; | ||
}; | ||
jest.mock('lodash.debounce', (fn) => fn); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(container); | ||
container = null; | ||
}); | ||
|
||
it('should call text-change event only once when editing', async () => { | ||
const mockFn = jest.fn(); | ||
debounce.mockImplementation(fn => fn); | ||
const { getByTestId, rerender } = render( | ||
<RichTextInput | ||
input={{ | ||
value: '<p>test</p>', | ||
onChange: mockFn | ||
}} | ||
meta={{error: null}} />); | ||
const quillNode = await waitForElement(() => { | ||
return getByTestId('quill') | ||
}); | ||
quillNode.__quill.setText('test1'); | ||
rerender( | ||
<RichTextInput | ||
input={{ | ||
value: '<p>test1</p>', | ||
onChange: mockFn | ||
}} | ||
meta={{error: null}} />) | ||
|
||
expect(mockFn).toHaveBeenCalledTimes(1); | ||
}); | ||
}) |
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