mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
* after authentification, query the categories if active and store them * get categories from store * use category store to get categories * get categories from store * mock store to have access to categories * to get rid of the active categories config variable in the frontend, the Category query returns an empty array when categories are not active * remove CATEGORIES_ACTIVE from .env * should return string to avoid warnings in console * replace all env calls for categories active by getter from store * use categoriesActive getter * ignore order of returned categories * mixin to get the category infos from the store, to ensure, that the quey has been called * fix misspelling --------- Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
import Vuex from 'vuex'
|
|
import { mount } from '@vue/test-utils'
|
|
import _id from './_id.vue'
|
|
|
|
const localVue = global.localVue
|
|
|
|
describe('post/_id.vue', () => {
|
|
let wrapper
|
|
let mocks
|
|
let store
|
|
let asyncData
|
|
let error
|
|
let userId
|
|
let authorId
|
|
|
|
beforeEach(() => {
|
|
asyncData = false
|
|
error = jest.fn()
|
|
})
|
|
|
|
describe('mount', () => {
|
|
const Wrapper = async () => {
|
|
mocks = {
|
|
$t: jest.fn(),
|
|
$i18n: {
|
|
locale: () => 'en',
|
|
},
|
|
apolloProvider: {
|
|
defaultClient: {
|
|
query: jest.fn().mockResolvedValue({
|
|
data: {
|
|
Post: [
|
|
{
|
|
author: { id: authorId },
|
|
postType: ['Article'],
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
store = new Vuex.Store({
|
|
getters: {
|
|
'auth/user': () => {
|
|
return { id: userId }
|
|
},
|
|
'categories/categories': jest.fn(() => []),
|
|
'categories/categoriesActive': () => false,
|
|
},
|
|
actions: {
|
|
'categories/init': jest.fn(),
|
|
},
|
|
})
|
|
if (asyncData) {
|
|
const data = _id.data ? _id.data() : {}
|
|
const aData = await _id.asyncData({
|
|
app: mocks,
|
|
store,
|
|
error,
|
|
params: { id: '123' },
|
|
})
|
|
_id.data = function () {
|
|
return { ...data, ...aData }
|
|
}
|
|
}
|
|
return mount(_id, { store, mocks, localVue })
|
|
}
|
|
|
|
it('renders', async () => {
|
|
asyncData = false
|
|
wrapper = await Wrapper()
|
|
expect(wrapper.findAll('.contribution-form')).toHaveLength(1)
|
|
})
|
|
|
|
it('renders with asyncData of different users', async () => {
|
|
asyncData = true
|
|
authorId = 'some-author'
|
|
userId = 'some-user'
|
|
wrapper = await Wrapper()
|
|
expect(error).toHaveBeenCalledWith({
|
|
message: 'error-pages.cannot-edit-post',
|
|
statusCode: 403,
|
|
})
|
|
})
|
|
|
|
it('renders with asyncData of same user', async () => {
|
|
asyncData = true
|
|
authorId = 'some-author'
|
|
userId = 'some-author'
|
|
wrapper = await Wrapper()
|
|
expect(error).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
})
|