mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
* feat(backend): pin more than one post * add postPinnedCount query, better names for env variable * add store and mixin for pinned posts counts * test pinned post store * context menu for pin posts * fix typos * unpin posts is always possible --------- Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
112 lines
2.7 KiB
JavaScript
112 lines
2.7 KiB
JavaScript
import { state as initialState, mutations, getters, actions } from './pinnedPosts'
|
|
import { postsPinnedCountsQuery } from '~/graphql/PostQuery'
|
|
|
|
describe('pinned post store', () => {
|
|
describe('initial state', () => {
|
|
it('sets all values to 0', () => {
|
|
expect(initialState()).toEqual({
|
|
maxPinnedPosts: 0,
|
|
currentlyPinnedPosts: 0,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('mutations', () => {
|
|
let testMutation
|
|
const state = {
|
|
maxPinnedPosts: 0,
|
|
currentlyPinnedPosts: 0,
|
|
}
|
|
|
|
describe('pinPost', () => {
|
|
it('increments currentlyPinnedPosts', () => {
|
|
testMutation = () => {
|
|
mutations.pinPost(state)
|
|
return getters.currentlyPinnedPosts(state)
|
|
}
|
|
expect(testMutation()).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('unpinPost', () => {
|
|
it('decrements currentlyPinnedPosts', () => {
|
|
state.currentlyPinnedPosts = 2
|
|
testMutation = () => {
|
|
mutations.unpinPost(state)
|
|
return getters.currentlyPinnedPosts(state)
|
|
}
|
|
expect(testMutation()).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('setMaxPinnedPosts', () => {
|
|
it('sets maxPinnedPosts correctly', () => {
|
|
state.maxPinnedPosts = 3
|
|
testMutation = () => {
|
|
mutations.setMaxPinnedPosts(state, 1)
|
|
return getters.maxPinnedPosts(state)
|
|
}
|
|
expect(testMutation()).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('setCurrentlyPinnedPosts', () => {
|
|
it('sets currentlyPinnedPosts', () => {
|
|
state.currentlyPinnedPosts = 3
|
|
testMutation = () => {
|
|
mutations.setCurrentlyPinnedPosts(state, 1)
|
|
return getters.currentlyPinnedPosts(state)
|
|
}
|
|
expect(testMutation()).toBe(1)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('actions', () => {
|
|
const queryMock = jest.fn().mockResolvedValue({
|
|
data: {
|
|
PostsPinnedCounts: {
|
|
maxPinnedPosts: 3,
|
|
currentlyPinnedPosts: 2,
|
|
},
|
|
},
|
|
})
|
|
const commit = jest.fn()
|
|
|
|
let action
|
|
|
|
beforeEach(() => {
|
|
const module = {
|
|
app: {
|
|
apolloProvider: {
|
|
defaultClient: {
|
|
query: queryMock,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
action = actions.fetch.bind(module)
|
|
})
|
|
|
|
describe('fetch', () => {
|
|
beforeEach(async () => {
|
|
await action({ commit })
|
|
})
|
|
|
|
it('calls apollo', () => {
|
|
expect(queryMock).toBeCalledWith({
|
|
query: postsPinnedCountsQuery(),
|
|
})
|
|
})
|
|
|
|
it('commits setMaxPinnedPosts', () => {
|
|
expect(commit).toBeCalledWith('setMaxPinnedPosts', 3)
|
|
})
|
|
|
|
it('commits setCurrentlyPinnedPosts', () => {
|
|
expect(commit).toBeCalledWith('setCurrentlyPinnedPosts', 2)
|
|
})
|
|
})
|
|
})
|
|
})
|