Skip to content

Commit

Permalink
Add newline to end of XML serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed May 3, 2024
1 parent 8d1aad1 commit e8eaafb
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

await pageConditions.numActivitiesShown(1);

expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!');
expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!\n');

const pushButton1 = document.querySelector('.ac-pushButton');

Expand All @@ -53,7 +53,7 @@
type: 'message'
});

expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!');
expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!\n');

const pushButton2 = document.querySelector('.ac-pushButton');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

await pageConditions.numActivitiesShown(1);

expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!');
expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!\n');

const textInput1 = document.querySelector('.ac-textInput');

Expand All @@ -62,7 +62,7 @@
type: 'message'
});

expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!');
expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!\n');

const textInput2 = document.querySelector('.ac-textInput');

Expand Down
36 changes: 18 additions & 18 deletions packages/bundle/src/__tests__/renderMarkdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,82 @@ describe('renderMarkdown', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown('Same line.\nSame line. \n2nd line.', styleOptions)).toBe(
'<p>Same line.\nSame line.<br />\n2nd line.</p>'
'<p>Same line.\nSame line.<br />\n2nd line.</p>\n'
);
});

it('should respect CRLF', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown('Same Line.\n\rSame Line.\r\n2nd line.', styleOptions)).toBe(
'<p>Same Line.\nSame Line.</p>\n<p>2nd line.</p>'
'<p>Same Line.\nSame Line.</p>\n<p>2nd line.</p>\n'
);
});

it('should respect LFCR', () => {
const styleOptions = { markdownRespectCRLF: false };

expect(renderMarkdown('Same Line.\r\nSame Line.\n\r2nd line.', styleOptions)).toBe(
'<p>Same Line.\nSame Line.</p>\n<p>2nd line.</p>'
'<p>Same Line.\nSame Line.</p>\n<p>2nd line.</p>\n'
);
});

it('should render bold text', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown('**Message with Markdown**\r\nShould see bold text.', styleOptions)).toBe(
'<p><strong>Message with Markdown</strong></p>\n<p>Should see bold text.</p>'
'<p><strong>Message with Markdown</strong></p>\n<p>Should see bold text.</p>\n'
);
});

it('should render code correctly', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown(`\`\`\`\n${JSON.stringify({ hello: 'World!' }, null, 2)}\n\`\`\``, styleOptions)).toBe(
'<pre><code>{\n "hello": "World!"\n}\n</code></pre>'
'<pre><code>{\n "hello": "World!"\n}\n</code></pre>\n'
);
});

it('should render aria-labels', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(
renderMarkdown('[example](https://sample.com){aria-label="Sample label"}', styleOptions)
).toMatchInlineSnapshot(
`"<p>\u200B<a href=\\"https://sample.com\\" aria-label=\\"Sample label\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\">example<img src=\\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\\" alt class=\\"webchat__render-markdown__external-link-icon\\" /></a>\u200B</p>"`
);
expect(renderMarkdown('[example](https://sample.com){aria-label="Sample label"}', styleOptions))
.toMatchInlineSnapshot(`
"<p>\u200B<a href=\\"https://sample.com\\" aria-label=\\"Sample label\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\">example<img src=\\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\\" alt class=\\"webchat__render-markdown__external-link-icon\\" /></a>\u200B</p>
"
`);
});

it('should render "open in new window" icon', () => {
const styleOptions = { markdownRespectCRLF: true };
const options = { externalLinkAlt: 'Opens in a new window, external.' };

expect(
renderMarkdown('[example](https://sample.com){aria-label="Sample label"}', styleOptions, options)
).toMatchInlineSnapshot(
`"<p>\u200B<a href=\\"https://sample.com\\" aria-label=\\"Sample label\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\">example<img src=\\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\\" alt class=\\"webchat__render-markdown__external-link-icon\\" title=\\"Opens in a new window, external.\\" /></a>\u200B</p>"`
);
expect(renderMarkdown('[example](https://sample.com){aria-label="Sample label"}', styleOptions, options))
.toMatchInlineSnapshot(`
"<p>\u200B<a href=\\"https://sample.com\\" aria-label=\\"Sample label\\" rel=\\"noopener noreferrer\\" target=\\"_blank\\">example<img src=\\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\\" alt class=\\"webchat__render-markdown__external-link-icon\\" title=\\"Opens in a new window, external.\\" /></a>\u200B</p>
"
`);
});

it('should render sip protocol links correctly', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown(`[example@test.com](sip:example@test.com)`, styleOptions)).toBe(
'<p>\u200B<a href="sip:example@test.com" rel="noopener noreferrer" target="_blank">example@test.com</a>\u200B</p>'
'<p>\u200B<a href="sip:example@test.com" rel="noopener noreferrer" target="_blank">example@test.com</a>\u200B</p>\n'
);
});

it('should render tel protocol links correctly', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown(`[(505)503-4455](tel:505-503-4455)`, styleOptions)).toBe(
'<p>\u200B<a href="tel:505-503-4455" rel="noopener noreferrer" target="_blank">(505)503-4455</a>\u200B</p>'
'<p>\u200B<a href="tel:505-503-4455" rel="noopener noreferrer" target="_blank">(505)503-4455</a>\u200B</p>\n'
);
});

it('should render strikethrough text correctly', () => {
const styleOptions = { markdownRespectCRLF: true };

expect(renderMarkdown(`~~strike text~~`, styleOptions)).toBe('<p><s>strike text</s></p>');
expect(renderMarkdown(`~~strike text~~`, styleOptions)).toBe('<p><s>strike text</s></p>\n');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "ariaLabel" option with "Hello, World!"', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" aria-label="Hello, World!">Example</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" aria-label="Hello, World!">Example</a></p>\n'
));

test('should match baseline', () =>
Expand All @@ -48,6 +48,6 @@ describe('When passing "ariaLabel" option with false', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>\n'
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "asButton" option with true', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><button type="button" value="https://example.com">Example</button></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><button type="button" value="https://example.com">Example</button></p>\n'
));

test('should match baseline', () =>
Expand All @@ -45,7 +45,7 @@ describe('When passing "asButton" option with true and "iconClassName" with "my-

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><button type="button" value="https://example.com">Example<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" class="my-icon" /></button></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><button type="button" value="https://example.com">Example<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" class="my-icon" /></button></p>\n'
));

test('should match baseline', () =>
Expand All @@ -71,7 +71,7 @@ describe('When passing "asButton" option with true and "title" with "Hello, Worl

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><button title="Hello, World!" type="button" value="https://example.com">Example</button></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><button title="Hello, World!" type="button" value="https://example.com">Example</button></p>\n'
));

test('should match baseline', () =>
Expand All @@ -97,7 +97,7 @@ describe('When passing "asButton" option with true and "className" with "my-link

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><button class="my-link" type="button" value="https://example.com">Example</button></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><button class="my-link" type="button" value="https://example.com">Example</button></p>\n'
));

test('should match baseline', () =>
Expand All @@ -123,7 +123,7 @@ describe('When passing "asButton" option with true and "aria-label" with "Hello,

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><button aria-label="Hello, World!" type="button" value="https://example.com">Example</button></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><button aria-label="Hello, World!" type="button" value="https://example.com">Example</button></p>\n'
));

test('should match baseline', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "className" option with "my-link"', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" class="my-link">Example</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" class="my-link">Example</a></p>\n'
));

test('should match baseline', () =>
Expand All @@ -48,6 +48,6 @@ describe('When passing "className" option with false', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>\n'
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('When passing "iconAlt" option with "Hello, World!" and "iconClassName"

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com">Example<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" class="my-icon" title="Hello, World!" /></a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com">Example<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" class="my-icon" title="Hello, World!" /></a></p>\n'
));

test('should match baseline', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "rel" option with "noopener noreferer"', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" rel="noopener noreferer">Example</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" rel="noopener noreferer">Example</a></p>\n'
));

test('should match baseline', () =>
Expand All @@ -47,6 +47,6 @@ describe('When passing "rel" option with false', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>\n'
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('When passing "ariaLabel" option with "Hello, World!" for a specific an

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/1" aria-label="Hello, World!">Hello, World!</a></p>\n<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/2">Aloha!</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/1" aria-label="Hello, World!">Hello, World!</a></p>\n<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/2">Aloha!</a></p>\n'
));

test('should match baseline', () =>
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('When passing "ariaLabel" option with "Hello, World!" for a specific an

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/1" aria-label="Hello, World!">Hello, World!</a></p>\n<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/2">Aloha!</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/1" aria-label="Hello, World!">Hello, World!</a></p>\n<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com/2">Aloha!</a></p>\n'
));

test('should match baseline', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "target" option with "noopener noreferer"', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" target="noopener noreferer">Example</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" target="noopener noreferer">Example</a></p>\n'
));

test('should match baseline', () =>
Expand All @@ -48,6 +48,6 @@ describe('When passing "target" option with false', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>\n'
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When passing "title" option with "Hello, World!"', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" title="Hello, World!">Example</a></p>'
'<p xmlns="http://www.w3.org/1999/xhtml"><a href="https://example.com" title="Hello, World!">Example</a></p>\n'
));

test('should match baseline', () =>
Expand All @@ -48,6 +48,6 @@ describe('When passing "title" option with false', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>'
'<a xmlns="http://www.w3.org/1999/xhtml" href="https://example.com">Example</a>\n'
));
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('When passing "wrapZeroWidthSpace" option with true', () => {

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml">\u200b<a href="https://example.com">Example</a>\u200b</p>'
'<p xmlns="http://www.w3.org/1999/xhtml">\u200b<a href="https://example.com">Example</a>\u200b</p>\n'
));

test('should match baseline', () =>
Expand All @@ -39,7 +39,7 @@ describe('When passing "wrapZeroWidthSpace" option with true and "asButton" opti

test('should match snapshot', () =>
expect(serializeDocumentIntoString(actual)).toBe(
'<p xmlns="http://www.w3.org/1999/xhtml">\u200b<button type="button" value="https://example.com">Example</button>\u200b</p>'
'<p xmlns="http://www.w3.org/1999/xhtml">\u200b<button type="button" value="https://example.com">Example</button>\u200b</p>\n'
));

test('should match baseline', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default function serializeDocumentIntoString(document: Document): string
elementHTML.push(serializer.serializeToString(element));
}

return elementHTML.join('\n');
return `${elementHTML.join('\n')}\n`;
}

0 comments on commit e8eaafb

Please sign in to comment.