|
| 1 | +import React from 'react'; |
| 2 | +import renderer from 'react-test-renderer'; |
| 3 | +import { renderText } from '../utils'; |
| 4 | + |
| 5 | +describe(`renderText`, () => { |
| 6 | + it('handles the special case where user name matches to an e-mail pattern - 1', () => { |
| 7 | + const Markdown = renderText( |
| 8 | + 'Hello @username@email.com, is username@email.com your @primary e-mail?', |
| 9 | + [{ id: 'id-username@email.com', name: 'username@email.com' }], |
| 10 | + ); |
| 11 | + const tree = renderer.create(Markdown).toJSON(); |
| 12 | + expect(tree).toMatchSnapshot(); |
| 13 | + }); |
| 14 | + |
| 15 | + it('handles the special case where user name matches to an e-mail pattern - 2', () => { |
| 16 | + const Markdown = renderText( |
| 17 | + 'username@email.com @username@email.com is this the right address?', |
| 18 | + [{ id: 'id-username@email.com', name: 'username@email.com' }], |
| 19 | + ); |
| 20 | + const tree = renderer.create(Markdown).toJSON(); |
| 21 | + expect(tree).toMatchSnapshot(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('handles the special case where user name matches to an e-mail pattern - 3', () => { |
| 25 | + const Markdown = renderText( |
| 26 | + '@username@email.com @username@email.com @username@email.com @username@email.com', |
| 27 | + [{ id: 'id-username@email.com', name: 'username@email.com' }], |
| 28 | + ); |
| 29 | + const tree = renderer.create(Markdown).toJSON(); |
| 30 | + expect(tree).toMatchSnapshot(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('handles the special case where user name matches to an e-mail pattern - 4', () => { |
| 34 | + const Markdown = renderText( |
| 35 | + '@username@email.com @username@email.com username@email.com @username@email.com', |
| 36 | + [{ id: 'id-username@email.com', name: 'username@email.com' }], |
| 37 | + ); |
| 38 | + const tree = renderer.create(Markdown).toJSON(); |
| 39 | + expect(tree).toMatchSnapshot(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('renders custom mention', () => { |
| 43 | + const Markdown = renderText( |
| 44 | + '@username@email.com @username@email.com username@email.com @username@email.com', |
| 45 | + [{ id: 'id-username@email.com', name: 'username@email.com' }], |
| 46 | + { |
| 47 | + customMarkDownRenderers: { |
| 48 | + mention: function MyMention(props) { |
| 49 | + return <span className='my-mention'>{props.children}</span>; |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + ); |
| 54 | + const tree = renderer.create(Markdown).toJSON(); |
| 55 | + expect(tree).toMatchSnapshot(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('renders standard markdown text', () => { |
| 59 | + const Markdown = renderText('Hi, shall we meet on **Tuesday**?', []); |
| 60 | + const tree = renderer.create(Markdown).toJSON(); |
| 61 | + expect(tree).toMatchSnapshot(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments