Add tests for onDelete, query functions

This commit is contained in:
Matt Rider 2019-03-11 18:36:32 -03:00
parent 168278d76a
commit c4dff9a916

View File

@ -1,6 +1,5 @@
import { mount, createLocalVue } from '@vue/test-utils' import { mount, createLocalVue } from '@vue/test-utils'
import SearchInput from './SearchInput.vue' import SearchInput from './SearchInput.vue'
import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import Styleguide from '@human-connection/styleguide' import Styleguide from '@human-connection/styleguide'
const localVue = createLocalVue() const localVue = createLocalVue()
@ -71,32 +70,46 @@ describe('SearchInput.vue', () => {
// ) // )
}) })
it('is clearable', () => { describe('testing custom functions', () => {
const wrapper = Wrapper() let select
const select = wrapper.find('.ds-select') let wrapper
beforeEach(() => {
wrapper = Wrapper()
select = wrapper.find('.ds-select')
select.trigger('focus') select.trigger('focus')
select.element.value = 'abcd' select.element.value = 'abcd'
})
it('is clearable', () => {
select.trigger('keyup.esc') select.trigger('keyup.esc')
expect(wrapper.emitted().clear.length).toBe(1) expect(wrapper.emitted().clear.length).toBe(1)
}) })
it('changes the unprocessedSearchInput as the value changes', () => { it('changes the unprocessedSearchInput as the value changes', () => {
const wrapper = Wrapper()
const select = wrapper.find('.ds-select')
select.trigger('focus')
select.element.value = 'abcd'
select.trigger('input') select.trigger('input')
expect(wrapper.vm.unprocessedSearchInput).toBe('abcd') expect(wrapper.vm.unprocessedSearchInput).toBe('abcd')
}) })
it('searches for the term when enter is pressed', async () => { it('searches for the term when enter is pressed', async () => {
const wrapper = Wrapper()
const select = wrapper.find('.ds-select')
select.trigger('focus')
select.element.value = 'abcd'
select.trigger('input') select.trigger('input')
select.trigger('keyup.enter') select.trigger('keyup.enter')
await expect(wrapper.emitted().search[0]).toEqual(['abcd']) await expect(wrapper.emitted().search[0]).toEqual(['abcd'])
}) })
it('calls onDelete when the delete key is pressed', () => {
const spy = jest.spyOn(wrapper.vm, 'onDelete')
select.trigger('input')
select.trigger('keyup.delete')
expect(spy).toHaveBeenCalledTimes(1)
})
it('calls query when a user starts a search by pressing enter', () => {
const spy = jest.spyOn(wrapper.vm, 'query')
select.trigger('input')
select.trigger('keyup.enter')
expect(spy).toHaveBeenCalledWith('abcd')
})
})
}) })
}) })