From cc00af7a3102034b05ebcd4aa1fd01c6f467184a Mon Sep 17 00:00:00 2001
From: Henry Jameson 3 4 7
2
8
\n
'
+ const result = convertHtmlToLines(inputOutput)
+ const comparableResult = result.map(mapOnlyText(processorKeep)).join('')
+ expect(comparableResult).to.eql(inputOutput)
+ })
+
+ it('fed with possibly broken HTML with invalid tags/composition', () => {
+ const inputOutput = '
' + const result = convertHtmlToLines(inputOutput) + const comparableResult = result.map(mapOnlyText(processorKeep)).join('') + expect(comparableResult).to.eql(inputOutput) + }) + + it('fed with sorta valid HTML but tags aren\'t closed', () => { + const inputOutput = 'just leaving a
p \nwithin
p!
and a3 4
5 \n 6 7
8
_
_\n__
_
' + const output = '
_' + const result = convertHtmlToLines(input) + const comparableResult = result.map(mapOnlyText(processorReplace)).join('') + expect(comparableResult).to.eql(output) + }) + + it('fed with sorta valid HTML but tags aren\'t closed', () => { + const input = 'just leaving a
p \nwithin
p!
and a_\n_
_
_2
3', + ['2'], + '
' + ], + ' ', + [ + '', + [ + '3', + ['2
3', + ['2'], + '
' + ], + [ + '', + [ + '3', + [' 42'
+ expect(convertHtmlToTree(input)).to.eql([
+ '1 ',
+ ['
'],
+ ' 2 ',
+ [
+ '
', + [' 42'] + ] + ]) + }) + it('realistic case 1', () => { + const input = '
' + expect(convertHtmlToTree(input)).to.eql([ + [ + '', + [ + [ + '', + [ + [ + '', + [ + '@', + [ + '', + [ + 'benis' + ], + '' + ] + ], + '' + ] + ], + '' + ], + ' ', + [ + '', + [ + [ + '', + [ + '@', + [ + '', + [ + 'hj' + ], + '' + ] + ], + '' + ] + ], + '' + ], + ' nice' + ], + '
' + ] + ]) + }) + it('realistic case 2', () => { + const inputOutput = 'Country improv: give me a city> rei = "0"
+ '0'
+ > rei == 0
+ true
+ > rei == null
+ falseThat, christian-like JS diagram but it’s evangelion instead.+ ` + const result = convertHtmlToLines(input) + const comparableResult = result.map(mapOnlyText(processorReplace)).join('') + expect(comparableResult).to.eql(input) + }) + it('Testing handling ignored blocks 2', () => { + const input = ` +
An SSL error has happened.
Shakespeare
+ ` + const output = ` +An SSL error has happened.
_
+ ` + const result = convertHtmlToLines(input) + const comparableResult = result.map(mapOnlyText(processorReplace)).join('') + expect(comparableResult).to.eql(output) + }) }) }) -- cgit v1.2.3-70-g09d2 From cd4455675024a3dfc8930184114d5f92438d0466 Mon Sep 17 00:00:00 2001 From: Henry Jameson${data.join('')}
` +const compwrap = (...data) => `${data.join('')}` +const removedMentionSpan = '' + +describe('RichContent', () => { + it('renders simple post without exploding', () => { + const html = p('Hello world!') + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(html)) + }) + + it('removes mentions from the beginning of post', () => { + const html = p( + makeMention('John'), + ' how are you doing thoday?' + ) + const expected = p( + removedMentionSpan, + 'how are you doing thoday?' + ) + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('removes mentions from the end of the hellpost ()', () => {
+ const html = [
+ p('How are you doing today, fine gentlemen?'),
+ p(
+ makeMention('John'),
+ makeMention('Josh'),
+ makeMention('Jeremy')
+ )
+ ].join('')
+ const expected = [
+ p(
+ 'How are you doing today, fine gentlemen?'
+ ),
+ // TODO fix this extra line somehow?
+ p()
+ ].join('')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('removes mentions from the end of the hellpost (
)', () => {
+ const html = [
+ 'How are you doing today, fine gentlemen?',
+ [
+ makeMention('John'),
+ makeMention('Josh'),
+ makeMention('Jeremy')
+ ].join('')
+ ].join('
')
+ const expected = [
+ 'How are you doing today, fine gentlemen?',
+ // TODO fix this extra line somehow?
+ '
'
+ ].join('')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('removes mentions from the end of the hellpost (\\n)', () => {
+ const html = [
+ 'How are you doing today, fine gentlemen?',
+ [
+ makeMention('John'),
+ makeMention('Josh'),
+ makeMention('Jeremy')
+ ].join('')
+ ].join('\n')
+ const expected = [
+ 'How are you doing today, fine gentlemen?',
+ // TODO fix this extra line somehow?
+ ''
+ ].join('\n')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('Does not remove mentions in the middle or at the end of text string', () => {
+ const html = [
+ [
+ makeMention('Jack'),
+ 'let\'s meet up with ',
+ makeMention('Janet')
+ ].join(''),
+ [
+ 'cc: ',
+ makeMention('John'),
+ makeMention('Josh'),
+ makeMention('Jeremy')
+ ].join('')
+ ].join('\n')
+ const expected = [
+ [
+ removedMentionSpan,
+ 'let\'s meet up with ',
+ stubMention('Janet')
+ ].join(''),
+ [
+ 'cc: ',
+ stubMention('John'),
+ stubMention('Josh'),
+ stubMention('Jeremy')
+ ].join('')
+ ].join('\n')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('removes mentions from the end if there\'s only one first mention', () => {
+ const html = [
+ p(
+ makeMention('Todd'),
+ 'so anyway you are wrong'
+ ),
+ p(
+ makeMention('Tom'),
+ makeMention('Trace'),
+ makeMention('Theodor')
+ )
+ ].join('')
+ const expected = [
+ p(
+ removedMentionSpan,
+ 'so anyway you are wrong'
+ ),
+ // TODO fix this extra line somehow?
+ p()
+ ].join('')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('does not remove mentions from the end if there\'s more than one first mention', () => {
+ const html = [
+ p(
+ makeMention('Zacharie'),
+ makeMention('Zinaide'),
+ 'you guys have cool names, and so do these guys: '
+ ),
+ p(
+ makeMention('Watson'),
+ makeMention('Wallace'),
+ makeMention('Wakamoto')
+ )
+ ].join('')
+ const expected = [
+ p(
+ removedMentionSpan,
+ removedMentionSpan,
+ 'you guys have cool names, and so do these guys: '
+ ),
+ p(
+ lastMentions(
+ stubMention('Watson'),
+ stubMention('Wallace'),
+ stubMention('Wakamoto')
+ )
+ )
+ ].join('')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: true,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('Does not touch links if link handling is disabled', () => {
+ const html = [
+ [
+ makeMention('Jack'),
+ 'let\'s meet up with ',
+ makeMention('Janet')
+ ].join(''),
+ [
+ makeMention('John'),
+ makeMention('Josh'),
+ makeMention('Jeremy')
+ ].join('')
+ ].join('\n')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: false,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(html))
+ })
+
+ it('Adds greentext and cyantext to the post', () => {
+ const html = [
+ '>preordering videogames',
+ '>any year'
+ ].join('\n')
+ const expected = [
+ '>preordering videogames',
+ '>any year'
+ ].join('\n')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: false,
+ greentext: true,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(expected))
+ })
+
+ it('Does not add greentext and cyantext if setting is set to false', () => {
+ const html = [
+ '>preordering videogames',
+ '>any year'
+ ].join('\n')
+
+ const wrapper = shallowMount(RichContent, {
+ localVue,
+ propsData: {
+ handleLinks: false,
+ greentext: false,
+ emoji: [],
+ html
+ }
+ })
+
+ expect(wrapper.html()).to.eql(compwrap(html))
+ })
+
+ it('Adds emoji to post', () => {
+ const html = p('Ebin :DDDD :spurdo:')
+ const expected = p(
+ 'Ebin :DDDD ',
+ '
2
3' - const output = '
_' + const output = '_
' const result = convertHtmlToLines(input) const comparableResult = result.map(mapOnlyText(processorReplace)).join('') expect(comparableResult).to.eql(output) @@ -111,7 +120,7 @@ describe('html_line_converter', () => { expect(comparableResult).to.eql(output) }) - it('fed with maybe valid HTML? self-closing divs and ps', () => { + it('fed with maybe valid HTML? (XHTML) self-closing divs and ps', () => { const input = 'a
what now ?' const output = '___' const result = convertHtmlToLines(input) -- cgit v1.2.3-70-g09d2 From c21b1cf89840297a781e6adc66cc195b8741cac6 Mon Sep 17 00:00:00 2001 From: Henry Jameson