diff --git a/WebExample/__tests__/textManipulation.spec.ts b/WebExample/__tests__/textManipulation.spec.ts index 748d237e7..9a64f7115 100644 --- a/WebExample/__tests__/textManipulation.spec.ts +++ b/WebExample/__tests__/textManipulation.spec.ts @@ -2,7 +2,7 @@ import {test, expect} from '@playwright/test'; import type {Locator, Page} from '@playwright/test'; // eslint-disable-next-line import/no-relative-packages import * as TEST_CONST from '../../example/src/testConstants'; -import {getCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue} from './utils'; +import {getCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue, setSelection, changeMarkdownStyle} from './utils'; const pasteContent = async ({text, page, inputLocator}: {text: string; page: Page; inputLocator: Locator}) => { await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), text); @@ -98,6 +98,18 @@ test('select all', async ({page}) => { expect(cursorPosition.end).toBe(TEST_CONST.EXAMPLE_CONTENT.length); }); +test("don't remove selection when changing markdown style", async ({page}) => { + const inputLocator = await setupInput(page, 'reset'); + + setSelection(page); + changeMarkdownStyle(page); + inputLocator.focus(); + + const cursorPosition = await getCursorPosition(inputLocator); + + expect(cursorPosition.end).toBe(TEST_CONST.SELECTION_END); +}); + test('cut content changes', async ({page, browserName}) => { test.skip(!!process.env.CI && browserName === 'webkit', 'Excluded from WebKit CI tests'); diff --git a/WebExample/__tests__/utils.ts b/WebExample/__tests__/utils.ts index af23dd7c3..ac38d59d1 100644 --- a/WebExample/__tests__/utils.ts +++ b/WebExample/__tests__/utils.ts @@ -11,6 +11,14 @@ const setupInput = async (page: Page, action?: 'clear' | 'reset') => { return inputLocator; }; +const changeMarkdownStyle = async (page: Page) => { + await page.click(`[data-testid="${TEST_CONST.TOGGLE_LINK_COLOR}"]`); +}; + +const setSelection = async (page: Page) => { + await page.click(`[data-testid="${TEST_CONST.CHANGE_SELECTION}"]`); +}; + const getCursorPosition = async (elementHandle: Locator) => { const inputSelectionHandle = await elementHandle.evaluateHandle( ( @@ -65,4 +73,4 @@ const getElementValue = async (elementHandle: Locator) => { return value; }; -export {setupInput, getCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue}; +export {setupInput, getCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue, changeMarkdownStyle, setSelection}; diff --git a/example/src/App.tsx b/example/src/App.tsx index 4284eade7..b5ff45715 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -92,6 +92,7 @@ export default function App() { onPress={() => setTextColorState(prev => !prev)} />