import React from 'react'; import { render } from '@testing-library/react-native'; import { Provider } from 'react-redux'; import { combineReducers, createStore } from 'redux'; import Markdown, { IMarkdownProps, markdownTestID } from './index'; import { IEmoji, TGetCustomEmoji } from '../../definitions'; const getCustomEmoji: TGetCustomEmoji = content => ({ marioparty: { name: content, extension: 'gif' }, react_rocket: { name: content, extension: 'png' }, nyan_rocket: { name: content, extension: 'png' } }[content] as IEmoji); const Render = ({ msg, baseUrl, getCustomEmoji, mentions, username }: IMarkdownProps) => { const reducers = combineReducers({ app: () => ({ isMasterDetail: false }) }); const store = createStore(reducers); return ( ); }; describe('Markdown', () => { test('should render header', () => { const header1 = render(); const header2 = render(); const header3 = render(); const header4 = render(); const header5 = render(); const header6 = render(); expect(header1.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); expect(header2.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); expect(header3.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); expect(header4.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); expect(header5.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); expect(header6.findByTestId(`${markdownTestID}-header`)).toBeTruthy(); }); test('should render code in line', async () => { const { findByTestId } = render(); const component = await findByTestId(`${markdownTestID}-code-in-line`); expect(component).toBeTruthy(); }); test('should render code block', async () => { const { findByTestId } = render( ); const component = await findByTestId(`${markdownTestID}-code-block`); expect(component).toBeTruthy(); }); test('should render image', async () => { const { findByTestId } = render(); const component = await findByTestId(`${markdownTestID}-image`); expect(component).toBeTruthy(); }); test('should render link', () => { const markdownLink = render(); const link = render(); expect(markdownLink.findByTestId(`${markdownTestID}-link`)).toBeTruthy(); expect(link.findByTestId(`${markdownTestID}-link`)).toBeTruthy(); }); test('should render block quote', async () => { const { findByTestId } = render( This is block quote this is a normal line`} /> ); const component = await findByTestId(`${markdownTestID}-block-quote`); expect(component).toBeTruthy(); }); test('should render list', () => { const markdownList = render(); const markdownNumberList = render(); expect(markdownList.findByTestId(`${markdownTestID}-list`)).toBeTruthy(); expect(markdownNumberList.findByTestId(`${markdownTestID}-list`)).toBeTruthy(); }); test('should render emojis', () => { const markdownCustomEmoji = render( ); const markdownUnicodeEmoji = render(); expect(markdownCustomEmoji.findByTestId(`${markdownTestID}-custom-emoji`)).toBeTruthy(); expect(markdownUnicodeEmoji.findByTestId(`${markdownTestID}-unicode-emoji`)).toBeTruthy(); }); test('should render hashtags', () => { const markdownHashtagChannels = render(); const markdownHashtagWithoutChannels = render(); expect(markdownHashtagChannels.findByTestId(`${markdownTestID}-hashtag-channels`)).toBeTruthy(); expect(markdownHashtagWithoutChannels.findByTestId(`${markdownTestID}-hashtag-without-channels`)).toBeTruthy(); }); test('should render mentions', async () => { const markdownMentionsAllAndHere = render(); const markdownMentionsUnknown = render(); const markdownMentionsUsers = render( ); expect(await markdownMentionsAllAndHere.findAllByTestId(`${markdownTestID}-mention-all-here`)).toBeTruthy(); expect(await markdownMentionsUnknown.findByTestId(`${markdownTestID}-mention-unknown`)).toBeTruthy(); expect(await markdownMentionsUsers.findByTestId(`${markdownTestID}-mention-users`)).toBeTruthy(); }); test('should render table', async () => { const { findByTestId } = render( ); const component = await findByTestId(`${markdownTestID}-table`); expect(component).toBeTruthy(); }); });