function descriptionText (description) { // preserve the line breaks when converting to text const html = cheerio.load('<div>' + description.replace(/<br>/g, '\r\n') + '</div>'); return cheerio.text(html('div')); }
describe('Markdown inline', () => { const expectSnapshotToMatch = markdown => { const actual = render(<Markdown text={markdown} inline />); expect(html(actual)).toMatchSnapshot(); }; it('should render text in a span', () => { expectSnapshotToMatch('Hello world!'); }); });
describe('Heading', () => { it('should render a heading according to the level', () => { let actual = shallow(<Heading level={3}>The heading</Heading>); expect(actual.dive().name()).toBe('h3'); actual = shallow(<Heading level={5}>The heading</Heading>); expect(actual.dive().name()).toBe('h5'); }); it('should render a heading', () => { const actual = render(<Heading level={2}>The heading</Heading>); expect(html(actual)).toMatchSnapshot(); }); });
describe('Markdown Heading', () => { it('should render a heading with a wrapper that provides margin', () => { const actual = render(<MarkdownHeading level={2}>The markdown heading</MarkdownHeading>); expect(html(actual)).toMatchSnapshot(); }); });
function convertHtmlToJson(htmlString) { const html = cheerio.load(htmlString); const elemArray = []; html("ul.linha_status").each((_, elem) => { elemArray.push(elem); }); const elemMap = elemArray.map((elem) => { const mapObj = {}; html(elem) .find("li") .each((_, liElem) => { const text = html(liElem).text(); if (text) { if (text.includes("Status")) mapObj.status = formatStatus(text); if (text.includes("Data")) { const dateTime = formatDateTime(text); mapObj.data = dateTime[0]; mapObj.hora = dateTime[1]; } if (text.includes("Local")) mapObj.local = formatLocal(text); if (text.includes("Origem")) mapObj.origem = formatOrigin(text); if (text.includes("Destino")) mapObj.destino = formatDestiny(text); } }); return mapObj; }); return elemMap.reverse(); }
const actual = render(<Markdown text={markdown} />); expect(html(actual)).toMatchSnapshot(); };