Skip to content

Commit

Permalink
cleanup, rename constants
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed May 6, 2024
1 parent afa5758 commit 9275353
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 36 deletions.
3 changes: 2 additions & 1 deletion WebExample/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {defineConfig, devices} from '@playwright/test';
import * as TEST_CONST from '../testConstants';

export default defineConfig({
testDir: './tests',
preserveOutput: 'never',
webServer: {
command: 'yarn web',
url: 'http://localhost:19006',
url: TEST_CONST.LOCAL_URL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
Expand Down
10 changes: 5 additions & 5 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 type {Page} from '@playwright/test';
import * as CONSTANTS from '../../constants';
import * as TEST_CONST from '../../testConstants';

const setupInput = async (page: Page, mode: 'clear' | 'reset') => {
const inputLocator = await page.locator(`div#MarkdownInput_Example`);
Expand All @@ -10,20 +10,20 @@ const setupInput = async (page: Page, mode: 'clear' | 'reset') => {
};

test.beforeEach(async ({page}) => {
await page.goto('http://localhost:19006/', {waitUntil: 'load'});
await page.goto(TEST_CONST.LOCAL_URL, {waitUntil: 'load'});
});

test.describe('standard input behaviour', () => {
test('standard input results', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');

await inputLocator.pressSequentially(CONSTANTS.EXAMPLE_CONTENT);
await inputLocator.pressSequentially(TEST_CONST.EXAMPLE_CONTENT);
const value = await inputLocator.innerText();
expect(value).toEqual(CONSTANTS.EXAMPLE_CONTENT);
expect(value).toEqual(TEST_CONST.EXAMPLE_CONTENT);
});

test('fast type cursor position', async ({page}) => {
const EXAMPLE_LONG_CONTENT = CONSTANTS.EXAMPLE_CONTENT.repeat(3);
const EXAMPLE_LONG_CONTENT = TEST_CONST.EXAMPLE_CONTENT.repeat(3);

const inputLocator = await setupInput(page, 'clear');

Expand Down
22 changes: 11 additions & 11 deletions WebExample/tests/styles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {test, expect} from '@playwright/test';
import type {Page} from '@playwright/test';
import * as CONSTANTS from '../../constants';
import * as TEST_CONST from '../../testConstants';

const setupInput = async (page: Page) => {
const inputLocator = await page.locator(`div#MarkdownInput_Example`);
Expand All @@ -23,45 +23,45 @@ const testMarkdownContentStyle = async ({styleName, style, page}: {styleName: st
};

test.beforeEach(async ({page}) => {
await page.goto('http://localhost:19006/', {waitUntil: 'load'});
await page.goto(TEST_CONST.LOCAL_URL, {waitUntil: 'load'});
await page.click('[data-testid="reset"]');
});

test.describe('markdown content styling', () => {
test('bold', async ({page}) => {
await testMarkdownContentStyle({styleName: 'bold', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.bold.style, page});
await testMarkdownContentStyle({styleName: 'bold', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.bold.style, page});
});

test('link', async ({page}) => {
await testMarkdownContentStyle({styleName: 'link', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.link.style, page});
await testMarkdownContentStyle({styleName: 'link', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.link.style, page});
});

test('title', async ({page}) => {
await testMarkdownContentStyle({styleName: 'title', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.title.style, page});
await testMarkdownContentStyle({styleName: 'title', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.title.style, page});
});

test('code', async ({page}) => {
await testMarkdownContentStyle({styleName: 'code', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.code.style, page});
await testMarkdownContentStyle({styleName: 'code', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.code.style, page});
});

test('codeBlock', async ({page}) => {
await testMarkdownContentStyle({styleName: 'codeBlock', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.codeBlock.style, page});
await testMarkdownContentStyle({styleName: 'codeBlock', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.codeBlock.style, page});
});

test('hereMention', async ({page}) => {
await testMarkdownContentStyle({styleName: 'here', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.here.style, page});
await testMarkdownContentStyle({styleName: 'here', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.here.style, page});
});

test('mentionUser', async ({page}) => {
await testMarkdownContentStyle({styleName: 'mentionUser', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.mentionUser.style, page});
await testMarkdownContentStyle({styleName: 'mentionUser', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.mentionUser.style, page});
});

test('roomMention', async ({page}) => {
await testMarkdownContentStyle({styleName: 'roomMention', style: CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.roomMention.style, page});
await testMarkdownContentStyle({styleName: 'roomMention', style: TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.roomMention.style, page});
});

test('blockquote', async ({page, browserName}) => {
const blockquoteStyle = CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.blockquote.style;
const blockquoteStyle = TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.blockquote.style;
// Firefox border properties are serialized slightly differently
const browserStyle = browserName === 'firefox' ? blockquoteStyle.replace(' border-left-style: solid', ' border-left: 6px solid gray') : blockquoteStyle;

Expand Down
22 changes: 11 additions & 11 deletions WebExample/tests/textManipulation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {test, expect} from '@playwright/test';
import type {Locator, Page} from '@playwright/test';
import * as CONSTANTS from '../../constants';
import * as TEST_CONST from '../../testConstants';

const setupInput = async (page: Page, mode: 'clear' | 'reset') => {
const inputLocator = await page.locator(`div#MarkdownInput_Example`);
Expand All @@ -18,14 +18,14 @@ const pasteContent = async ({text, page, inputLocator}: {text: string; page: Pag
};

test.beforeEach(async ({page, context, browserName}) => {
await page.goto('http://localhost:19006/', {waitUntil: 'load'});
await page.goto(TEST_CONST.LOCAL_URL, {waitUntil: 'load'});
if (browserName === 'chromium') await context.grantPermissions(['clipboard-write', 'clipboard-read']);
});

test.describe('paste content', () => {
test('paste', async ({page}) => {
const PASTE_TEXT = 'bold';
const boldStyleDefinition = CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.bold;
const boldStyleDefinition = TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.bold;

const inputLocator = await setupInput(page, 'clear');

Expand Down Expand Up @@ -63,10 +63,10 @@ test.describe('paste content', () => {
await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), PASTE_TEXT_FIRST);

await inputLocator.press(`${OPERATION_MODIFIER}+v`);
await page.waitForTimeout(CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.waitForTimeout(TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), PASTE_TEXT_SECOND);
await inputLocator.press(`${OPERATION_MODIFIER}+v`);
await page.waitForTimeout(CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.waitForTimeout(TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS);

await inputLocator.press(`${OPERATION_MODIFIER}+z`);

Expand All @@ -81,11 +81,11 @@ test.describe('paste content', () => {

await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), PASTE_TEXT_FIRST);
await inputLocator.press(`${OPERATION_MODIFIER}+v`);
await page.waitForTimeout(CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.waitForTimeout(TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.evaluate(async (pasteText) => navigator.clipboard.writeText(pasteText), PASTE_TEXT_SECOND);
await page.waitForTimeout(CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.waitForTimeout(TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await inputLocator.press(`${OPERATION_MODIFIER}+v`);
await page.waitForTimeout(CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS);
await page.waitForTimeout(TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS);

await inputLocator.press(`${OPERATION_MODIFIER}+z`);
await inputLocator.press(`${OPERATION_MODIFIER}+Shift+z`);
Expand All @@ -110,13 +110,13 @@ test('select', async ({page}) => {
return preCaretRange.toString().length;
});

expect(cursorPosition).toBe(CONSTANTS.EXAMPLE_CONTENT.length);
expect(cursorPosition).toBe(TEST_CONST.EXAMPLE_CONTENT.length);
});

test('cut content changes', async ({page}) => {
const INITIAL_CONTENT = 'bold';
const WRAPPED_CONTENT = CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.bold.wrapContent(INITIAL_CONTENT);
const EXPECTED_CONTENT = CONSTANTS.MARKDOWN_STYLE_DEFINITIONS.bold.wrapContent(INITIAL_CONTENT).slice(0, 3);
const WRAPPED_CONTENT = TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.bold.wrapContent(INITIAL_CONTENT);
const EXPECTED_CONTENT = TEST_CONST.MARKDOWN_STYLE_DEFINITIONS.bold.wrapContent(INITIAL_CONTENT).slice(0, 3);

const inputLocator = await setupInput(page, 'clear');
await pasteContent({text: WRAPPED_CONTENT, page, inputLocator});
Expand Down
2 changes: 1 addition & 1 deletion WebExample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"strict": true
},
"include": ["App.tsx", "**/*.ts", "../constants.ts"],
"include": ["App.tsx", "**/*.ts", "../testConstants.ts"],
"exclude": ["node_modules"]
}
7 changes: 4 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Button, Platform, StyleSheet, Text, View} from 'react-native';

import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import type {TextInput} from 'react-native';
import * as CONSTANTS from '../../constants';
import * as TEST_CONST from '../../testConstants';

function isWeb() {
return Platform.OS === 'web';
Expand Down Expand Up @@ -59,7 +59,7 @@ function getRandomColor() {
}

export default function App() {
const [value, setValue] = React.useState(CONSTANTS.EXAMPLE_CONTENT);
const [value, setValue] = React.useState(TEST_CONST.EXAMPLE_CONTENT);
const [markdownStyle, setMarkdownStyle] = React.useState({});
const [selection, setSelection] = React.useState({start: 0, end: 0});

Expand Down Expand Up @@ -100,6 +100,7 @@ export default function App() {
placeholder="Type here..."
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
selection={selection}
id={TEST_CONST.INPUT_ID}
/>
{/* <Text>TextInput singleline</Text>
<TextInput
Expand Down Expand Up @@ -141,7 +142,7 @@ export default function App() {
testID="reset"
title="Reset"
onPress={() => {
setValue(CONSTANTS.EXAMPLE_CONTENT);
setValue(TEST_CONST.EXAMPLE_CONTENT);
setMarkdownStyle({});
}}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
value,
autoFocus = false,
onContentSizeChange,
id,
},
ref,
) => {
Expand Down Expand Up @@ -601,7 +602,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
id="MarkdownInput_Example"
id={id}
ref={setRef}
contentEditable={!disabled}
style={inputStyles}
Expand Down
4 changes: 2 additions & 2 deletions src/web/InputHistory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as CONSTANTS from '../../constants';
import * as TEST_CONST from '../../testConstants';

type HistoryItem = {
text: string;
Expand All @@ -18,7 +18,7 @@ export default class InputHistory {

debounceTime: number;

constructor(depth: number, debounceTime = CONSTANTS.INPUT_HISTORY_DEBOUNCE_TIME_MS) {
constructor(depth: number, debounceTime = TEST_CONST.INPUT_HISTORY_DEBOUNCE_TIME_MS) {
this.depth = depth;
this.history = [];
this.historyIndex = 0;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"verbatimModuleSyntax": true,
"typeRoots": ["node_modules/@types"]
},
"include": ["src/**/*", "types/global.d.ts", "constants.ts"],
"include": ["src/**/*", "types/global.d.ts", "testConstants.ts"],
"exclude": ["**/node_modules/**/*", "parser/**/*", "**/lib/**/*", "example/src/**/*", "WebExample/**/*"]
}

0 comments on commit 9275353

Please sign in to comment.