mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +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>
144 lines
3.0 KiB
JavaScript
144 lines
3.0 KiB
JavaScript
import { shallowMount, mount, RouterLinkStub } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
import PostTeaser from './PostTeaser.vue'
|
|
|
|
const localVue = global.localVue
|
|
|
|
describe('PostTeaser', () => {
|
|
let store
|
|
let stubs
|
|
let mocks
|
|
let propsData
|
|
let getters
|
|
let actions
|
|
let Wrapper
|
|
let wrapper
|
|
|
|
beforeEach(() => {
|
|
propsData = {
|
|
post: {
|
|
id: 'p23',
|
|
disabled: false,
|
|
shoutedCount: 0,
|
|
commentsCount: 0,
|
|
clickedCount: 0,
|
|
viewedTeaserCount: 0,
|
|
name: 'It is a post',
|
|
author: {
|
|
id: 'u1',
|
|
},
|
|
postType: ['Article'],
|
|
},
|
|
}
|
|
stubs = {
|
|
NuxtLink: RouterLinkStub,
|
|
'client-only': true,
|
|
'v-popover': true,
|
|
}
|
|
mocks = {
|
|
$t: jest.fn(),
|
|
$toast: {
|
|
success: jest.fn(),
|
|
error: jest.fn(),
|
|
},
|
|
$apollo: {
|
|
mutate: jest.fn().mockResolvedValue({
|
|
data: { DeletePost: { id: 'deleted-post-id' } },
|
|
}),
|
|
},
|
|
}
|
|
getters = {
|
|
'auth/isModerator': () => false,
|
|
'auth/user': () => {
|
|
return {}
|
|
},
|
|
'categories/categoriesActive': () => false,
|
|
}
|
|
actions = {
|
|
'categories/init': jest.fn(),
|
|
}
|
|
})
|
|
|
|
describe('shallowMount', () => {
|
|
Wrapper = () => {
|
|
store = new Vuex.Store({ getters, actions })
|
|
return shallowMount(PostTeaser, {
|
|
store,
|
|
propsData,
|
|
mocks,
|
|
localVue,
|
|
})
|
|
}
|
|
|
|
it('has no validation errors', () => {
|
|
const spy = jest.spyOn(global.console, 'error')
|
|
Wrapper()
|
|
expect(spy).not.toHaveBeenCalled()
|
|
spy.mockReset()
|
|
})
|
|
|
|
beforeEach(() => {
|
|
jest.useFakeTimers()
|
|
})
|
|
|
|
describe('test Post callbacks', () => {
|
|
beforeEach(() => {
|
|
wrapper = Wrapper()
|
|
})
|
|
|
|
describe('deletion of Post from Page by invoking "deletePostCallback()"', () => {
|
|
beforeEach(() => {
|
|
wrapper.vm.deletePostCallback()
|
|
})
|
|
|
|
describe('after timeout', () => {
|
|
beforeEach(jest.runAllTimers)
|
|
|
|
it('does call mutation', () => {
|
|
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('mutation is successful', () => {
|
|
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('emits "removePostFromList"', () => {
|
|
expect(wrapper.emitted('removePostFromList')).toEqual([[{ id: 'deleted-post-id' }]])
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('mount', () => {
|
|
Wrapper = () => {
|
|
const store = new Vuex.Store({
|
|
getters,
|
|
actions,
|
|
})
|
|
return mount(PostTeaser, {
|
|
stubs,
|
|
mocks,
|
|
propsData,
|
|
store,
|
|
localVue,
|
|
})
|
|
}
|
|
|
|
describe('given a post', () => {
|
|
beforeEach(() => {
|
|
propsData.post = {
|
|
...propsData.post,
|
|
title: "It's a title",
|
|
}
|
|
})
|
|
|
|
it('renders title', () => {
|
|
expect(Wrapper().text()).toContain("It's a title")
|
|
})
|
|
})
|
|
})
|
|
})
|