pleroma-fe/test/unit/specs/components/user_profile.spec.js

220 lines
4.7 KiB
JavaScript
Raw Normal View History

import { mount } from '@vue/test-utils'
2026-01-08 17:26:52 +02:00
import { createStore } from 'vuex'
2018-12-15 06:16:44 +03:00
import UserProfile from 'src/components/user_profile/user_profile.vue'
import { getters } from 'src/modules/users.js'
2026-01-06 16:23:17 +02:00
import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js'
2018-12-15 06:16:44 +03:00
const mutations = {
2026-01-06 17:32:22 +02:00
clearTimeline: () => {
/* no-op */
},
2018-12-15 06:16:44 +03:00
}
const actions = {
2026-01-06 17:32:22 +02:00
fetchUser: () => {
/* no-op */
},
fetchUserByScreenName: () => {
/* no-op */
},
}
const testGetters = {
2026-01-06 16:22:52 +02:00
findUser: (state) => getters.findUser(state.users),
findUserByName: (state) => getters.findUserByName(state.users),
relationship: (state) => getters.relationship(state.users),
2025-02-04 15:23:21 +02:00
mergedConfig: () => ({
colors: '',
highlight: {},
customTheme: {
2026-01-06 16:22:52 +02:00
colors: [],
},
}),
}
const localUser = {
id: 100,
is_local: true,
2021-02-26 16:37:46 +02:00
screen_name: 'testUser',
2026-01-06 16:22:52 +02:00
screen_name_ui: 'testUser',
}
const extUser = {
id: 100,
is_local: false,
2021-02-26 16:37:46 +02:00
screen_name: 'testUser@test.instance',
2026-01-06 16:22:52 +02:00
screen_name_ui: 'testUser@test.instance',
}
const externalProfileStore = createStore({
2018-12-15 06:16:44 +03:00
mutations,
actions,
getters: testGetters,
2018-12-15 06:16:44 +03:00
state: {
api: {
2019-04-28 20:46:01 +03:00
fetchers: {},
2026-01-06 16:22:52 +02:00
backendInteractor: backendInteractorService(''),
2018-12-15 06:16:44 +03:00
},
2018-12-17 02:45:40 +03:00
interface: {
2026-01-06 16:22:52 +02:00
browserSupport: '',
2018-12-17 02:45:40 +03:00
},
2018-12-15 06:16:44 +03:00
instance: {
2026-01-06 16:22:52 +02:00
hideUserStats: true,
2018-12-15 06:16:44 +03:00
},
statuses: {
timelines: {
user: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
viewing: 'statuses',
userId: 100,
2026-01-06 16:22:52 +02:00
flushMarker: 0,
2019-01-26 13:51:07 +00:00
},
media: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
viewing: 'statuses',
userId: 100,
2026-01-06 16:22:52 +02:00
flushMarker: 0,
},
},
2018-12-15 06:16:44 +03:00
},
users: {
currentUser: {
2026-01-06 16:22:52 +02:00
credentials: '',
2018-12-15 06:16:44 +03:00
},
usersObject: { 100: extUser },
usersByNameObject: {},
2020-04-22 00:07:01 +03:00
users: [extUser],
2026-01-06 16:22:52 +02:00
relationships: {},
},
},
2018-12-15 06:16:44 +03:00
})
const localProfileStore = createStore({
2018-12-17 01:53:21 +03:00
mutations,
actions,
getters: testGetters,
2018-12-17 01:53:21 +03:00
state: {
api: {
2019-04-28 20:46:01 +03:00
fetchers: {},
2026-01-06 16:22:52 +02:00
backendInteractor: backendInteractorService(''),
2018-12-17 01:53:21 +03:00
},
2018-12-17 02:45:40 +03:00
interface: {
2026-01-06 16:22:52 +02:00
browserSupport: '',
2018-12-17 02:45:40 +03:00
},
2018-12-17 01:53:21 +03:00
config: {
colors: '',
2018-12-17 02:45:40 +03:00
highlight: {},
customTheme: {
2026-01-06 16:22:52 +02:00
colors: [],
},
2018-12-17 01:53:21 +03:00
},
instance: {
2026-01-06 16:22:52 +02:00
hideUserStats: true,
2018-12-17 01:53:21 +03:00
},
statuses: {
timelines: {
user: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
2019-01-26 13:51:07 +00:00
viewing: 'statuses',
userId: 100,
2026-01-06 16:22:52 +02:00
flushMarker: 0,
2019-01-26 13:51:07 +00:00
},
media: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
2018-12-17 01:53:21 +03:00
viewing: 'statuses',
userId: 100,
2026-01-06 16:22:52 +02:00
flushMarker: 0,
},
},
2018-12-17 01:53:21 +03:00
},
users: {
currentUser: {
2026-01-06 16:22:52 +02:00
credentials: '',
2018-12-17 01:53:21 +03:00
},
usersObject: { 100: localUser },
usersByNameObject: { testuser: localUser },
2020-04-22 00:07:01 +03:00
users: [localUser],
2026-01-06 16:22:52 +02:00
relationships: {},
},
},
2018-12-17 01:53:21 +03:00
})
// https://github.com/vuejs/test-utils/issues/1382
describe.skip('UserProfile', () => {
2018-12-17 01:53:21 +03:00
it('renders external profile', () => {
2018-12-15 06:16:44 +03:00
const wrapper = mount(UserProfile, {
global: {
2022-07-31 12:35:48 +03:00
plugins: [externalProfileStore],
mocks: {
$route: {
params: { id: 100 },
2026-01-06 16:22:52 +02:00
name: 'external-user-profile',
},
2026-01-06 16:22:52 +02:00
$t: (msg) => msg,
},
},
2018-12-15 06:16:44 +03:00
})
2026-01-06 16:22:52 +02:00
expect(wrapper.find('.user-screen-name').text()).to.eql(
'@testUser@test.instance',
)
2018-12-15 06:16:44 +03:00
})
2018-12-17 01:53:21 +03:00
it('renders local profile', () => {
const wrapper = mount(UserProfile, {
global: {
2022-07-31 12:35:48 +03:00
plugins: [localProfileStore],
mocks: {
$route: {
params: { name: 'testUser' },
2026-01-06 16:22:52 +02:00
name: 'user-profile',
},
2026-01-06 16:22:52 +02:00
$t: (msg) => msg,
},
},
2018-12-17 01:53:21 +03:00
})
expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser')
2018-12-17 01:53:21 +03:00
})
2018-12-15 06:16:44 +03:00
})