Specs for Searches

This commit is contained in:
Moriz Wahl 2020-01-06 16:10:28 +01:00
parent b4d120dff3
commit bc3aa519d0
4 changed files with 103 additions and 35 deletions

View File

@ -30,14 +30,6 @@ describe('SearchResources.vue', () => {
}
describe('mount', () => {
it('defaults to an empty array as searchResults', () => {
expect(wrapper.vm.searchResults).toEqual([])
})
it('defaults to pending false, as in the search is not pending', () => {
expect(wrapper.vm.pending).toBe(false)
})
describe('Emitted events', () => {
let searchableInputComponent
beforeEach(() => {
@ -60,7 +52,7 @@ describe('SearchResources.vue', () => {
})
it('clears searchResults', () => {
expect(wrapper.vm.searchResults).toEqual([])
expect(wrapper.find('.is-open').exists()).toBe(false)
})
it('set pending to false', () => {

View File

@ -0,0 +1,27 @@
import { mount } from '@vue/test-utils'
import SearchHeading from './SearchHeading.vue'
const localVue = global.localVue
describe('SearchHeading.vue', () => {
let mocks, wrapper, propsData
beforeEach(() => {
mocks = {
$t: jest.fn(string => string),
}
propsData = {
resourceType: 'Post',
}
wrapper = Wrapper()
})
const Wrapper = () => {
return mount(SearchHeading, { mocks, localVue, propsData })
}
describe('mount', () => {
it('renders heading', () => {
expect(wrapper.text()).toMatch('search.heading.Post')
})
})
})

View File

@ -0,0 +1,62 @@
import { shallowMount } from '@vue/test-utils'
import SearchPost from './SearchPost.vue'
const localVue = global.localVue
localVue.filter('dateTime', d => d)
describe('SearchPost.vue', () => {
let mocks, wrapper, propsData
beforeEach(() => {
mocks = {
$t: jest.fn(string => string),
}
propsData = {
option: {
title: 'Post Title',
commentsCount: 3,
shoutedCount: 6,
createdAt: '23.08.2019',
author: {
name: 'Post Author',
},
},
}
wrapper = Wrapper()
})
const Wrapper = () => {
return shallowMount(SearchPost, { mocks, localVue, propsData })
}
describe('mount', () => {
it('renders post title', () => {
expect(wrapper.find('.search-option-label').text()).toMatch('Post Title')
})
it('renders post commentsCount', () => {
expect(
wrapper
.find('.search-post-meta')
.findAll('span')
.at(0)
.text(),
).toMatch('3')
})
it('renders post shoutedCount', () => {
expect(
wrapper
.find('.search-post-meta')
.findAll('span')
.at(1)
.text(),
).toMatch('6')
})
it('renders post author', () => {
expect(
wrapper
.find('.search-post-author')
.text()
.replace(/\s+-\s+/, ' '),
).toMatch('Post Author 23.08.2019')
})
})
})

View File

@ -11,7 +11,7 @@ localVue.filter('dateTime', () => Date.now)
config.stubs['nuxt-link'] = '<span><slot /></span>'
describe('SearchableInput.vue', () => {
let mocks, propsData, getters
let mocks, propsData, getters, wrapper
beforeEach(() => {
propsData = {}
@ -22,56 +22,43 @@ describe('SearchableInput.vue', () => {
$t: jest.fn(string => string),
}
getters = { 'auth/isModerator': () => false }
wrapper = Wrapper()
})
const Wrapper = () => {
const store = new Vuex.Store({
getters,
})
return mount(SearchableInput, { mocks, localVue, propsData, store })
}
describe('mount', () => {
const Wrapper = () => {
const store = new Vuex.Store({
getters,
})
return mount(SearchableInput, { mocks, localVue, propsData, store })
}
it('defaults to an empty value', () => {
expect(Wrapper().vm.value).toBe('')
})
it('default to a 300 millisecond delay from the time the user stops typing to when the search starts', () => {
expect(Wrapper().vm.delay).toEqual(300)
})
it('defaults to an empty array as options', () => {
expect(Wrapper().vm.options).toEqual([])
})
describe('testing custom functions', () => {
let select, wrapper
let select
beforeEach(() => {
wrapper = Wrapper()
select = wrapper.find('.ds-select')
select.trigger('focus')
select.element.value = 'abcd'
})
it('opens the select dropdown when focused on', () => {
expect(wrapper.vm.isOpen).toBe(true)
expect(wrapper.find('.is-open').exists()).toBe(true)
})
it('opens the select dropdown and blurs after focused on', () => {
select.trigger('blur')
expect(wrapper.vm.isOpen).toBe(false)
expect(wrapper.find('.is-open').exists()).toBe(false)
})
it('is clearable', () => {
select.trigger('input')
select.trigger('keyup.esc')
expect(wrapper.emitted().clearSearch.length).toBe(1)
expect(wrapper.find('.is-open').exists()).toBe(false)
})
it('changes the unprocessedSearchInput as the value changes', () => {
select.trigger('input')
expect(wrapper.vm.unprocessedSearchInput).toBe('abcd')
expect(select.element.value).toBe('abcd')
})
it('searches for the term when enter is pressed', async () => {