2022-03-22 16:14:56 +00:00
|
|
|
import { h } from 'vue'
|
|
|
|
import { shallowMount } from '@vue/test-utils'
|
2019-09-15 13:01:57 +00:00
|
|
|
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
|
2022-03-22 16:14:56 +00:00
|
|
|
import vClickOutside from 'click-outside-vue3'
|
2019-09-15 13:01:57 +00:00
|
|
|
|
2019-09-25 17:54:07 +00:00
|
|
|
const generateInput = (value, padEmoji = true) => {
|
2019-09-15 13:01:57 +00:00
|
|
|
const wrapper = shallowMount(EmojiInput, {
|
2022-03-22 16:14:56 +00:00
|
|
|
global: {
|
|
|
|
renderStubDefaultSlot: true,
|
|
|
|
mocks: {
|
|
|
|
$store: {
|
|
|
|
getters: {
|
|
|
|
mergedConfig: {
|
|
|
|
padEmoji
|
|
|
|
}
|
2019-09-25 17:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 16:14:56 +00:00
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
FAIcon: true
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
'click-outside': vClickOutside
|
2019-09-25 17:54:07 +00:00
|
|
|
}
|
|
|
|
},
|
2022-03-22 16:14:56 +00:00
|
|
|
props: {
|
|
|
|
suggest: () => [],
|
|
|
|
enableEmojiPicker: true,
|
|
|
|
modelValue: value
|
2019-09-15 13:01:57 +00:00
|
|
|
},
|
2022-03-22 16:14:56 +00:00
|
|
|
slots: {
|
2022-07-31 09:35:48 +00:00
|
|
|
default: () => h('input', '')
|
2022-03-22 16:14:56 +00:00
|
|
|
}
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
2022-03-22 16:14:56 +00:00
|
|
|
return wrapper
|
2019-09-15 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('EmojiInput', () => {
|
|
|
|
describe('insertion mechanism', () => {
|
|
|
|
it('inserts string at the end with trailing space', () => {
|
|
|
|
const initialString = 'Testing'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: initialString.length })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: '(test)', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('Testing (test) ')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('inserts string at the end with trailing space (source has a trailing space)', () => {
|
|
|
|
const initialString = 'Testing '
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: initialString.length })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: '(test)', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('Testing (test) ')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('inserts string at the begginning without leading space', () => {
|
|
|
|
const initialString = 'Testing'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: 0 })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: '(test)', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('(test) Testing')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('inserts string between words without creating extra spaces', () => {
|
|
|
|
const initialString = 'Spurdo Sparde'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: 6 })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: ':ebin:', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('Spurdo :ebin: Sparde')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('inserts string between words without creating extra spaces (other caret)', () => {
|
|
|
|
const initialString = 'Spurdo Sparde'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: 7 })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: ':ebin:', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('Spurdo :ebin: Sparde')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
2019-09-25 17:54:07 +00:00
|
|
|
it('inserts string without any padding if padEmoji setting is set to false', () => {
|
2019-09-15 13:01:57 +00:00
|
|
|
const initialString = 'Eat some spam!'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString, false)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
2019-09-25 17:54:07 +00:00
|
|
|
wrapper.setData({ caret: initialString.length, keepOpen: false })
|
|
|
|
wrapper.vm.insert({ insertion: ':spam:' })
|
2022-03-22 16:14:56 +00:00
|
|
|
const inputEvents = wrapper.emitted()['update:modelValue']
|
2020-02-16 21:35:04 +00:00
|
|
|
expect(inputEvents[inputEvents.length - 1][0]).to.eql('Eat some spam!:spam:')
|
2019-09-15 13:01:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('correctly sets caret after insertion at beginning', (done) => {
|
|
|
|
const initialString = '1234'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: 0 })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: '1234', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
wrapper.vm.$nextTick(() => {
|
2019-09-15 13:01:57 +00:00
|
|
|
expect(wrapper.vm.caret).to.eql(5)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('correctly sets caret after insertion at end', (done) => {
|
|
|
|
const initialString = '1234'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: initialString.length })
|
2019-09-23 17:29:01 +00:00
|
|
|
wrapper.vm.insert({ insertion: '1234', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
wrapper.vm.$nextTick(() => {
|
2019-09-15 13:01:57 +00:00
|
|
|
expect(wrapper.vm.caret).to.eql(10)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-09-25 17:54:07 +00:00
|
|
|
it('correctly sets caret after insertion if padEmoji setting is set to false', (done) => {
|
2019-09-15 13:01:57 +00:00
|
|
|
const initialString = '1234'
|
2022-03-22 16:14:56 +00:00
|
|
|
const wrapper = generateInput(initialString, false)
|
2019-09-15 13:01:57 +00:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.setValue(initialString)
|
|
|
|
wrapper.setData({ caret: initialString.length })
|
2019-09-25 17:54:07 +00:00
|
|
|
wrapper.vm.insert({ insertion: '1234', keepOpen: false })
|
2022-03-22 16:14:56 +00:00
|
|
|
wrapper.vm.$nextTick(() => {
|
2019-09-15 13:01:57 +00:00
|
|
|
expect(wrapper.vm.caret).to.eql(8)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|