import { getPostBodySummary } from './post-body-summary' describe('postBodySummary', () => { it('1- Should return empty string', () => { const input = { author: 'foo81', permlink: 'bar81', last_update: '2019-05-10T09:15:21', body: '' } const expected = '' expect(getPostBodySummary(input)).toBe(expected) }) it('2- Should remove html tags', () => { const input = { author: 'foo82', permlink: 'bar82', last_update: '2019-05-10T09:15:21', body: '
Lorem Ipsum Dolor
' } const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('3- Should remove new lines', () => { const input = { author: 'foo83', permlink: 'bar83', last_update: '2019-05-10T09:15:21', body: 'Lorem \n Ipsum \n Dolor' } const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('4- Should trim', () => { const input = { author: 'foo84', permlink: 'bar84', last_update: '2019-05-10T09:15:21', body: ' Lorem Ipsum Dolor ' } const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('5- Should remove urls', () => { const input = { author: 'foo85', permlink: 'bar85', last_update: '2019-05-10T09:15:21', body: 'Lorem http://lorem.com Ipsum Dolor https://ipsum.com' } const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('6- Should remove white spaces between words', () => { const input = { author: 'foo86', permlink: 'bar86', last_update: '2019-05-10T09:15:21', body: ' Lorem Ipsum Dolor ' } const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('7- Should limit to 20', () => { const input = { author: 'foo87', permlink: 'bar87', last_update: '2019-05-10T09:15:21', body: 'lorem ipsum dolor sit amet' } const expected = 'lorem ipsum dolor sit' expect(getPostBodySummary(input, 20)).toBe(expected) }) it('8- Test with long markdown', () => { const input = { author: 'foo88', permlink: 'bar88', last_update: '2019-05-10T09:15:21', body: `https://youtu.be/DII2VTXDP7A In this post, we want to bring you up to speed on what is happening inside Steemit, as well as give you our perspective on the successes (and failures) of the past year, let you know what we see as our mission going forward, and provide some insight into what we have planned.

Steemit’s Vision and Mission

Through our vision of **empowering entrepreneurs to tokenize the internet**, our primary roles in the Steem ecosystem are providing the community with software enhancements to the Steem blockchain, modular framework applications made up of components that can be leveraged by application developers and inspiration through these platforms to entrepreneurial end-users. We believe we must build in ways that create as many opportunities — and catalyze as many amazing Steem-based entrepreneurs and communities — as possible.` } const expected = 'In this post, we want to bring you up to speed on what is happening inside Steemit, as well as give you our perspective on the successes (and failures) of the past year, let you know what we see as our' expect(getPostBodySummary(input, 200)).toBe(expected) }) it('9- Test with long markdown', () => { const input = { author: 'foo89', permlink: 'bar89', last_update: '2019-05-10T09:15:21', body: `

Everybody has a dream. Most of the time it takes us a while to turn these great wishes into reality, especially because they usually come with a bigger price tag.

Now thanks to Steem some of us will be able to cut corners in order to achieve their goals more quickly. The additional income can be a game changer to many players.

My Steem earnings enabled me to buy a piece of land where I'll build my first own house. Writing down these words still seems a bit unreal to me, since I didn't believe to come to that point so quickly.

Click on the above image or HERE ▶️ to watch my video statement.

Without hard work and dedication as well as the great support from the community this wouldn't have been possible. Also the timing was brilliant, I joined in the earlier stages.

I'm both grateful and proud.

Many people supported me along the way, some tried to tear me down. I'm glad I only stayed with those who pushed me, they have a large stake in my success story.

` } const expected = 'Everybody has a dream. Most of the time it takes us a while to turn these great wishes into reality, especially because they usually come with a bigger price tag. Now thanks to Steem some of us will be' expect(getPostBodySummary(input, 200)).toBe(expected) }) it('10- Test with long markdown', () => { const input = { author: 'foo90', permlink: 'bar90', last_update: '2019-05-10T09:15:21', body: `

![DTUBE.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519196266/ebleqjokesumzw3mwpcz.jpg) ###### Hey Dtube! ###### Hey Steemian ###### It's your boy marpe @marpemusic. I greet you from my stable, Ibadan Nigeria. **There's excitement in the air! The epoch making STEEMIB (that is, STEEMIT IBADAN) meet up is around the corner!! Where would you rather be on the 24th of February 2018? You don't want to miss this peeps.** ![meet up.jpeg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519196411/ihzgikihusxnazqpzltr.jpg) ### Boooommm!!! I'm giving Three DTUBE & STEEMIT BRANDED TEES to three people for free. Yes, for free. *E fit be you ooo!* So, how can you qualify to get one?` } const expected = 'Hey Dtube! Hey Steemian It\'s your boy marpe @marpemusic. I greet you from my stable, Ibadan Nigeria. There\'s excitement in the air! The epoch making STEEMIB (that is, STEEMIT IBADAN) meet up is around' expect(getPostBodySummary(input, 200)).toBe(expected) }) it('11- Test with not obj param', () => { const input = '
Lorem Ipsum Dolor
' const expected = 'Lorem Ipsum Dolor' expect(getPostBodySummary(input)).toBe(expected) }) it('12- Test entity parsing', () => { const input = 'http://lorem.com Lorem < Ipsum & Dolor € ' const expected = 'Lorem < Ipsum & Dolor €' expect(getPostBodySummary(input)).toBe(expected) }) })