fix tests

This commit is contained in:
Henry Jameson 2026-08-19 23:46:51 +03:00
commit 25d0d16dbb
10 changed files with 203 additions and 204 deletions

View file

@ -1,24 +1,11 @@
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { mount, shallowMount } from '@vue/test-utils'
import { mountOpts } from '../../../fixtures/setup_test'
import RichContent from 'src/components/rich_content/rich_content.jsx'
const attentions = []
const global = {
mocks: {
$store: {
state: {},
getters: {
mergedConfig: () => ({
mentionLinkShowTooltip: true,
}),
findUserByUrl: () => null,
},
},
},
stubs: {
FAIcon: true,
},
}
const makeMention = (who, noClass) => {
attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` })
@ -37,10 +24,13 @@ const mentionsLine = (times) =>
].join('')
describe('RichContent', () => {
beforeEach(() => {
setActivePinia(createTestingPinia())
})
it('renders simple post without exploding', () => {
const html = p('Hello world!')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -48,7 +38,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
})
@ -56,8 +46,7 @@ describe('RichContent', () => {
it('unescapes everything as needed', () => {
const html = [p('Testing 'em all'), 'Testing 'em all'].join('')
const expected = [p("Testing 'em all"), "Testing 'em all"].join('')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -65,15 +54,14 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
it('replaces mention with mentionsline', () => {
const html = p(makeMention('John'), ' how are you doing today?')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -81,7 +69,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(
compwrap(p(mentionsLine(1), ' how are you doing today?')),
@ -105,8 +93,7 @@ describe('RichContent', () => {
),
].join('')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -114,7 +101,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
@ -141,8 +128,7 @@ describe('RichContent', () => {
].join(''),
].join('\n')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: false,
@ -150,7 +136,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html()).to.eql(compwrap(strippedHtml))
})
@ -162,8 +148,7 @@ describe('RichContent', () => {
'<span class="greentext">&gt;any year</span>',
].join('\n')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: false,
@ -171,7 +156,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html()).to.eql(compwrap(expected))
})
@ -179,8 +164,7 @@ describe('RichContent', () => {
it('Does not add greentext and cyantext if setting is set to false', () => {
const html = ['&gt;preordering videogames', '&gt;any year'].join('\n')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: false,
@ -188,7 +172,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html()).to.eql(compwrap(html))
})
@ -200,8 +184,7 @@ describe('RichContent', () => {
'<anonymous-stub shortcode="spurdo" islocal="true" class="emoji img" src="about:blank" title=":spurdo:" alt=":spurdo:"></anonymous-stub>',
)
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: false,
@ -209,7 +192,7 @@ describe('RichContent', () => {
emoji: [{ url: 'about:blank', shortcode: 'spurdo' }],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
@ -217,8 +200,7 @@ describe('RichContent', () => {
it("Doesn't add nonexistent emoji to post", () => {
const html = p('Lol :lol:')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: false,
@ -226,7 +208,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
})
@ -245,8 +227,7 @@ describe('RichContent', () => {
'<span class="greentext">&gt;quote</span>',
].join('\n')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -254,7 +235,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html()).to.eql(compwrap(expected))
})
@ -268,8 +249,7 @@ describe('RichContent', () => {
].join('<br>')
const expected = ['Bruh', 'Bruh', mentionsLine(3), 'Bruh'].join('<br>')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -277,7 +257,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
@ -304,8 +284,7 @@ describe('RichContent', () => {
' </p>',
].join('')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -313,7 +292,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
@ -351,8 +330,7 @@ describe('RichContent', () => {
p('Testing'),
].join('')
const wrapper = mount(RichContent, {
global,
const wrapper = mount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -360,7 +338,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(
wrapper
@ -424,8 +402,7 @@ describe('RichContent', () => {
'Testing',
].join('')
const wrapper = mount(RichContent, {
global,
const wrapper = mount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -433,7 +410,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(
wrapper
@ -473,8 +450,7 @@ describe('RichContent', () => {
'</p>',
].join('')
const wrapper = shallowMount(RichContent, {
global,
const wrapper = shallowMount(RichContent, mountOpts({
props: {
attentions,
handleLinks: true,
@ -482,7 +458,7 @@ describe('RichContent', () => {
emoji: [],
html,
},
})
}))
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
})
@ -519,14 +495,13 @@ describe('RichContent', () => {
const ptest = (handleLinks, vhtml) => {
const t0 = performance.now()
const wrapper = mount(TestComponent, {
global,
const wrapper = mount(TestComponent, mountOpts({
props: {
attentions,
handleLinks,
vhtml,
},
})
}))
const t1 = performance.now()