Skip to content

Commit 1302bf2

Browse files
committed
add test
1 parent 578cae5 commit 1302bf2

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

WebExample/__tests__/textManipulation.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {test, expect} from '@playwright/test';
22
import type {Locator, Page} from '@playwright/test';
33
// eslint-disable-next-line import/no-relative-packages
44
import * as TEST_CONST from '../../example/src/testConstants';
5-
import {getCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue} from './utils';
5+
import {getCursorPosition, setupInput, getElementStyle, pressCmd, getElementValue, setSelection, changeMarkdownStyle} from './utils';
66

77
const pasteContent = async ({text, page, inputLocator}: {text: string; page: Page; inputLocator: Locator}) => {
88
await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), text);
@@ -98,6 +98,17 @@ test('select all', async ({page}) => {
9898
expect(cursorPosition.end).toBe(TEST_CONST.EXAMPLE_CONTENT.length);
9999
});
100100

101+
test("don't remove selection when changing markdown style", async ({page}) => {
102+
const inputLocator = await setupInput(page, 'reset');
103+
104+
setSelection(page);
105+
changeMarkdownStyle(page);
106+
107+
const cursorPosition = await getCursorPosition(inputLocator);
108+
109+
expect(cursorPosition.end).toBe(TEST_CONST.SELECTION_END);
110+
});
111+
101112
test('cut content changes', async ({page, browserName}) => {
102113
test.skip(!!process.env.CI && browserName === 'webkit', 'Excluded from WebKit CI tests');
103114

WebExample/__tests__/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ const setupInput = async (page: Page, action?: 'clear' | 'reset') => {
1111
return inputLocator;
1212
};
1313

14+
const changeMarkdownStyle = async (page: Page) => {
15+
await page.click(`[data-testid="${TEST_CONST.TOGGLE_LINK_COLOR}"]`);
16+
};
17+
18+
const setSelection = async (page: Page) => {
19+
await page.click(`[data-testid="${TEST_CONST.CHANGE_SELECTION}"]`);
20+
};
21+
1422
const getCursorPosition = async (elementHandle: Locator) => {
1523
const inputSelectionHandle = await elementHandle.evaluateHandle(
1624
(
@@ -65,4 +73,4 @@ const getElementValue = async (elementHandle: Locator) => {
6573
return value;
6674
};
6775

68-
export {setupInput, getCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue};
76+
export {setupInput, getCursorPosition, setCursorPosition, getElementStyle, pressCmd, getElementValue, changeMarkdownStyle, setSelection};

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default function App() {
9292
onPress={() => setTextColorState(prev => !prev)}
9393
/>
9494
<Button
95+
testID="toggle-link-color"
9596
title="Toggle link color"
9697
onPress={() => setLinkColorState(prev => !prev)}
9798
/>
@@ -113,6 +114,7 @@ export default function App() {
113114
}}
114115
/>
115116
<Button
117+
testID="change-selection"
116118
title="Change selection"
117119
onPress={() => {
118120
if (!ref.current) {

example/src/testConstants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ const EXAMPLE_CONTENT = [
1515
].join('\n');
1616

1717
const INPUT_ID = 'MarkdownInput_Example';
18+
const TOGGLE_LINK_COLOR = 'toggle-link-color';
19+
const CHANGE_SELECTION = 'change-selection';
20+
const SELECTION_END = 20;
1821
const INPUT_HISTORY_DEBOUNCE_TIME_MS = 150;
1922

20-
export {LOCAL_URL, EXAMPLE_CONTENT, INPUT_ID, INPUT_HISTORY_DEBOUNCE_TIME_MS};
23+
export {
24+
LOCAL_URL,
25+
EXAMPLE_CONTENT,
26+
INPUT_ID,
27+
INPUT_HISTORY_DEBOUNCE_TIME_MS,
28+
TOGGLE_LINK_COLOR,
29+
CHANGE_SELECTION,
30+
SELECTION_END,
31+
};

0 commit comments

Comments
 (0)