From fca8d44ec07d0122228949598b9267120e7aeb21 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 4 Oct 2019 21:06:01 +0300 Subject: [PATCH] Add test for rendering user profile --- src/api/__mocks__/users.js | 12 +++++++++ test/views/users/show.test.js | 48 ++++++++++++++++++++++++++++++++++ test/views/users/store.conf.js | 2 ++ 3 files changed, 62 insertions(+) create mode 100644 test/views/users/show.test.js diff --git a/src/api/__mocks__/users.js b/src/api/__mocks__/users.js index b5aca6a1..31657293 100644 --- a/src/api/__mocks__/users.js +++ b/src/api/__mocks__/users.js @@ -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' }}) } diff --git a/test/views/users/show.test.js b/test/views/users/show.test.js new file mode 100644 index 00000000..b57501c5 --- /dev/null +++ b/test/views/users/show.test.js @@ -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() + }) +}) diff --git a/test/views/users/store.conf.js b/test/views/users/store.conf.js index 77e2b7c8..89a7622a 100644 --- a/test/views/users/store.conf.js +++ b/test/views/users/store.conf.js @@ -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