Add test for rendering user profile
This commit is contained in:
parent
b278f1488d
commit
fca8d44ec0
3 changed files with 62 additions and 0 deletions
|
@ -4,6 +4,10 @@ export let users = [
|
|||
{ active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['strip_media'] }
|
||||
]
|
||||
|
||||
const userProfile = { avatar: 'avatar.jpg', display_name: 'Allis', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false }
|
||||
|
||||
const userStatuses = []
|
||||
|
||||
const filterUsers = (str) => {
|
||||
const filters = str.split(',').filter(item => item.length > 0)
|
||||
if (filters.length === 0) {
|
||||
|
@ -20,6 +24,10 @@ const filterUsers = (str) => {
|
|||
return applyFilters([], filters, users)
|
||||
}
|
||||
|
||||
export async function fetchUser(id, authHost, token) {
|
||||
return Promise.resolve({ data: userProfile })
|
||||
}
|
||||
|
||||
export async function fetchUsers(filters, authHost, token, page = 1) {
|
||||
const filteredUsers = filterUsers(filters)
|
||||
return Promise.resolve({ data: {
|
||||
|
@ -29,6 +37,10 @@ export async function fetchUsers(filters, authHost, token, page = 1) {
|
|||
}})
|
||||
}
|
||||
|
||||
export async function fetchUserStatuses(id, authHost, godmode, token) {
|
||||
return Promise.resolve({ data: userStatuses })
|
||||
}
|
||||
|
||||
export async function getPasswordResetToken(nickname, authHost, token) {
|
||||
return Promise.resolve({ data: { token: 'g05lxnBJQnL', link: 'http://url/api/pleroma/password_reset/g05lxnBJQnL' }})
|
||||
}
|
||||
|
|
48
test/views/users/show.test.js
Normal file
48
test/views/users/show.test.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import Vuex from 'vuex'
|
||||
import { mount, createLocalVue, config } from '@vue/test-utils'
|
||||
import flushPromises from 'flush-promises'
|
||||
import Element from 'element-ui'
|
||||
import UsersShow from '@/views/users/show'
|
||||
import storeConfig from './store.conf'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
config.mocks["$t"] = () => {}
|
||||
|
||||
const localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
localVue.use(Element)
|
||||
|
||||
const $route = {
|
||||
params: {
|
||||
id: '2'
|
||||
}
|
||||
}
|
||||
|
||||
jest.mock('@/api/nodeInfo')
|
||||
jest.mock('@/api/users')
|
||||
|
||||
describe('Search and filter users', () => {
|
||||
let store
|
||||
|
||||
beforeEach(() => {
|
||||
store = new Vuex.Store(cloneDeep(storeConfig))
|
||||
})
|
||||
|
||||
it('fetches user profile', async (done) => {
|
||||
const wrapper = mount(UsersShow, {
|
||||
store,
|
||||
localVue,
|
||||
sync: false,
|
||||
stubs: ['router-link'],
|
||||
mocks: {
|
||||
$route
|
||||
}
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.user-profile-card').isVisible()).toBe(true)
|
||||
expect(store.state.userProfile.user.nickname).toBe('allis')
|
||||
expect(store.state.userProfile.user.roles.admin).toBe(true)
|
||||
done()
|
||||
})
|
||||
})
|
|
@ -1,5 +1,6 @@
|
|||
import app from '@/store/modules/app'
|
||||
import user from '@/store/modules/user'
|
||||
import userProfile from '@/store/modules/userProfile'
|
||||
import users from '@/store/modules/users'
|
||||
import getters from '@/store/getters'
|
||||
|
||||
|
@ -7,6 +8,7 @@ export default {
|
|||
modules: {
|
||||
app,
|
||||
user,
|
||||
userProfile,
|
||||
users
|
||||
},
|
||||
getters
|
||||
|
|
Loading…
Reference in a new issue