From 55e78b49edeaee363a385c051bf78c1efadc3d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Thu, 4 Jul 2024 16:01:45 +0200 Subject: [PATCH] Update checkCursorPosition function in e2e tests --- WebExample/__tests__/input.spec.ts | 6 +++--- WebExample/__tests__/textManipulation.spec.ts | 6 +++--- WebExample/__tests__/utils.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/WebExample/__tests__/input.spec.ts b/WebExample/__tests__/input.spec.ts index 25b5ef53..3ec26376 100644 --- a/WebExample/__tests__/input.spec.ts +++ b/WebExample/__tests__/input.spec.ts @@ -1,6 +1,6 @@ import {test, expect} from '@playwright/test'; import * as TEST_CONST from '../../example/src/testConstants'; -import {checkCursorPosition, getElementValue, setupInput} from './utils'; +import {getCursorPosition, getElementValue, setupInput} from './utils'; test.beforeEach(async ({page}) => { await page.goto(TEST_CONST.LOCAL_URL, {waitUntil: 'load'}); @@ -25,8 +25,8 @@ test.describe('typing', () => { expect(await getElementValue(inputLocator)).toBe(EXAMPLE_LONG_CONTENT); - const cursorPosition = await checkCursorPosition(inputLocator); + const cursorPosition = await getCursorPosition(inputLocator); - expect(cursorPosition).toBe(EXAMPLE_LONG_CONTENT.length); + expect(cursorPosition.end).toBe(EXAMPLE_LONG_CONTENT.length); }); }); diff --git a/WebExample/__tests__/textManipulation.spec.ts b/WebExample/__tests__/textManipulation.spec.ts index 369aa037..fa970c92 100644 --- a/WebExample/__tests__/textManipulation.spec.ts +++ b/WebExample/__tests__/textManipulation.spec.ts @@ -1,7 +1,7 @@ import {test, expect} from '@playwright/test'; import type {Locator, Page} from '@playwright/test'; import * as TEST_CONST from '../../example/src/testConstants'; -import {checkCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue} from './utils'; +import {getCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue} from './utils'; const pasteContent = async ({text, page, inputLocator}: {text: string; page: Page; inputLocator: Locator}) => { await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), text); @@ -93,9 +93,9 @@ test('select all', async ({page}) => { await inputLocator.focus(); await pressCmd({inputLocator, command: 'a'}); - const cursorPosition = await checkCursorPosition(inputLocator); + const cursorPosition = await getCursorPosition(inputLocator); - expect(cursorPosition).toBe(TEST_CONST.EXAMPLE_CONTENT.length); + expect(cursorPosition.end).toBe(TEST_CONST.EXAMPLE_CONTENT.length); }); test('cut content changes', async ({page, browserName}) => { diff --git a/WebExample/__tests__/utils.ts b/WebExample/__tests__/utils.ts index a5c42a8e..f93b233d 100644 --- a/WebExample/__tests__/utils.ts +++ b/WebExample/__tests__/utils.ts @@ -11,8 +11,8 @@ const setupInput = async (page: Page, action?: 'clear' | 'reset') => { return inputLocator; }; -const checkCursorPosition = async (elementHandle: Locator) => { - const inputSelectionHandle = await elementHandle.evaluateHandle((div: MarkdownTextInputElement) => div.selectionEnd); +const getCursorPosition = async (elementHandle: Locator) => { + const inputSelectionHandle = await elementHandle.evaluateHandle((div: MarkdownTextInputElement) => ({start: div.selectionStart, end: div.selectionEnd})); const selection = await inputSelectionHandle.jsonValue(); return selection; }; @@ -59,4 +59,4 @@ const getElementValue = async (elementHandle: Locator) => { return value; }; -export {setupInput, checkCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue}; +export {setupInput, getCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue};