1
0
Fork 0
forked from srxl/akkoma-fe
akkoma-fe/test/unit/specs/components/user_profile.spec.js

165 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-12-15 03:16:44 +00:00
import { mount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import UserProfile from 'src/components/user_profile/user_profile.vue'
import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js'
import { getters } from 'src/modules/users.js'
2018-12-15 03:16:44 +00:00
const localVue = createLocalVue()
localVue.use(Vuex)
const mutations = {
clearTimeline: () => {},
setError: () => {}
2018-12-15 03:16:44 +00:00
}
const testGetters = {
userByName: state => getters.userByName(state.users),
userById: state => getters.userById(state.users)
}
const localUser = {
id: 100,
is_local: true,
screen_name: 'testUser'
}
const extUser = {
id: 100,
is_local: false,
screen_name: 'testUser@test.instance'
}
2018-12-16 22:53:21 +00:00
const externalProfileStore = new Vuex.Store({
2018-12-15 03:16:44 +00:00
mutations,
getters: testGetters,
2018-12-15 03:16:44 +00:00
state: {
api: {
backendInteractor: backendInteractorService('')
},
2018-12-16 23:45:40 +00:00
interface: {
browserSupport: ''
},
2018-12-15 03:16:44 +00:00
config: {
colors: '',
2018-12-16 23:45:40 +00:00
highlight: {},
customTheme: {
colors: []
}
2018-12-15 03:16:44 +00:00
},
instance: {
hideUserStats: true
},
statuses: {
timelines: {
user: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
viewing: 'statuses',
userId: 100,
2018-12-15 03:16:44 +00:00
flushMarker: 0
}
}
},
users: {
currentUser: {
credentials: ''
},
usersObject: [extUser],
users: [extUser]
2018-12-15 03:16:44 +00:00
}
}
})
2018-12-16 22:53:21 +00:00
const localProfileStore = new Vuex.Store({
mutations,
getters: testGetters,
2018-12-16 22:53:21 +00:00
state: {
api: {
backendInteractor: backendInteractorService('')
},
2018-12-16 23:45:40 +00:00
interface: {
browserSupport: ''
},
2018-12-16 22:53:21 +00:00
config: {
colors: '',
2018-12-16 23:45:40 +00:00
highlight: {},
customTheme: {
colors: []
}
2018-12-16 22:53:21 +00:00
},
instance: {
hideUserStats: true
},
statuses: {
timelines: {
user: {
statuses: [],
statusesObject: {},
faves: [],
visibleStatuses: [],
visibleStatusesObject: {},
newStatusCount: 0,
maxId: 0,
minVisibleId: 0,
loading: false,
followers: [],
friends: [],
viewing: 'statuses',
userId: 100,
2018-12-16 22:53:21 +00:00
flushMarker: 0
}
}
},
users: {
currentUser: {
credentials: ''
},
usersObject: [localUser],
users: [localUser]
2018-12-16 22:53:21 +00:00
}
}
})
2018-12-15 03:16:44 +00:00
describe('UserProfile', () => {
2018-12-16 22:53:21 +00:00
it('renders external profile', () => {
2018-12-15 03:16:44 +00:00
const wrapper = mount(UserProfile, {
localVue,
2018-12-16 22:53:21 +00:00
store: externalProfileStore,
2018-12-15 03:16:44 +00:00
mocks: {
$route: {
params: { id: 100 },
2018-12-15 03:16:44 +00:00
name: 'external-user-profile'
},
$t: (msg) => msg
}
})
expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser@test.instance')
2018-12-15 03:16:44 +00:00
})
2018-12-16 22:53:21 +00:00
it('renders local profile', () => {
const wrapper = mount(UserProfile, {
localVue,
store: localProfileStore,
mocks: {
$route: {
params: { name: 'testUser' },
2018-12-16 22:53:21 +00:00
name: 'user-profile'
},
$t: (msg) => msg
}
})
expect(wrapper.find('.user-screen-name').text()).to.eql('@testUser')
2018-12-16 22:53:21 +00:00
})
2018-12-15 03:16:44 +00:00
})