import MessageFormatter from '../MessageFormatter'; describe('#MessageFormatter', () => { describe('content with links', () => { it('should format correctly', () => { const message = 'Chatwoot is an opensource tool. [Chatwoot](https://www.chatwoot.com)'; expect(new MessageFormatter(message).formattedMessage).toMatch( '
Chatwoot is an opensource tool. Chatwoot
' ); }); it('should format correctly', () => { const message = 'Chatwoot is an opensource tool. https://www.chatwoot.com'; expect(new MessageFormatter(message).formattedMessage).toMatch( 'Chatwoot is an opensource tool. https://www.chatwoot.com
' ); }); }); describe('parses heading to strong', () => { it('should format correctly', () => { const message = '### opensource \n ## tool'; expect(new MessageFormatter(message).formattedMessage).toMatch( 'opensourcetool' ); }); }); describe('tweets', () => { 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, true, false).formattedMessage ).toMatch( '@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername
' ); }); it('should add links to #tags', () => { const message = '#chatwootapp is an opensource tool'; expect( new MessageFormatter(message, true, false).formattedMessage ).toMatch( '#chatwootapp is an opensource tool
' ); }); }); 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); }); }); describe('plain text content', () => { it('returns the plain text without HTML', () => { const message = 'Chatwoot is an opensource tool. https://www.chatwoot.com'; expect(new MessageFormatter(message).plainText).toMatch( 'Chatwoot is an opensource tool. https://www.chatwoot.com' ); }); }); 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( 'xssLink
normalLinkI am a bold text paragraph