Skip to content

Commit

Permalink
Tests for getting / restoring selections across iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Oct 13, 2016
1 parent 4ea5fb3 commit 489866b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/renderers/dom/client/__tests__/ReactInputSelection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,39 @@ describe('ReactInputSelection', () => {

document.body.removeChild(input);
});

it('gets and restores selection for inputs in an iframe that get remounted', () => {
var iframe = document.createElement('iframe');
iframe.setAttribute('tabIndex', 0);
document.body.appendChild(iframe);
iframe.focus();
var iframeDoc = iframe.contentDocument;
var input = document.createElement('input');
input.value = textValue;
iframeDoc.body.appendChild(input);
// Focus iframe first to get around jsdom limitations
iframe.focus();
input.focus();
input.selectionStart = 1;
input.selectionEnd = 10;
var selectionInfo = ReactInputSelection.getSelectionInformation();
expect(selectionInfo.focusedElement).toBe(input);
expect(selectionInfo.activeElements[0].selectionRange).toEqual({start: 1, end: 10});
expect(document.activeElement).toBe(iframe);
expect(iframeDoc.activeElement).toBe(input);

input.setSelectionRange(0, 0);
iframeDoc.body.removeChild(input);
expect(iframeDoc.activeElement).not.toBe(input);
expect(input.selectionStart).not.toBe(1);
expect(input.selectionEnd).not.toBe(10);
iframeDoc.body.appendChild(input);
ReactInputSelection.restoreSelection(selectionInfo);
expect(iframeDoc.activeElement).toBe(input);
expect(input.selectionStart).toBe(1);
expect(input.selectionEnd).toBe(10);

document.body.removeChild(iframe);
});
});
});

0 comments on commit 489866b

Please sign in to comment.