-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(range): Fix Range.getClientRects on IE/Edge (#577)
* fix(range): Fix Range.getClientRects on IE/Edge * feat(region): Move test to actions-test
- Loading branch information
Mingze
authored
Sep 4, 2020
1 parent
53b00bd
commit 8de3cf0
Showing
3 changed files
with
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import state from '../__mocks__/highlightState'; | ||
import { mockContainerRect, mockDOMRect, mockRange } from '../__mocks__/data'; | ||
import { setSelectionAction } from '../actions'; | ||
|
||
describe('store/highlight/actions', () => { | ||
describe('setSelectionAction', () => { | ||
const arg = { | ||
containerRect: mockContainerRect, | ||
location: 1, | ||
range: mockRange, | ||
}; | ||
|
||
test('should prepare correct argument', () => { | ||
expect(setSelectionAction(arg)).toEqual({ | ||
payload: state.selection, | ||
type: 'SET_SELECTION', | ||
}); | ||
}); | ||
|
||
test('should prepare correct argument in IE/Edge', () => { | ||
jest.spyOn(document, 'createNodeIterator').mockReturnValueOnce(({ | ||
nextNode: jest.fn().mockReturnValueOnce(mockRange.startContainer), | ||
} as unknown) as NodeIterator); | ||
jest.spyOn(document, 'createRange').mockReturnValueOnce({ | ||
...new Range(), | ||
getBoundingClientRect: jest.fn().mockReturnValueOnce(mockDOMRect), | ||
selectNodeContents: jest.fn(), | ||
setEnd: jest.fn(), | ||
setStart: jest.fn(), | ||
}); | ||
const range = { | ||
...mockRange, | ||
getClientRects: () => ({ length: 0 } as DOMRectList), | ||
}; | ||
|
||
const newArg = { | ||
...arg, | ||
range, | ||
}; | ||
|
||
expect(setSelectionAction(newArg)).toEqual({ | ||
payload: state.selection, | ||
type: 'SET_SELECTION', | ||
}); | ||
}); | ||
}); | ||
}); |
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