Skip to content

Commit

Permalink
Update checkCursorPosition function in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Jul 4, 2024
1 parent 60f4f4b commit 55e78b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions WebExample/__tests__/input.spec.ts
Original file line number Diff line number Diff line change
@@ -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'});
Expand All @@ -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);
});
});
6 changes: 3 additions & 3 deletions WebExample/__tests__/textManipulation.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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}) => {
Expand Down
6 changes: 3 additions & 3 deletions WebExample/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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};

0 comments on commit 55e78b4

Please sign in to comment.