Fix fetching and searching tests for users

This commit is contained in:
Angelina Filippova 2019-03-27 01:56:44 +05:00
parent 46f53b2405
commit 9c8dd06780
2 changed files with 70 additions and 20 deletions

View file

@ -1,11 +1,22 @@
const users = [ const users = [
{ deactivated: false, id: '2', nickname: 'allis', local: true, roles: { admin: true, moderator: false }, tags: [] }, { active: true, deactivated: false, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [] },
{ deactivated: false, id: '10', nickname: 'bob', local: false, roles: { admin: false, moderator: true }, tags: ['sandbox'] }, { active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: true }, tags: ['sandbox'] },
{ deactivated: true, id: 'abc', nickname: 'john', local: true, roles: { admin: false, moderator: false }, tags: ['strip_media'] } { active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['strip_media'] }
] ]
export async function fetchUsers(showLocalUsersOnly, authHost, token, page = 1) { const filterUsers = (str) => {
const filteredUsers = showLocalUsersOnly ? users.filter(user => user.local) : users const filters = str.split(',').filter(item => item.length > 0)
if (filters.length === 0) {
return users
}
return filters.reduce((filter, acc) => {
const filteredUsers = users.filter(user => user[filter])
return [...acc, ...filteredUsers]
}, [])
}
export async function fetchUsers(filters, authHost, token, page = 1) {
const filteredUsers = filterUsers(filters)
return Promise.resolve({ data: { return Promise.resolve({ data: {
users: filteredUsers, users: filteredUsers,
count: filteredUsers.length, count: filteredUsers.length,
@ -18,8 +29,8 @@ export async function toggleUserActivation(nickname, authHost, token) {
return Promise.resolve({ data: { ...response, deactivated: !response.deactivated }}) return Promise.resolve({ data: { ...response, deactivated: !response.deactivated }})
} }
export async function searchUsers(query, showLocalUsersOnly, authHost, token, page = 1) { export async function searchUsers(query, filters, authHost, token, page = 1) {
const filteredUsers = showLocalUsersOnly ? users.filter(user => user.local) : users const filteredUsers = filterUsers(filters)
const response = filteredUsers.filter(user => user.nickname === query) const response = filteredUsers.filter(user => user.nickname === query)
return Promise.resolve({ data: { return Promise.resolve({ data: {
users: response, users: response,

View file

@ -6,6 +6,9 @@ import storeConfig from './store.conf'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
config.mocks["$t"] = () => {} config.mocks["$t"] = () => {}
config.mocks["$i18n"] = {
t: () => {}
}
const localVue = createLocalVue() const localVue = createLocalVue()
localVue.use(Vuex) localVue.use(Vuex)
@ -23,7 +26,10 @@ describe('Search and filter users', () => {
it('fetches initial list of users', async (done) => { it('fetches initial list of users', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -34,7 +40,10 @@ describe('Search and filter users', () => {
it('starts a search on input change', async (done) => { it('starts a search on input change', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
wrapper.vm.handleDebounceSearchInput = (query) => { wrapper.vm.handleDebounceSearchInput = (query) => {
@ -44,7 +53,7 @@ describe('Search and filter users', () => {
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
expect(wrapper.vm.usersCount).toEqual(3) expect(wrapper.vm.usersCount).toEqual(3)
const input = wrapper.find('input.el-input__inner') const input = wrapper.find('.search input.el-input__inner')
input.element.value = 'bob' input.element.value = 'bob'
input.trigger('input') input.trigger('input')
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -61,7 +70,10 @@ describe('Search and filter users', () => {
it('shows local users on checkbox click', async (done) => { it('shows local users on checkbox click', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -82,7 +94,10 @@ describe('Search and filter users', () => {
it('shows local users with search query', async (done) => { it('shows local users with search query', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
wrapper.vm.handleDebounceSearchInput = (query) => { wrapper.vm.handleDebounceSearchInput = (query) => {
@ -131,7 +146,10 @@ describe('Users actions', () => {
it('grants admin and moderator rights to a local user', async (done) => { it('grants admin and moderator rights to a local user', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -153,7 +171,10 @@ describe('Users actions', () => {
it('does not show actions that grant admin and moderator rights to external users', async (done) => { it('does not show actions that grant admin and moderator rights to external users', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -167,7 +188,10 @@ describe('Users actions', () => {
it('toggles activation status', async (done) => { it('toggles activation status', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -185,7 +209,10 @@ describe('Users actions', () => {
it('deactivates user when Delete action is called', async (done) => { it('deactivates user when Delete action is called', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -203,7 +230,10 @@ describe('Users actions', () => {
it('adds tags', async (done) => { it('adds tags', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -227,7 +257,10 @@ describe('Users actions', () => {
it('deletes tags', async (done) => { it('deletes tags', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -245,7 +278,10 @@ describe('Users actions', () => {
it('shows check icon when tag is added', async (done) => { it('shows check icon when tag is added', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
@ -261,7 +297,10 @@ describe('Users actions', () => {
it('does not change user index in array when tag is added', async (done) => { it('does not change user index in array when tag is added', async (done) => {
const wrapper = mount(Users, { const wrapper = mount(Users, {
store, store,
localVue localVue,
stubs: {
transition: false
}
}) })
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()