mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
- Update styling - Avoid nested tags - Rename components with two names - Add story - Co-authored-by: Alina Beck <alina.beck@mail.com>
116 lines
2.9 KiB
JavaScript
116 lines
2.9 KiB
JavaScript
import { mount, RouterLinkStub } from '@vue/test-utils'
|
|
import User from './User.vue'
|
|
import Vuex from 'vuex'
|
|
|
|
const localVue = global.localVue
|
|
const filter = jest.fn(str => str)
|
|
|
|
localVue.filter('truncate', filter)
|
|
|
|
describe('User', () => {
|
|
let propsData
|
|
let mocks
|
|
let stubs
|
|
let getters
|
|
|
|
beforeEach(() => {
|
|
propsData = {}
|
|
|
|
mocks = {
|
|
$t: jest.fn(),
|
|
}
|
|
stubs = {
|
|
NuxtLink: RouterLinkStub,
|
|
}
|
|
getters = {
|
|
'auth/user': () => {
|
|
return {}
|
|
},
|
|
'auth/isModerator': () => false,
|
|
}
|
|
})
|
|
|
|
describe('mount', () => {
|
|
const Wrapper = () => {
|
|
const store = new Vuex.Store({
|
|
getters,
|
|
})
|
|
return mount(User, { store, propsData, mocks, stubs, localVue })
|
|
}
|
|
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.text()).toBe('')
|
|
expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym')
|
|
})
|
|
|
|
describe('given an user', () => {
|
|
beforeEach(() => {
|
|
propsData.user = {
|
|
name: 'Tilda Swinton',
|
|
slug: 'tilda-swinton',
|
|
}
|
|
})
|
|
|
|
it('renders user name', () => {
|
|
const wrapper = Wrapper()
|
|
expect(mocks.$t).not.toHaveBeenCalledWith('profile.userAnonym')
|
|
expect(wrapper.text()).toMatch('Tilda Swinton')
|
|
})
|
|
|
|
describe('user is deleted', () => {
|
|
beforeEach(() => {
|
|
propsData.user.deleted = true
|
|
})
|
|
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.text()).not.toMatch('Tilda Swinton')
|
|
expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym')
|
|
})
|
|
|
|
describe('even if the current user is a moderator', () => {
|
|
beforeEach(() => {
|
|
getters['auth/isModerator'] = () => true
|
|
})
|
|
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.text()).not.toMatch('Tilda Swinton')
|
|
expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('user is disabled', () => {
|
|
beforeEach(() => {
|
|
propsData.user.disabled = true
|
|
})
|
|
|
|
it('renders anonymous user', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.text()).not.toMatch('Tilda Swinton')
|
|
expect(mocks.$t).toHaveBeenCalledWith('profile.userAnonym')
|
|
})
|
|
|
|
describe('current user is a moderator', () => {
|
|
beforeEach(() => {
|
|
getters['auth/isModerator'] = () => true
|
|
})
|
|
|
|
it('renders user name', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.text()).not.toMatch('Anonymous')
|
|
expect(wrapper.text()).toMatch('Tilda Swinton')
|
|
})
|
|
|
|
it('has "disabled-content" class', () => {
|
|
const wrapper = Wrapper()
|
|
expect(wrapper.classes()).toContain('disabled-content')
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|