diff options
Diffstat (limited to 'test/unit/specs/components/rich_content.spec.js')
| -rw-r--r-- | test/unit/specs/components/rich_content.spec.js | 272 |
1 files changed, 270 insertions, 2 deletions
diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index 835fbea2..96c480ea 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -1,4 +1,4 @@ -import { shallowMount, createLocalVue } from '@vue/test-utils' +import { mount, shallowMount, createLocalVue } from '@vue/test-utils' import RichContent from 'src/components/rich_content/rich_content.jsx' const localVue = createLocalVue() @@ -16,6 +16,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -38,6 +39,34 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('replaces first mention with mentionsline if hideMentions=false', () => { + const html = p( + makeMention('John'), + ' how are you doing thoday?' + ) + const expected = p( + '<span class="h-card">', + '<mentionsline-stub mentions="', + '[object Object]', + '"></mentionsline-stub>', + '</span>', + 'how are you doing thoday?' + ) + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: false, handleLinks: true, greentext: true, emoji: [], @@ -68,6 +97,44 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('replaces mentions at the end of the hellpost if hideMentions=false (<p>)', () => { + 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( + '<mentionsline-stub mentions="', + '[object Object],', + '[object Object],', + '[object Object]', + '"></mentionsline-stub>' + ) + ].join('') + + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: false, handleLinks: true, greentext: true, emoji: [], @@ -96,6 +163,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -124,6 +192,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -165,6 +234,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -199,6 +269,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -240,6 +311,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -267,6 +339,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: false, greentext: true, emoji: [], @@ -290,6 +363,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: false, greentext: true, emoji: [], @@ -309,6 +383,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: false, greentext: false, emoji: [], @@ -329,6 +404,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: false, greentext: false, emoji: [{ url: 'about:blank', shortcode: 'spurdo' }], @@ -345,6 +421,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: false, greentext: false, emoji: [], @@ -407,6 +484,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -425,10 +503,18 @@ describe('RichContent', () => { makeMention('bar'), makeMention('baz') ].join('<br>') + const expected = [ + 'Bruh', + 'Bruh', + stubMention('foo'), + stubMention('bar'), + stubMention('baz') + ].join('<br>') const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -436,7 +522,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(html)) + expect(wrapper.html()).to.eql(compwrap(expected)) }) it('Don\'t remove last mentions if there are more than one first mention - remove first instead', () => { @@ -471,6 +557,7 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, handleLinks: true, greentext: true, emoji: [], @@ -506,6 +593,187 @@ describe('RichContent', () => { const wrapper = shallowMount(RichContent, { localVue, propsData: { + hideMentions: true, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('buggy example/hashtags', () => { + const html = [ + '<p>', + '<a href="http://macrochan.org/images/N/H/NHCMDUXJPPZ6M3Z2CQ6D2EBRSWGE7MZY.jpg">', + 'NHCMDUXJPPZ6M3Z2CQ6D2EBRSWGE7MZY.jpg</a>', + ' <a class="hashtag" data-tag="nou" href="https://shitposter.club/tag/nou">', + '#nou</a>', + ' <a class="hashtag" data-tag="screencap" href="https://shitposter.club/tag/screencap">', + '#screencap</a>', + ' </p>' + ].join('') + const expected = [ + '<p>', + '<a href="http://macrochan.org/images/N/H/NHCMDUXJPPZ6M3Z2CQ6D2EBRSWGE7MZY.jpg" target="_blank">', + 'NHCMDUXJPPZ6M3Z2CQ6D2EBRSWGE7MZY.jpg</a>', + ' <a class="hashtag" data-tag="nou" href="https://shitposter.club/tag/nou" target="_blank">', + '#nou</a>', + ' <a class="hashtag" data-tag="screencap" href="https://shitposter.club/tag/screencap" target="_blank">', + '#screencap</a>', + ' </p>' + ].join('') + + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: true, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('rich contents of a mention are handled properly', () => { + const html = [ + p( + 'Testing' + ), + p( + '<a href="lol" class="mention">', + '<span>', + 'https://</span>', + '<span>', + 'lol.tld/</span>', + '<span>', + '</span>', + '</a>' + ) + ].join('') + const expected = [ + p( + 'Testing' + ), + p( + '<mentionlink-stub url="lol" content="', + '<span>', + 'https://</span>', + '<span>', + 'lol.tld/</span>', + '<span>', + '</span>', + '">', + '</mentionlink-stub>' + ) + ].join('') + + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: false, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('rich contents of a mention in beginning are handled properly', () => { + const html = [ + p( + '<a href="lol" class="mention">', + '<span>', + 'https://</span>', + '<span>', + 'lol.tld/</span>', + '<span>', + '</span>', + '</a>' + ), + p( + 'Testing' + ) + ].join('') + const expected = [ + p( + '<span class="MentionsLine">', + '<mentionlink-stub content="', + '<span>', + 'https://</span>', + '<span>', + 'lol.tld/</span>', + '<span>', + '</span>', + '" url="lol" class="mention-link">', + '</mentionlink-stub>', + '<!---->', // v-if placeholder + '</span>' + ), + p( + 'Testing' + ) + ].join('') + + const wrapper = mount(RichContent, { + localVue, + stubs: { + MentionLink: true + }, + propsData: { + hideMentions: false, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + + it('rich contents of a link are handled properly', () => { + const html = [ + '<p>', + 'Freenode is dead.</p>', + '<p>', + '<a href="https://isfreenodedeadyet.com/">', + '<span>', + 'https://</span>', + '<span>', + 'isfreenodedeadyet.com/</span>', + '<span>', + '</span>', + '</a>', + '</p>' + ].join('') + const expected = [ + '<p>', + 'Freenode is dead.</p>', + '<p>', + '<a href="https://isfreenodedeadyet.com/" target="_blank">', + '<span>', + 'https://</span>', + '<span>', + 'isfreenodedeadyet.com/</span>', + '<span>', + '</span>', + '</a>', + '</p>' + ].join('') + + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: false, handleLinks: true, greentext: true, emoji: [], |
