From 5e23d803014a0634ea61825935ffeda244a5a0a6 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 12 Aug 2021 19:37:04 +0300 Subject: [PATCH] fix tests, add performance test (skipped, doesn't assert anything), tweak max mentions count --- src/components/mention_link/mention_link.js | 2 +- src/components/mentions_line/mentions_line.js | 2 +- src/components/rich_content/rich_content.jsx | 2 +- .../specs/components/rich_content.spec.js | 126 ++++++++++-------- 4 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index a60a8040..4d27fe6d 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -41,7 +41,7 @@ const MentionLink = { }, computed: { user () { - return this.url && this.$store.getters.findUserByUrl(this.url) + return this.url && this.$store && this.$store.getters.findUserByUrl(this.url) }, isYou () { // FIXME why user !== currentUser??? diff --git a/src/components/mentions_line/mentions_line.js b/src/components/mentions_line/mentions_line.js index 33e25391..83eeea4c 100644 --- a/src/components/mentions_line/mentions_line.js +++ b/src/components/mentions_line/mentions_line.js @@ -15,7 +15,7 @@ const MentionsLine = { }, computed: { limit () { - return 2 + return 5 }, mentionsComputed () { return this.mentions.slice(0, this.limit) diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 4b7d4d37..32b737ec 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -159,7 +159,7 @@ export default Vue.component('RichContent', { return item // We'll handle it later } case 'span': - if (attrs['class'].includes('h-card')) { + if (this.handleLinks && attrs['class'] && attrs['class'].includes('h-card')) { return ['', children.map(processItem), ''] } } diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index dfc229c0..b29edeab 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -56,7 +56,7 @@ describe('RichContent', () => { expect(wrapper.html()).to.eql(compwrap(expected)) }) - it('replaces first mention with mentionsline', () => { + it('replaces mention with mentionsline', () => { const html = p( makeMention('John'), ' how are you doing today?' @@ -234,7 +234,7 @@ describe('RichContent', () => { ].join('\n') const expected = [ '>quote', - mentionsLine(1) + mentionsLine(1), '>quote', '>quote' ].join('\n') @@ -267,7 +267,7 @@ describe('RichContent', () => { const expected = [ 'Bruh', 'Bruh', - mentionsLine(3) + mentionsLine(3), 'Bruh' ].join('
') @@ -322,53 +322,6 @@ describe('RichContent', () => { }) it('rich contents of a mention are handled properly', () => { - const html = [ - p( - 'Testing' - ), - p( - '', - '', - 'https://', - '', - 'lol.tld/', - '', - '', - '' - ) - ].join('') - const expected = [ - p( - 'Testing' - ), - p( - '', - '' - ) - ].join('') - - const wrapper = shallowMount(RichContent, { - localVue, - propsData: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html - } - }) - - expect(wrapper.html()).to.eql(compwrap(expected)) - }) - - it('rich contents of a mention in beginning are handled properly', () => { attentions.push({ statusnet_profile_url: 'lol' }) const html = [ p( @@ -388,16 +341,19 @@ describe('RichContent', () => { const expected = [ p( '', - '', + '', '', 'https://', '', 'lol.tld/', '', '', - '" url="lol" class="mention-link">', - '', - '', // v-if placeholder + '', + ' ', + '', // v-if placeholder, mentionlink's "new" (i.e. rich) display + '', + '', // v-if placeholder, mentionsline's extra mentions and stuff '' ), p( @@ -407,9 +363,6 @@ describe('RichContent', () => { const wrapper = mount(RichContent, { localVue, - stubs: { - MentionLink: true - }, propsData: { attentions, handleLinks: true, @@ -465,4 +418,63 @@ describe('RichContent', () => { expect(wrapper.html()).to.eql(compwrap(expected)) }) + + it.skip('[INFORMATIVE] Performance testing, 10 000 simple posts', () => { + const amount = 20 + + const onePost = p( + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + makeMention('Lain'), + ' i just landed in l a where are you' + ) + + const TestComponent = { + template: ` +
+ ${new Array(amount).fill(``)} +
+
+ ${new Array(amount).fill(`
`)} +
+ `, + props: ['handleLinks', 'attentions', 'vhtml'] + } + console.log(1) + + const ptest = (handleLinks, vhtml) => { + const t0 = performance.now() + + const wrapper = mount(TestComponent, { + localVue, + propsData: { + attentions, + handleLinks, + vhtml + } + }) + + const t1 = performance.now() + + wrapper.destroy() + + const t2 = performance.now() + + return `Mount: ${t1 - t0}ms, destroy: ${t2 - t1}ms, avg ${(t1 - t0) / amount}ms - ${(t2 - t1) / amount}ms per item` + } + + console.log(`${amount} items with links handling:`) + console.log(ptest(true)) + console.log(`${amount} items without links handling:`) + console.log(ptest(false)) + console.log(`${amount} items plain v-html:`) + console.log(ptest(false, true)) + }) })