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

@ -2,6 +2,7 @@ import { createTestingPinia } from '@pinia/testing'
import { flushPromises, mount } from '@vue/test-utils'
import { setActivePinia } from 'pinia'
import { nextTick } from 'vue'
import { useUsersStore } from 'src/stores/users.js'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
@ -34,13 +35,20 @@ const saveManually = async (wrapper) => {
const waitSaveTime = 4000
afterEach(() => {
vi.useRealTimers()
})
const currentUser = {
id: 'current-user',
default_scope: 'public',
locked: false,
}
describe('Draft saving', () => {
beforeEach(() => {
setActivePinia(createTestingPinia())
useUsersStore().currentUser = currentUser
})
afterEach(() => {
vi.useRealTimers()
})
autoSaveOrNot(

View file

@ -1,4 +1,6 @@
import { createTestingPinia } from '@pinia/testing'
import { mount } from '@vue/test-utils'
import { setActivePinia } from 'pinia'
import { vi } from 'vitest'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
@ -33,24 +35,18 @@ const repliedStatus2 = {
user: repliedUser,
}
const replyMountOpts = (props) =>
mountOpts({
props,
afterStore(store) {
useUsersStore().currentUser = currentUser
useStatusesStore().allStatuses = {
[repliedStatus.id]: repliedStatus,
}
},
})
describe('PostStatusForm', () => {
beforeEach(() => {
vi.useFakeTimers()
setActivePinia(createTestingPinia())
useUsersStore().currentUser = currentUser
useStatusesStore().allStatuses = new Map([
[repliedStatus.id, repliedStatus],
])
})
it('Clean empty initial state', () => {
const wrapper = mount(PostStatusForm, replyMountOpts())
const wrapper = mount(PostStatusForm, mountOpts())
expect(wrapper.vm.statusType).to.equal('new')
expect(wrapper.vm.newStatus.spoilerText).to.eql('')
@ -59,7 +55,7 @@ describe('PostStatusForm', () => {
})
it('Reset cleans form to pristine state equal to state form was when created', () => {
const wrapper = mount(PostStatusForm, replyMountOpts())
const wrapper = mount(PostStatusForm, mountOpts())
const initial = { ...wrapper.vm.newStatus }
wrapper.vm.clearStatus()
@ -70,8 +66,10 @@ describe('PostStatusForm', () => {
it('Initializes a reply form', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus,
mountOpts({
props: {
repliedStatus: repliedStatus,
},
}),
)
@ -93,8 +91,10 @@ describe('PostStatusForm', () => {
it('Copies scope and subject line, disables quoting for locked posts', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus2,
mountOpts({
props: {
repliedStatus: repliedStatus2,
},
}),
)
@ -123,8 +123,10 @@ describe('PostStatusForm', () => {
it('Forces direct mode when replying to a DM, mastodon style subject handling', () => {
// We need to initialize pinia first which is happening here...
const options = replyMountOpts({
repliedStatus: { ...repliedStatus2, visibility: 'direct' },
const options = mountOpts({
props: {
repliedStatus: { ...repliedStatus2, visibility: 'direct' },
},
})
// ...set our settings...
@ -152,10 +154,12 @@ describe('PostStatusForm', () => {
it('Sets status to statusText without mentions if mentions line is enabled', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus2,
statusText: 'testing',
mentionsLine: true,
mountOpts({
props: {
repliedStatus: repliedStatus2,
statusText: 'testing',
mentionsLine: true,
},
}),
)
@ -168,8 +172,10 @@ describe('PostStatusForm', () => {
it('Sets mention when asked for it', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
profileMention: repliedUser,
mountOpts({
props: {
profileMention: repliedUser,
},
}),
)
@ -182,8 +188,10 @@ describe('PostStatusForm', () => {
it('Initializes quote when reply/quote toggled to quote', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus2,
mountOpts({
props: {
repliedStatus: repliedStatus2,
},
}),
)
@ -198,8 +206,10 @@ describe('PostStatusForm', () => {
it('Resets quote when reply/quote toggled to reply', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus2,
mountOpts({
props: {
repliedStatus: repliedStatus2,
},
}),
)
@ -215,8 +225,10 @@ describe('PostStatusForm', () => {
it('Initializes and reset quote when toggling quote attachment', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
repliedStatus: repliedStatus2,
mountOpts({
props: {
repliedStatus: repliedStatus2,
},
}),
)
@ -236,17 +248,19 @@ describe('PostStatusForm', () => {
it('Status editing', () => {
const wrapper = mount(
PostStatusForm,
replyMountOpts({
statusId: 'edited',
statusText: 'text',
statusSubject: 'heading',
statusIsSensitive: true,
statusPoll: {},
statusQuote: {},
statusFiles: [],
statusMediaDescriptions: {},
statusVisibility: 'unlisted',
statusContentType: 'text/markdown',
mountOpts({
props: {
statusId: 'edited',
statusText: 'text',
statusSubject: 'heading',
statusIsSensitive: true,
statusPoll: {},
statusQuote: {},
statusFiles: [],
statusMediaDescriptions: {},
statusVisibility: 'unlisted',
statusContentType: 'text/markdown',
},
}),
)
@ -266,7 +280,7 @@ describe('PostStatusForm', () => {
it('Posting should reset idempotency key', async () => {
vi.setSystemTime(new Date(2027, 1, 1, 13))
const wrapper = mount(PostStatusForm, replyMountOpts())
const wrapper = mount(PostStatusForm, mountOpts())
const oldIdempotency = wrapper.vm.idempotencyKey
vi.setSystemTime(new Date(2028, 1, 1, 13))
@ -280,7 +294,7 @@ describe('PostStatusForm', () => {
// TODO Probably better to separate attachment upload/manipulation into its own component?
// we need to upload-on-submit for compression setting anyway
it('Attachments manipulations (moving, adding, removing)', () => {
const wrapper = mount(PostStatusForm, replyMountOpts())
const wrapper = mount(PostStatusForm, mountOpts())
const i1 = { id: '1', url: 'a' }
const i2 = { id: '2', url: 'b' }
@ -310,7 +324,7 @@ describe('PostStatusForm', () => {
})
it('Attachment descriptions', () => {
const wrapper = mount(PostStatusForm, replyMountOpts())
const wrapper = mount(PostStatusForm, mountOpts())
const i1 = { id: '1', url: 'a' }

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()