Skip to content

Implement code and pre blocks support on web #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 165 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
f853061
Add refactor changes
Skalakid Jun 25, 2024
c4108c1
Fix parserUtils
Skalakid Jun 25, 2024
38693c4
Add tree building when creating markdown HTML structure
Skalakid Jun 26, 2024
6a1eaf1
Refactor function and type names
Skalakid Jun 26, 2024
75d6afd
Fix TS errors
Skalakid Jun 26, 2024
db68b78
Update parser structure
Skalakid Jun 26, 2024
31711ab
Move BrowserUtils into an object
Skalakid Jun 26, 2024
cab8ca7
Move utils to separate folder
Skalakid Jun 26, 2024
2f829cc
Add block utils
Skalakid Jun 26, 2024
b9b2984
Move functions from above the web component to utils
Skalakid Jun 26, 2024
3fbc456
Fix unit tests
Skalakid Jun 27, 2024
d74e0e4
Fix cursor positioning bugs
Skalakid Jun 28, 2024
220395b
Remove scrollCursorIntoView function
Skalakid Jun 28, 2024
4d95382
Rename variable names
Skalakid Jun 28, 2024
907c73b
Replace textContent with ref value
Skalakid Jun 28, 2024
1017ebc
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jun 28, 2024
1f1fefd
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 1, 2024
ff41dd7
Fix crashes and cursor positioning in E/App
Skalakid Jul 1, 2024
d1d8a49
Fix copying and pasting text with markdown
Skalakid Jul 1, 2024
153ead8
Fix pasting text starting with newlines
Skalakid Jul 1, 2024
ea6aad8
Fix errors when replacing text
Skalakid Jul 2, 2024
87953bb
Fix HTML injestions and pasted text parsing
Skalakid Jul 2, 2024
3d30621
Fix paste text trimming condiftion
Skalakid Jul 2, 2024
471f53a
Fix cutting text
Skalakid Jul 2, 2024
92a224c
Change handlePaste logic to fix newlines in pasted text
Skalakid Jul 2, 2024
c14add4
Fix cursor positioning when undoing/redoing previously pasted text
Skalakid Jul 2, 2024
e9d8ec3
Fix text coloring
Skalakid Jul 2, 2024
e24d259
Add review changes
Skalakid Jul 3, 2024
092775d
Move updateTextColor function
Skalakid Jul 3, 2024
a0c1dfa
Fix cursor positioning when changing text and styles at the same time
Skalakid Jul 3, 2024
d04ad32
Fix newlines on FireFox
Skalakid Jul 3, 2024
63de148
Fix cursor position value update when entering newline inside codeblock
Skalakid Jul 3, 2024
f06d10f
Fix removing characters when cursor is at the beginning of the line o…
Skalakid Jul 3, 2024
34eabe2
Fix writing in empty line on Firefox
Skalakid Jul 3, 2024
a52e3f5
Fix cursor position value on Cmd+A on FireFox
Skalakid Jul 3, 2024
b5515cf
Fix getting value in e2e tests
Skalakid Jul 4, 2024
5a043a3
Fix input e2e tests
Skalakid Jul 4, 2024
5a1dae2
Fix style e2e tests
Skalakid Jul 4, 2024
60f4f4b
Fix text manipulation e2e tests
Skalakid Jul 4, 2024
55e78b4
Update checkCursorPosition function in e2e tests
Skalakid Jul 4, 2024
8a0a7be
Update checkCursorPosition function in e2e tests
Skalakid Jul 4, 2024
96a9b5c
Fix cursor position after redoing pasted text
Skalakid Jul 5, 2024
8c85473
Merge branch '@Skalakid/web-parser-refactor' of github.com:Expensify/…
Skalakid Jul 5, 2024
401febe
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 5, 2024
862e74a
Fix e2e tests on CI/CD
Skalakid Jul 5, 2024
0580f45
Uncomment undo test
Skalakid Jul 5, 2024
6682c9d
Fix TS errors
Skalakid Jul 5, 2024
8165fb9
Change line merging funciton
Skalakid Jul 5, 2024
9e2b943
Fix selection event sending on paste
Skalakid Jul 5, 2024
0f5b86a
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 8, 2024
5f369ec
Fix scrolling cursor into view on Safari browser
Skalakid Jul 8, 2024
7cdaf9a
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 9, 2024
6bada78
Enhance cursor positioning on input
Skalakid Jul 9, 2024
d9c097d
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 10, 2024
309bccf
Fix diacritics after CMD+A
Skalakid Jul 10, 2024
90d2ea3
Fix autocorrect cursor positioning
Skalakid Jul 10, 2024
111fd6b
Fix deleting codeBlock lines with CMD+backspace
Skalakid Jul 10, 2024
d14f4ba
Fix text color on undo/redo
Skalakid Jul 10, 2024
82d58ca
Fix removing last letter from the line
Skalakid Jul 10, 2024
2b9e56a
Fix cursor position when replacing text with the same text
Skalakid Jul 11, 2024
5861a21
Change parseInnerHTMLToText function
Skalakid Jul 15, 2024
68ae9be
Fix input behavior when interracting with display: block element
Skalakid Jul 15, 2024
0bc882a
Fix getTreeNodeByIndex function
Skalakid Jul 16, 2024
cc8e307
Fix replacing whole content of the input
Skalakid Jul 16, 2024
3da3989
Fix set cursor position when content changes
Skalakid Jul 16, 2024
ccb251e
Fix removing selection on paste
Skalakid Jul 16, 2024
e759170
Fix set cursor position on paste
Skalakid Jul 16, 2024
4db4441
Fix dissapearing cursor bug
Skalakid Jul 16, 2024
0480cb8
Fix pasting text into empty input
Skalakid Jul 16, 2024
5faac50
Fix newline deletion
Skalakid Jul 17, 2024
14d0eed
Improve parseInnerHTMLToText function and fix pasted text correct val…
Skalakid Jul 18, 2024
0c204f5
Remove buildTree function
Skalakid Jul 18, 2024
de12aca
Fix tests
Skalakid Jul 18, 2024
8648205
Replacing text by text cursor position
Skalakid Jul 19, 2024
eb1502a
Fix cursor positioning on custom text pasting (E/App)
Skalakid Jul 19, 2024
3486303
Add function comments
Skalakid Jul 19, 2024
fd2be10
feat: code block background with proper handling
BartoszGrajdek Jul 25, 2024
df04ba0
feat: adjust styles for background width
BartoszGrajdek Jul 25, 2024
3958bc3
feat: support for custom styles
BartoszGrajdek Jul 29, 2024
c57b91f
fix: refactor stylesheet handling
BartoszGrajdek Aug 21, 2024
07ce864
chore: resolve merge conflicts
BartoszGrajdek Sep 12, 2024
9485690
feat: improve styling
BartoszGrajdek Sep 19, 2024
b5a09d6
chore: resolve merge conflicts
BartoszGrajdek Sep 19, 2024
5bea3f1
fix: paddings & autocorrect
BartoszGrajdek Oct 1, 2024
5eb25b3
chore: resolve merge conflicts
BartoszGrajdek Oct 1, 2024
457ea25
feat: add support for vertical & horizontal padding
BartoszGrajdek Oct 1, 2024
561e0ec
fix: jumping background
BartoszGrajdek Oct 14, 2024
6f1c32f
chore: merge main
BartoszGrajdek Oct 14, 2024
e54929e
fix: background issues
BartoszGrajdek Oct 17, 2024
6379bb5
fix: cursor positioning
BartoszGrajdek Oct 28, 2024
a7fc650
fix: background sizing
BartoszGrajdek Oct 30, 2024
3fa6fba
chore: resolve merge conflicts
BartoszGrajdek Nov 29, 2024
bb46ce0
fix: insufficient line-height in large code blocks
BartoszGrajdek Dec 9, 2024
cddf8a0
chore: resolve merge conflicts
BartoszGrajdek Dec 9, 2024
7bc4ef0
fix: inline code parser problems
BartoszGrajdek Dec 11, 2024
4aa355b
fix: performance & line-height
BartoszGrajdek Feb 23, 2025
830b866
chore: resolve merge conflicts
BartoszGrajdek Feb 23, 2025
1097a16
fix: resizing & styles not loading
BartoszGrajdek Feb 28, 2025
32f1a1d
refactor: cleanup
BartoszGrajdek Mar 3, 2025
351c32a
fix: code markdown fontSize in h1 tag
Skalakid Mar 11, 2025
b035335
chore: resolve merge conflicts
Skalakid Mar 11, 2025
c858c96
chore: merge main
Skalakid Apr 9, 2025
1f2e93f
fix: tests
Skalakid Apr 9, 2025
e8b5e80
Mock RNweb funtions
Skalakid Apr 11, 2025
89018dc
Remove unneccesary type export
Skalakid Apr 11, 2025
ee0609b
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Apr 15, 2025
2d3fcf9
Add review changes
Skalakid Apr 15, 2025
ee67a71
Fix InputHistory after merge
Skalakid Apr 15, 2025
e2c2993
Move getPropertyValue
Skalakid Apr 15, 2025
46818b0
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Apr 28, 2025
c0ff1ba
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid May 13, 2025
0a95808
Fix removing last new line in code block on Firefox
Skalakid May 14, 2025
a8b249b
Fix codeblock height when enetring different markdown in the same line
Skalakid May 15, 2025
3b5161d
Make input parser fix only for Firefox
Skalakid May 15, 2025
6775991
Fix flickering spellcheck
Skalakid May 16, 2025
4c22b9d
Rename function
Skalakid May 16, 2025
3b02ffe
Fix JS errors when value prop isn't passed
Skalakid May 19, 2025
edab956
Remove stylesheet when component is unmounted
Skalakid May 19, 2025
884722a
Unify inline-code and pre styles2
Skalakid May 19, 2025
6212c9c
Make border styles optional
Skalakid May 19, 2025
0aff26d
Enhance style tests for codeblock
Skalakid May 20, 2025
d091bc9
Change codeblock HTML structure
Skalakid May 23, 2025
7072394
Fix tests
Skalakid May 23, 2025
3fbe395
Fix issue with multiple codeblocks in one input
Skalakid May 23, 2025
5297311
Fix scrolling to the proper line inside codeblock when focusing an input
Skalakid May 26, 2025
c771ca7
Fix placing cursor at the end of first codeblock syntax
Skalakid May 27, 2025
0924fb3
Fix selectable area inside codeblock on FireFox
Skalakid May 27, 2025
26c82b3
Fix writing outside of codeblock borders
Skalakid May 27, 2025
a15826a
Add codeblock e2e tests
Skalakid May 27, 2025
ddbceed
Add codeblock content wrapping test
Skalakid May 27, 2025
f84890c
Add codeblock input resizing test
Skalakid May 27, 2025
d2d8c54
Fix codeblock dimensions test
Skalakid May 27, 2025
6f8d873
Add test for scrolling codeblock into view
Skalakid May 27, 2025
e4efbdf
Fix scrolling to BR inside the codeblock
Skalakid May 27, 2025
39740ad
Add delay after resizing the input
Skalakid May 27, 2025
51d1d59
Fix display in global css file
Skalakid May 27, 2025
cab5ca6
Fix placing and focusing to the cursor at the end of the codeblock op…
Skalakid May 28, 2025
5a5a2e9
Move isChildOfMarkdownElementTypes function to inputUtils
Skalakid May 28, 2025
7512207
Fix newline generation after clearing the input
Skalakid May 30, 2025
c3af8d3
Fix breaking codeblock when removing first newline
Skalakid Jun 2, 2025
ac0bee5
Fix breaking codeblock when removing last newline
Skalakid Jun 2, 2025
0d1b6d5
Move codeblock element styles to css file
Skalakid Jun 2, 2025
5b6bab9
Fix breaking codeblock structure when deleting text before the closin…
Skalakid Jun 3, 2025
44b59a7
Fix breaking codeblock when removing first newline
Skalakid Jun 3, 2025
c59982b
Update test names
Skalakid Jun 3, 2025
35785eb
Add newline removal tests
Skalakid Jun 3, 2025
e343025
Fix codeblock tests structure
Skalakid Jun 4, 2025
53050a4
Add content modification tests
Skalakid Jun 4, 2025
8cdb8c3
Update code comments
Skalakid Jun 4, 2025
db4ab11
Fix removing newline at the end of codeblock on all platforms
Skalakid Jun 4, 2025
5d2c50d
Fix problems with multiple codeblock merging together
Skalakid Jun 4, 2025
34dbda2
Add codeblock styling checks
Skalakid Jun 4, 2025
382ba4b
Add testCodeblock function to playwright tests
Skalakid Jun 4, 2025
733115c
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Jun 4, 2025
1ff2515
Add codeblock markdown count check
Skalakid Jun 5, 2025
3aba838
Add newlines
Skalakid Jun 5, 2025
67b97b5
Clean up code
Skalakid Jun 5, 2025
7180aad
Refactor codeblock styles
Skalakid Jun 6, 2025
6671add
Clean up code after refactor
Skalakid Jun 9, 2025
f2ed1c3
Remove newlines
Skalakid Jun 9, 2025
ddd456b
Update tests
Skalakid Jun 9, 2025
6201427
Fix codeblock style test
Skalakid Jun 9, 2025
f3a0a12
Clean up web component changes
Skalakid Jun 9, 2025
02bde24
Merge simillar styles
Skalakid Jun 9, 2025
c022083
Add review changes
Skalakid Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
'es/no-nullish-coalescing-operators': 'off',
'es/no-optional-chaining': 'off',
'@typescript-eslint/no-use-before-define': 'off', // TODO consider enabling this (currently it reports styles defined at the bottom of the file)
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' },
Expand Down
287 changes: 287 additions & 0 deletions WebExample/__tests__/codeblock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
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 {getElementValue, pressCmd, setCursorPosition, setupInput, testMarkdownContentStyle} from './utils';

const CODEBLOCK_DEFAULT_STYLE =
'font-family: monospace; font-size: 20px; color: black; background-color: lightgray; border-color: gray; border-width: 1px; border-radius: 4px; border-style: solid; padding: 2px;';

async function testCodeblockStyle(page: Page, dimmensions: {height: number; width: number} | null, style: string | null = CODEBLOCK_DEFAULT_STYLE) {
if (style === null) {
await testMarkdownContentStyle({
testContent: 'Codeblock',
style: 'margin: 0px; padding: 0px;',
page,
});
return;
}
await testMarkdownContentStyle({
testContent: 'Codeblock',
style,
dimmensions: dimmensions ?? undefined,
page,
});
}

async function getCodeblockElementCount(inputLocator: Locator) {
return inputLocator.locator(`span[data-type="codeblock"]`).count();
}

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

test.describe('modifying codeblock content', () => {
test('keep newlines when writing after opening syntax', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 0);
await inputLocator.pressSequentially('test');

expect(await getElementValue(inputLocator)).toEqual('```test\nCodeblock\nSample code line\n```');
// Verify if the codeblock style wasn't applied
await testCodeblockStyle(page, null, null);
});

test('keep codeblock structure when writing in the empty last line', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n\n```');

await setCursorPosition(page, 6, 0);
await inputLocator.pressSequentially('test');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\ntest\n```');
await testCodeblockStyle(page, {
height: 84,
width: 198,
});
});

test('allow writing after closing syntax', async ({page}) => {
const codeblockDimmensions = {
height: 58,
width: 198,
};
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 6);
await testCodeblockStyle(page, codeblockDimmensions);
await inputLocator.pressSequentially('test');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\n```test');
// Verify if when typing after codeblock closing syntax, its height is not changed
await testCodeblockStyle(page, codeblockDimmensions);
});

test('remove whole codeblock', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await pressCmd({inputLocator, command: 'a'});
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('');
});

test('wrap content', async ({page}) => {
const LINE_TO_ADD = ' very long line of code that should be wrapped';
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 3);
await inputLocator.pressSequentially(LINE_TO_ADD);

expect(await getElementValue(inputLocator)).toEqual(`\`\`\`\nCodeblock${LINE_TO_ADD}\nSample code line\n\`\`\``);
await testCodeblockStyle(page, {
height: 110,
width: 288,
});
});

test('remove newline after opening syntax', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 2, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```Codeblock\nSample code line\n```');
// Verify if the codeblock style wasn't applied
await testCodeblockStyle(page, null, null);
});

test('remove newline after opening syntax with single line content', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\n```');

await setCursorPosition(page, 2, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```Codeblock\n```');
// Verify if the codeblock style wasn't applied
await testCodeblockStyle(page, null, null);
});

test('remove newline before closing syntax', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 6, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line```');
// Verify if the codeblock style wasn't applied
await testCodeblockStyle(page, null, null);
});

test('remove newline before closing syntax with one empty line at the end', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n\n```');

await setCursorPosition(page, 6, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\n```');
await testCodeblockStyle(page, {
height: 58,
width: 198,
});
});

test('remove newline before closing syntax with two empy lines at the end', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n\n\n```');

await setCursorPosition(page, 6, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\n\n```');
await testCodeblockStyle(page, {
height: 84,
width: 198,
});
});

test('remove newline before opening syntax', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('\n\n```\nCodeblock\nSample code line\n```');

await setCursorPosition(page, 2, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('\n```\nCodeblock\nSample code line\n```');
await testCodeblockStyle(page, {
height: 58,
width: 198,
});
});

test('remove newline between two codeblocks', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample code line\n```\n```\nCodeblock\nSecond sample code line\n```');

await setCursorPosition(page, 7, 0);
await inputLocator.press('Backspace');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\n``````\nCodeblock\nSecond sample code line\n```');
expect(await getCodeblockElementCount(inputLocator)).toEqual(1);

await inputLocator.press('Enter');

expect(await getElementValue(inputLocator)).toEqual('```\nCodeblock\nSample code line\n```\n```\nCodeblock\nSecond sample code line\n```');
expect(await getCodeblockElementCount(inputLocator)).toEqual(2);
});
});

test('update codeblock dimensions when resizing the input', async ({page}) => {
await page.setViewportSize({width: 1280, height: 720});
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.pressSequentially('```\nCodeblock\nSample very long line of code that should be wrapped\n```');

await testCodeblockStyle(page, {
height: 110,
width: 288,
});

await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
element.style.width = '500px';
element.style.height = '200px';
});
await page.waitForTimeout(10);

await testCodeblockStyle(page, {
height: 84,
width: 488,
});
});

test.describe('scrolling into view', () => {
test('scroll to an empty codeblock line', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
element.style.height = '100px';
});
await inputLocator.pressSequentially('```\nCodeblock start\n\n\n\n\n\n\n\n\nCodeblock end\n```');

await setCursorPosition(page, 4);
await inputLocator.blur();
await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
element.scrollTop = element.scrollHeight;
return element.scrollHeight;
});

await inputLocator.focus();
const scrollTop = await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
return element.scrollTop;
});

expect(scrollTop).toBeLessThanOrEqual(30);
});

test('scroll to the cursor after opening syntax', async ({page}) => {
const inputLocator = await setupInput(page, 'clear');
await inputLocator.focus();
await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
element.style.height = '100px';
});
await inputLocator.pressSequentially('```\nCodeblock start\n\n\n\n\n\n\n\n\nCodeblock end\n```');

await setCursorPosition(page, 1);
await inputLocator.blur();
await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
element.scrollTop = element.scrollHeight;
return element.scrollHeight;
});

await inputLocator.focus();
const scrollTop = await inputLocator.evaluate((inputElement: HTMLInputElement) => {
const element = inputElement;
return element.scrollTop;
});

expect(scrollTop).toBeLessThanOrEqual(25);
});
});
28 changes: 14 additions & 14 deletions WebExample/__tests__/styles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import {test, expect} from '@playwright/test';
import type {Page} from '@playwright/test';
import {test} from '@playwright/test';
// eslint-disable-next-line import/no-relative-packages
import * as TEST_CONST from '../../example/src/testConstants';
import {setupInput, getElementStyle} from './utils';

const testMarkdownContentStyle = async ({testContent, style, page}: {testContent: string; style: string; page: Page}) => {
const inputLocator = await setupInput(page);

const elementHandle = inputLocator.locator('span', {hasText: testContent}).last();
const elementStyle = await getElementStyle(elementHandle);

expect(elementStyle).toEqual(style);
};
import {testMarkdownContentStyle} from './utils';

test.beforeEach(async ({page}) => {
await page.goto(TEST_CONST.LOCAL_URL, {waitUntil: 'load'});
Expand All @@ -32,11 +22,21 @@ test.describe('markdown content styling', () => {
});

test('inline code', async ({page}) => {
await testMarkdownContentStyle({testContent: 'inline code', style: 'font-family: monospace; font-size: 20px; color: black; background-color: lightgray;', page});
await testMarkdownContentStyle({
testContent: 'inline code',
style:
'font-family: monospace; font-size: 20px; color: black; background-color: lightgray; border-color: gray; border-width: 1px; border-radius: 4px; border-style: solid; padding: 0px; line-height: 1.5;',
page,
});
});

test('codeblock', async ({page}) => {
await testMarkdownContentStyle({testContent: 'codeblock', style: 'font-family: monospace; font-size: 20px; color: black; background-color: lightgray;', page});
await testMarkdownContentStyle({
testContent: 'codeblock',
style:
'font-family: monospace; font-size: 20px; color: black; background-color: lightgray; border-color: gray; border-width: 1px; border-radius: 4px; border-style: solid; padding: 2px;',
page,
});
});

test('mention-here', async ({page}) => {
Expand Down
2 changes: 1 addition & 1 deletion WebExample/__tests__/textManipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ test('cut content changes', async ({page, browserName}) => {

expect(await getElementValue(inputLocator)).toBe(EXPECTED_CONTENT);

// Ckeck if there is no markdown elements after the cut operation
// Check if there is no markdown elements after the cut operation
const spans = await inputLocator.locator('span[data-type="text"]');
expect(await spans.count()).toBe(1);
});
Expand Down
Loading
Loading