2019-11-23 18:59:55 +00:00
|
|
|
import MessageFormatter from '../MessageFormatter';
|
|
|
|
|
|
|
|
describe('#MessageFormatter', () => {
|
|
|
|
describe('content with links', () => {
|
|
|
|
it('should format correctly', () => {
|
|
|
|
const message =
|
2021-01-15 09:10:50 +00:00
|
|
|
'Chatwoot is an opensource tool. [Chatwoot](https://www.chatwoot.com)';
|
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(
|
2022-03-14 12:43:21 +00:00
|
|
|
'<p>Chatwoot is an opensource tool. <a title="" class="link" href="https://www.chatwoot.com" rel="noreferrer noopener nofollow" target="_blank">Chatwoot</a></p>'
|
2021-01-15 09:10:50 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should format correctly', () => {
|
|
|
|
const message =
|
|
|
|
'Chatwoot is an opensource tool. https://www.chatwoot.com';
|
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(
|
2022-03-14 12:43:21 +00:00
|
|
|
'<p>Chatwoot is an opensource tool. <a title="" class="link" href="https://www.chatwoot.com" rel="noreferrer noopener nofollow" target="_blank">https://www.chatwoot.com</a></p>'
|
2021-01-15 09:10:50 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parses heading to strong', () => {
|
|
|
|
it('should format correctly', () => {
|
|
|
|
const message = '### opensource \n ## tool';
|
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(
|
|
|
|
'<strong>opensource</strong><strong>tool</strong>'
|
2019-11-23 18:59:55 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-08-11 04:27:42 +00:00
|
|
|
|
|
|
|
describe('tweets', () => {
|
|
|
|
it('should return the same string if not tags or @mentions', () => {
|
|
|
|
const message = 'Chatwoot is an opensource tool';
|
2021-01-15 09:10:50 +00:00
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(message);
|
2020-08-11 04:27:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add links to @mentions', () => {
|
|
|
|
const message =
|
|
|
|
'@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername';
|
2022-03-31 14:52:52 +00:00
|
|
|
expect(
|
|
|
|
new MessageFormatter(message, true, false).formattedMessage
|
|
|
|
).toMatch(
|
2021-01-15 09:10:50 +00:00
|
|
|
'<p><a href="http://twitter.com/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">@chatwootapp</a> is an opensource tool thanks @longnonexistenttwitterusername</p>'
|
2020-08-11 04:27:42 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add links to #tags', () => {
|
|
|
|
const message = '#chatwootapp is an opensource tool';
|
2022-03-31 14:52:52 +00:00
|
|
|
expect(
|
|
|
|
new MessageFormatter(message, true, false).formattedMessage
|
|
|
|
).toMatch(
|
2021-01-15 09:10:50 +00:00
|
|
|
'<p><a href="https://twitter.com/hashtag/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">#chatwootapp</a> is an opensource tool</p>'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-31 14:52:52 +00:00
|
|
|
describe('private notes', () => {
|
|
|
|
it('should return the same string if not tags or @mentions', () => {
|
|
|
|
const message = 'Chatwoot is an opensource tool';
|
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add links to @mentions', () => {
|
|
|
|
const message =
|
|
|
|
'@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername';
|
|
|
|
expect(
|
|
|
|
new MessageFormatter(message, false, true).formattedMessage
|
|
|
|
).toMatch(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add links to #tags', () => {
|
|
|
|
const message = '#chatwootapp is an opensource tool';
|
|
|
|
expect(
|
|
|
|
new MessageFormatter(message, false, true).formattedMessage
|
|
|
|
).toMatch(message);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-15 09:10:50 +00:00
|
|
|
describe('plain text content', () => {
|
|
|
|
it('returns the plain text without HTML', () => {
|
|
|
|
const message =
|
|
|
|
'<b>Chatwoot is an opensource tool. https://www.chatwoot.com</b>';
|
|
|
|
expect(new MessageFormatter(message).plainText).toMatch(
|
|
|
|
'Chatwoot is an opensource tool. https://www.chatwoot.com'
|
2020-08-11 04:27:42 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-03-14 12:43:21 +00:00
|
|
|
|
|
|
|
describe('#sanitize', () => {
|
|
|
|
it('sanitizes markup and removes all unnecessary elements', () => {
|
|
|
|
const message =
|
|
|
|
'[xssLink](javascript:alert(document.cookie))\n[normalLink](https://google.com)**I am a bold text paragraph**';
|
|
|
|
expect(new MessageFormatter(message).formattedMessage).toMatch(
|
|
|
|
'<p><a title="" class="link" rel="noreferrer noopener nofollow" target="_blank">xssLink</a><br><a title="" class="link" href="https://google.com" rel="noreferrer noopener nofollow" target="_blank">normalLink</a><strong>I am a bold text paragraph</strong></p>'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-11-23 18:59:55 +00:00
|
|
|
});
|