fix tests

This commit is contained in:
Henry Jameson 2026-01-23 17:24:02 +02:00
commit 3cdcb87831
11 changed files with 165 additions and 82 deletions

View file

@ -1,9 +1,12 @@
import { createTestingPinia } from '@pinia/testing'
import { flushPromises, mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
const autoSaveOrNot = (caseFn, caseTitle, runFn) => {
caseFn(`${caseTitle} with auto-save`, function () {
return runFn.bind(this)(true)
@ -30,20 +33,23 @@ const saveManually = async (wrapper) => {
const waitSaveTime = 4000
afterEach(() => {
vi.useRealTimers()
})
describe('Draft saving', () => {
beforeEach(() => {
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
autoSaveDraft: true,
}
})
afterEach(() => {
vi.useRealTimers()
})
autoSaveOrNot(
it,
'should save when the button is clicked',
async (autoSave) => {
const wrapper = mount(PostStatusForm, mountOpts())
await wrapper.vm.$store.dispatch('setOption', {
name: 'autoSaveDraft',
value: autoSave,
})
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
const textarea = wrapper.get('textarea')
@ -83,10 +89,6 @@ describe('Draft saving', () => {
},
}),
)
await wrapper.vm.$store.dispatch('setOption', {
name: 'autoSaveDraft',
value: true,
})
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
const textarea = wrapper.get('textarea')
await textarea.setValue('mew mew')
@ -104,14 +106,11 @@ describe('Draft saving', () => {
},
}),
)
await wrapper.vm.$store.dispatch('setOption', {
name: 'autoSaveDraft',
value: false,
})
await wrapper.vm.$store.dispatch('setOption', {
name: 'unsavedPostAction',
value: 'save',
})
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'save',
}
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
const textarea = wrapper.get('textarea')
await textarea.setValue('mew mew')
@ -129,14 +128,11 @@ describe('Draft saving', () => {
},
}),
)
await wrapper.vm.$store.dispatch('setOption', {
name: 'autoSaveDraft',
value: false,
})
await wrapper.vm.$store.dispatch('setOption', {
name: 'unsavedPostAction',
value: 'discard',
})
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'discard',
}
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
const textarea = wrapper.get('textarea')
await textarea.setValue('mew mew')
@ -154,14 +150,11 @@ describe('Draft saving', () => {
},
}),
)
await wrapper.vm.$store.dispatch('setOption', {
name: 'autoSaveDraft',
value: false,
})
await wrapper.vm.$store.dispatch('setOption', {
name: 'unsavedPostAction',
value: 'confirm',
})
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'confirm',
}
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
const textarea = wrapper.get('textarea')
await textarea.setValue('mew mew')