Skip to content

Commit

Permalink
Add test for caretRangeFromPoint and caretPositionFromPoint usage (cl…
Browse files Browse the repository at this point in the history
…oses #1385)
  • Loading branch information
AlexanderMoskovkin committed Apr 19, 2017
1 parent 49c695e commit 355f0cb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/functional/fixtures/regression/gh-1385/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>gh-1385</title>
</head>
<body>

<div id='div' contenteditable="true">content</div>

<script>
document.getElementById('div').addEventListener('mousedown', function (e) {
var x = e.clientX;
var y = e.clientY;

window.elementFromPointId = document.elementFromPoint(x, y).id;

if (document.caretPositionFromPoint)
window.caretPositionFromPointData = document.caretPositionFromPoint(x, y).offsetNode.data;

if (document.caretRangeFromPoint)
window.caretRangeFromPointData = document.caretRangeFromPoint(x, y).startContainer.data;
});
</script>

</body>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-1385/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-1385)', function () {
it('Should be able to get elements under cursor via "...fromPoint" functions', function () {
return runTests('testcafe-fixtures/index-test.js', 'Check "...fromPoint" functions');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
fixture `gh-1385`
.page `http://localhost:3000/fixtures/regression/gh-1385/pages/index.html`;

test('Check "...fromPoint" functions', async t => {
await t.click('#div');

const {
caretPositionFromPointSupported,
caretRangeFromPointSupported,
elementFromPointId,
caretPositionFromPointData,
caretRangeFromPointData
} = await t.eval(() => {
return {
caretPositionFromPointSupported: !!document.caretPositionFromPoint,
caretRangeFromPointSupported: !!document.caretRangeFromPoint,
elementFromPointId: window.elementFromPointId,
caretPositionFromPointData: window.caretPositionFromPointData,
caretRangeFromPointData: window.caretRangeFromPointData
};
});

await t.expect(elementFromPointId).eql('div');

if (caretPositionFromPointSupported)
await t.expect(caretPositionFromPointData).eql('content');

if (caretRangeFromPointSupported)
await t.expect(caretRangeFromPointData).eql('content');
});

0 comments on commit 355f0cb

Please sign in to comment.