fix tests

This commit is contained in:
Henry Jameson 2022-11-27 00:11:54 +02:00
parent 7fed35a627
commit 74813864fc
3 changed files with 32 additions and 10 deletions

View File

@ -150,6 +150,7 @@ export default {
if (Array.isArray(item)) { if (Array.isArray(item)) {
const [opener, children, closer] = item const [opener, children, closer] = item
const Tag = getTagName(opener) const Tag = getTagName(opener)
const fullAttrs = getAttrs(opener, () => true)
const attrs = getAttrs(opener) const attrs = getAttrs(opener)
const previouslyMentions = currentMentions !== null const previouslyMentions = currentMentions !== null
/* During grouping of mentions we trim all the empty text elements /* During grouping of mentions we trim all the empty text elements
@ -171,7 +172,7 @@ export default {
return ['', [mentionsLinePadding, renderImage(opener)], ''] return ['', [mentionsLinePadding, renderImage(opener)], '']
case 'a': // replace mentions with MentionLink case 'a': // replace mentions with MentionLink
if (!this.handleLinks) break if (!this.handleLinks) break
if (attrs['class'] && attrs['class'].includes('mention')) { if (fullAttrs.class && fullAttrs.class.includes('mention')) {
// Handling mentions here // Handling mentions here
return renderMention(attrs, children) return renderMention(attrs, children)
} else { } else {
@ -179,7 +180,7 @@ export default {
break break
} }
case 'span': case 'span':
if (this.handleLinks && attrs.class && attrs.class.includes('h-card')) { if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) {
return ['', children.map(processItem), ''] return ['', children.map(processItem), '']
} }
} }
@ -215,11 +216,12 @@ export default {
switch (Tag) { switch (Tag) {
case 'a': { // replace mentions with MentionLink case 'a': { // replace mentions with MentionLink
if (!this.handleLinks) break if (!this.handleLinks) break
const attrs = getAttrs(opener) const fullAttrs = getAttrs(opener, () => true)
const attrs = getAttrs(opener, () => true)
// should only be this // should only be this
if ( if (
(attrs.class && attrs.class.includes('hashtag')) || // Pleroma style (fullAttrs.class && fullAttrs.class.includes('hashtag')) || // Pleroma style
(attrs.rel === 'tag') // Mastodon style (fullAttrs.rel === 'tag') // Mastodon style
) { ) {
return renderHashtag(attrs, children, encounteredTextReverse) return renderHashtag(attrs, children, encounteredTextReverse)
} else { } else {

View File

@ -28,7 +28,14 @@ export const getAttrs = (tag, filter) => {
if (!v) return [k, true] if (!v) return [k, true]
return [k, v.substring(1, v.length - 1)] return [k, v.substring(1, v.length - 1)]
}) })
const defaultFilter = ([k, v]) => (k.toLowerCase() !== 'class' && k.toLowerCase() !== 'style') const defaultFilter = ([k, v]) => {
const attrKey = k.toLowerCase()
if (attrKey === 'style') return false
if (attrKey === 'class') {
return v === 'greentext' || v === 'cyantext'
}
return true
}
return Object.fromEntries(attrs.filter(filter || defaultFilter)) return Object.fromEntries(attrs.filter(filter || defaultFilter))
} }

View File

@ -19,9 +19,11 @@ const global = {
} }
} }
const makeMention = (who) => { const makeMention = (who, noClass) => {
attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` }) attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` })
return `<span class="h-card"><a class="u-url mention" href="https://fake.tld/@${who}">@<span>${who}</span></a></span>` return noClass
? `<span><a href="https://fake.tld/@${who}">@<span>${who}</span></a></span>`
: `<span class="h-card"><a class="u-url mention" href="https://fake.tld/@${who}">@<span>${who}</span></a></span>`
} }
const p = (...data) => `<p>${data.join('')}</p>` const p = (...data) => `<p>${data.join('')}</p>`
const compwrap = (...data) => `<span class="RichContent">${data.join('')}</span>` const compwrap = (...data) => `<span class="RichContent">${data.join('')}</span>`
@ -142,6 +144,17 @@ describe('RichContent', () => {
makeMention('Josh'), makeMention('Jeremy') makeMention('Josh'), makeMention('Jeremy')
].join('') ].join('')
].join('\n') ].join('\n')
const strippedHtml = [
[
makeMention('Jack', true),
'let\'s meet up with ',
makeMention('Janet', true)
].join(''),
[
makeMention('John', true),
makeMention('Josh', true), makeMention('Jeremy', true)
].join('')
].join('\n')
const wrapper = shallowMount(RichContent, { const wrapper = shallowMount(RichContent, {
global, global,
@ -154,7 +167,7 @@ describe('RichContent', () => {
} }
}) })
expect(wrapper.html()).to.eql(compwrap(html)) expect(wrapper.html()).to.eql(compwrap(strippedHtml))
}) })
it('Adds greentext and cyantext to the post', () => { it('Adds greentext and cyantext to the post', () => {
@ -412,7 +425,7 @@ describe('RichContent', () => {
'Testing' 'Testing'
].join('') ].join('')
const expected = [ const expected = [
'<span class="poast-style">', '<span>',
'<span class="MentionsLine">', '<span class="MentionsLine">',
'<span class="MentionLink mention-link">', '<span class="MentionLink mention-link">',
'<a href="lol" class="original" target="_blank">', '<a href="lol" class="original" target="_blank">',