From cc0f2f8f4fd1db5fe6f89641b467900467a6a7e9 Mon Sep 17 00:00:00 2001 From: Adil Rakhaliyev <67043367+Bayheck@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:26:16 +0500 Subject: [PATCH] fix: typetext issue test (#8342) ## Purpose _Describe the problem you want to address or the feature you want to implement._ ## Approach _Describe how your changes address the issue or implement the desired functionality in as much detail as possible._ ## References closes https://github.com/DevExpress/testcafe/issues/8321 ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail --------- Co-authored-by: Bayheck --- src/client/core/utils/content-editable.js | 8 +++---- .../regression/gh-8321/pages/index.html | 23 +++++++++++++++++++ .../fixtures/regression/gh-8321/test.js | 5 ++++ .../gh-8321/testcafe-fixtures/index.js | 11 +++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 test/functional/fixtures/regression/gh-8321/pages/index.html create mode 100644 test/functional/fixtures/regression/gh-8321/test.js create mode 100644 test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js diff --git a/src/client/core/utils/content-editable.js b/src/client/core/utils/content-editable.js index 46dfb13bd9..4546fa4797 100644 --- a/src/client/core/utils/content-editable.js +++ b/src/client/core/utils/content-editable.js @@ -285,16 +285,16 @@ export function getNearestCommonAncestor (node1, node2) { //selection utils function getSelectedPositionInParentByOffset (node, offset) { - // NOTE: we get a child element by its offset index in the parent - if (domUtils.isShadowUIElement(node)) - return { node, offset }; - const childNodes = nativeMethods.nodeChildNodesGetter.call(node); const childCount = domUtils.getChildNodesLength(childNodes); let isSearchForLastChild = offset >= childCount; let currentNode = childNodes[offset]; let currentOffset = 0; + // NOTE: we get a child element by its offset index in the parent + if (domUtils.isShadowUIElement(node) || !currentNode) + return { node, offset }; + // NOTE: skip shadowUI elements if (domUtils.isShadowUIElement(currentNode)) { if (childCount <= 1) diff --git a/test/functional/fixtures/regression/gh-8321/pages/index.html b/test/functional/fixtures/regression/gh-8321/pages/index.html new file mode 100644 index 0000000000..4a6a85f03e --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/pages/index.html @@ -0,0 +1,23 @@ + + + + + + +
+
example
+
+ + + \ No newline at end of file diff --git a/test/functional/fixtures/regression/gh-8321/test.js b/test/functional/fixtures/regression/gh-8321/test.js new file mode 100644 index 0000000000..b0c7fe6211 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/test.js @@ -0,0 +1,5 @@ +describe('[Regression](GH-8321)', function () { + it('Should type text without errors when document selection is updated', function () { + return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' }); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js b/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js new file mode 100644 index 0000000000..3bdfcc048e --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js @@ -0,0 +1,11 @@ +import { Selector } from 'testcafe'; + +fixture('GH-8321 - Callsite Issue') + .page`http://localhost:3000/fixtures/regression/gh-8321/pages/index.html`; + +test('Callsite Issue', async t => { + const editor = Selector('[contenteditable=true]'); + + await t.click(editor); + await t.typeText(editor, 'text1'); +});