Add tests for filtering with multiple filters and with search query

This commit is contained in:
Angelina Filippova 2019-03-28 21:31:45 +07:00
parent 9a4209cb4e
commit 55165f152b

View file

@ -7,6 +7,7 @@ import { cloneDeep } from 'lodash'
import flushPromises from 'flush-promises' import flushPromises from 'flush-promises'
config.mocks["$t"] = () => {} config.mocks["$t"] = () => {}
config.stubs.transition = false
const localVue = createLocalVue() const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
@ -26,67 +27,56 @@ describe('Filters users', () => {
it('shows local users on "Local" filter click', async (done) => { it('shows local users on "Local" filter click', async (done) => {
const wrapper = mount(Filters, { const wrapper = mount(Filters, {
store, store,
localVue, localVue
stubs: {
transition: false
}
}) })
let usersLength = store.state.users.totalUsersCount expect(store.state.users.totalUsersCount).toEqual(3)
expect(usersLength).toEqual(3)
const filter = wrapper.find(`li.el-select-dropdown__item:nth-child(${1})`) const filter = wrapper.find(`li.el-select-dropdown__item:nth-child(${1})`)
filter.trigger('click') filter.trigger('click')
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
usersLength = store.state.users.totalUsersCount expect(store.state.users.totalUsersCount).toEqual(2)
expect(usersLength).toEqual(2)
filter.trigger('click') filter.trigger('click')
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
usersLength = store.state.users.totalUsersCount expect(store.state.users.totalUsersCount).toEqual(2)
expect(usersLength).toEqual(2)
done() done()
}) })
// it('shows local users with search query', async (done) => { it('shows local users with search query', async (done) => {
// const wrapper = mount(Users, { expect(store.state.users.totalUsersCount).toEqual(3)
// store,
// localVue,
// stubs: ['users-filter']
// })
// wrapper.vm.handleDebounceSearchInput = (query) => { store.dispatch('ToggleUsersFilter', { active: true })
// store.dispatch('SearchUsers', { query, page: 1 }) await flushPromises()
// } store.dispatch('SearchUsers', { query: 'john', page: 1 })
await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(0)
// await wrapper.vm.$nextTick() store.dispatch('SearchUsers', { query: 'allis', page: 1 })
// expect(wrapper.vm.usersCount).toEqual(3) await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(1)
// const checkboxInput = wrapper.find('input.el-checkbox__original') store.dispatch('SearchUsers', { query: '', page: 1 })
// checkboxInput.trigger('click') await flushPromises()
// await wrapper.vm.$nextTick() expect(store.state.users.totalUsersCount).toEqual(2)
// const searchInput = wrapper.find('input.el-input__inner')
// searchInput.element.value = 'bob'
// searchInput.trigger('input')
// await wrapper.vm.$nextTick()
// expect(wrapper.vm.usersCount).toEqual(0)
// searchInput.element.value = 'allis' done()
// searchInput.trigger('input') })
// await wrapper.vm.$nextTick()
// expect(wrapper.vm.usersCount).toEqual(1)
// searchInput.element.value = '' it('applies two filters', async (done) => {
// searchInput.trigger('input') expect(store.state.users.totalUsersCount).toEqual(3)
// await wrapper.vm.$nextTick()
// expect(wrapper.vm.usersCount).toEqual(2)
// checkboxInput.trigger('click') store.dispatch('ToggleUsersFilter', { active: true, local: true })
// await wrapper.vm.$nextTick() await flushPromises()
// expect(wrapper.vm.usersCount).toEqual(3) expect(store.state.users.totalUsersCount).toEqual(1)
expect(store.state.users.fetchedUsers[0].nickname).toEqual('allis')
// done() store.dispatch('ToggleUsersFilter', { deactivated: true, external: true })
// }) await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(0)
done()
})
}) })