Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Aug 30, 2024
1 parent c6c70c1 commit 1992975
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WebExample/__tests__/styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test.describe('markdown content styling', () => {

test('blockquote', async ({page, browserName}) => {
const blockquoteStyle =
'border-color: gray; border-width: 6px; margin-left: 6px; padding-left: 6px; border-left-style: solid; display: inline-block; max-width: 100%; box-sizing: border-box;';
'border-color: gray; border-width: 6px; margin-left: 6px; padding-left: 6px; border-left-style: solid; display: inline-block; max-width: 100%; box-sizing: border-box; overflow-wrap: anywhere;';

// 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
13 changes: 11 additions & 2 deletions example/src/testConstants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const LOCAL_URL = 'http://localhost:19006/';

const EXAMPLE_CONTENT =
'![demo image](https://images.unsplash.com/photo-1597431793715-b4b71ddb5670?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=800&ixid=MnwxfDB8MXxyYW5kb218MHx8fHx8fHx8MTcxNDQ3OTI3Nw&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=1900)';
const EXAMPLE_CONTENT = [
'Hello, *world*!',
'https://expensify.com',
'# header1',
'> blockquote',
'`inline code`',
'```\ncodeblock\n```',
'@here',
'@[email protected]',
'#mention-report',
].join('\n');

const INPUT_ID = 'MarkdownInput_Example';
const INPUT_HISTORY_DEBOUNCE_TIME_MS = 150;
Expand Down
12 changes: 12 additions & 0 deletions parser/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ describe('trailing whitespace', () => {
describe('inline image', () => {
test('with alt text', () => {
expect('![test](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 38},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 6, length: 1},
Expand All @@ -412,6 +413,7 @@ describe('inline image', () => {

test('without alt text', () => {
expect('![](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 34},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 2, length: 1},
Expand All @@ -423,6 +425,7 @@ describe('inline image', () => {

test('with same alt text as src', () => {
expect('![https://example.com/image.png](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 63},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 31, length: 1},
Expand All @@ -434,12 +437,14 @@ describe('inline image', () => {

test('text containing images', () => {
expect('An image of a banana: ![banana](https://example.com/banana.png) an image of a developer: ![dev](https://example.com/developer.png)').toBeParsedAs([
{type: 'inline-image', start: 22, length: 41},
{type: 'syntax', start: 22, length: 1},
{type: 'syntax', start: 23, length: 1},
{type: 'syntax', start: 30, length: 1},
{type: 'syntax', start: 31, length: 1},
{type: 'link', start: 32, length: 30},
{type: 'syntax', start: 62, length: 1},
{type: 'inline-image', start: 89, length: 41},
{type: 'syntax', start: 89, length: 1},
{type: 'syntax', start: 90, length: 1},
{type: 'syntax', start: 94, length: 1},
Expand All @@ -451,6 +456,7 @@ describe('inline image', () => {

test('with alt text containing markdown', () => {
expect('![# fake-heading *bold* _italic_ ~strike~ [:-)]](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 79},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 47, length: 1},
Expand All @@ -462,6 +468,7 @@ describe('inline image', () => {

test('text containing image and autolink', () => {
expect('An image of a banana: ![banana](https://example.com/banana.png) an autolink: example.com').toBeParsedAs([
{type: 'inline-image', start: 22, length: 41},
{type: 'syntax', start: 22, length: 1},
{type: 'syntax', start: 23, length: 1},
{type: 'syntax', start: 30, length: 1},
Expand All @@ -482,6 +489,7 @@ describe('inline image', () => {

test('trying to inject additional attributes', () => {
expect('![test" onerror="alert(\'xss\')](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 81},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 29, length: 1},
Expand All @@ -493,6 +501,7 @@ describe('inline image', () => {

test('inline code in alt', () => {
expect('![`code`](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 50},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 8, length: 1},
Expand All @@ -504,6 +513,7 @@ describe('inline image', () => {

test('blockquote in alt', () => {
expect('![```test```](https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 74},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'syntax', start: 12, length: 1},
Expand All @@ -515,6 +525,7 @@ describe('inline image', () => {

test('image without alt text', () => {
expect('!(https://example.com/image.png)').toBeParsedAs([
{type: 'inline-image', start: 0, length: 32},
{type: 'syntax', start: 0, length: 1},
{type: 'syntax', start: 1, length: 1},
{type: 'link', start: 2, length: 29},
Expand All @@ -526,6 +537,7 @@ describe('inline image', () => {
expect('# ![](example.com)').toBeParsedAs([
{type: 'syntax', start: 0, length: 2},
{type: 'h1', start: 2, length: 16},
{type: 'inline-image', start: 2, length: 16},
{type: 'syntax', start: 2, length: 1},
{type: 'syntax', start: 3, length: 1},
{type: 'syntax', start: 4, length: 1},
Expand Down

0 comments on commit 1992975

Please sign in to comment.