components
This commit is contained in:
parent
c9dede920e
commit
dbc9bd9c46
46 changed files with 247 additions and 160 deletions
|
|
@ -1,10 +1,13 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
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)
|
||||
|
|
@ -36,17 +39,19 @@ afterEach(() => {
|
|||
})
|
||||
|
||||
describe('Draft saving', () => {
|
||||
createTestingPinia()
|
||||
beforeEach(() => {
|
||||
setActivePinia(createTestingPinia())
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
const store = useSyncConfigStore()
|
||||
store.mergedConfig = {
|
||||
autoSaveDraft: autoSave,
|
||||
}
|
||||
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
|
||||
|
||||
const textarea = wrapper.get('textarea')
|
||||
|
|
@ -63,10 +68,10 @@ describe('Draft saving', () => {
|
|||
it('should auto-save if it is enabled', async function () {
|
||||
vi.useFakeTimers()
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
await wrapper.vm.$store.dispatch('setOption', {
|
||||
name: 'autoSaveDraft',
|
||||
value: true,
|
||||
})
|
||||
const store = useSyncConfigStore()
|
||||
store.mergedConfig = {
|
||||
autoSaveDraft: true,
|
||||
}
|
||||
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
|
||||
const textarea = wrapper.get('textarea')
|
||||
await textarea.setValue('mew mew')
|
||||
|
|
@ -86,10 +91,10 @@ describe('Draft saving', () => {
|
|||
},
|
||||
}),
|
||||
)
|
||||
await wrapper.vm.$store.dispatch('setOption', {
|
||||
name: 'autoSaveDraft',
|
||||
value: true,
|
||||
})
|
||||
const store = useSyncConfigStore()
|
||||
store.mergedConfig = {
|
||||
autoSaveDraft: true,
|
||||
}
|
||||
expect(wrapper.vm.$store.getters.draftCount).to.equal(0)
|
||||
const textarea = wrapper.get('textarea')
|
||||
await textarea.setValue('mew mew')
|
||||
|
|
@ -107,14 +112,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()
|
||||
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')
|
||||
|
|
@ -132,14 +134,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()
|
||||
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')
|
||||
|
|
@ -157,14 +156,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')
|
||||
|
|
|
|||
|
|
@ -7,18 +7,13 @@ createTestingPinia()
|
|||
|
||||
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
|
||||
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
|
||||
const generateInput = (value, padEmoji = true) => {
|
||||
const wrapper = shallowMount(EmojiInput, {
|
||||
global: {
|
||||
renderStubDefaultSlot: true,
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
mergedConfig: {
|
||||
padEmoji,
|
||||
},
|
||||
},
|
||||
},
|
||||
$t: (msg) => msg,
|
||||
},
|
||||
stubs: {
|
||||
|
|
@ -49,6 +44,12 @@ const generateInput = (value, padEmoji = true) => {
|
|||
}
|
||||
|
||||
describe('EmojiInput', () => {
|
||||
beforeEach(() => {
|
||||
const store = useSyncConfigStore(createTestingPinia())
|
||||
store.mergedConfig = {
|
||||
padEmoji: true,
|
||||
}
|
||||
})
|
||||
describe('insertion mechanism', () => {
|
||||
it('inserts string at the end with trailing space', () => {
|
||||
const initialString = 'Testing'
|
||||
|
|
@ -112,6 +113,10 @@ describe('EmojiInput', () => {
|
|||
it('inserts string without any padding if padEmoji setting is set to false', () => {
|
||||
const initialString = 'Eat some spam!'
|
||||
const wrapper = generateInput(initialString, false)
|
||||
const store = useSyncConfigStore(createTestingPinia())
|
||||
store.mergedConfig = {
|
||||
padEmoji: false,
|
||||
}
|
||||
const input = wrapper.find('input')
|
||||
input.setValue(initialString)
|
||||
wrapper.setData({ caret: initialString.length, keepOpen: false })
|
||||
|
|
@ -147,6 +152,10 @@ describe('EmojiInput', () => {
|
|||
it('correctly sets caret after insertion if padEmoji setting is set to false', async () => {
|
||||
const initialString = '1234'
|
||||
const wrapper = generateInput(initialString, false)
|
||||
const store = useSyncConfigStore(createTestingPinia())
|
||||
store.mergedConfig = {
|
||||
padEmoji: false,
|
||||
}
|
||||
const input = wrapper.find('input')
|
||||
input.setValue(initialString)
|
||||
wrapper.setData({ caret: initialString.length })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue