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