mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
add filter by posts in my groups to store and test it
This commit is contained in:
parent
77ca09ed04
commit
d2462c34f1
@ -30,6 +30,19 @@ export const mutations = {
|
||||
}
|
||||
}
|
||||
},
|
||||
TOGGLE_FILTER_BY_MY_GROUPS(state) {
|
||||
const filter = clone(state.filter)
|
||||
const status = get(filter, 'postsInMyGroups')
|
||||
if (status) {
|
||||
delete filter.postsInMyGroups
|
||||
state.filter = filter
|
||||
} else {
|
||||
state.filter = {
|
||||
...filter,
|
||||
postsInMyGroups: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
RESET_CATEGORIES(state) {
|
||||
const filter = clone(state.filter)
|
||||
delete filter.categories_some
|
||||
@ -84,6 +97,9 @@ export const getters = {
|
||||
filteredByUsersFollowed(state) {
|
||||
return !!get(state.filter, 'author.followedBy_some.id')
|
||||
},
|
||||
filteredByPostsInMyGroups(state) {
|
||||
return !!get(state.filter, 'postsInMyGroups')
|
||||
},
|
||||
filteredByEmotions(state) {
|
||||
return get(state.filter, 'emotions_some.emotion_in') || []
|
||||
},
|
||||
|
||||
@ -56,6 +56,18 @@ describe('getters', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('filteredByPostsInMyGroups', () => {
|
||||
it('returns true if filter is set', () => {
|
||||
state = { filter: { postsInMyGroups: true } }
|
||||
expect(getters.filteredByPostsInMyGroups(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false if filter is not set', () => {
|
||||
state = { filter: { categories_some: { id_in: [23] } } }
|
||||
expect(getters.filteredByUsersFollowed(state)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('filteredByEmotions', () => {
|
||||
it('returns an emotions array if filter is set', () => {
|
||||
state = { filter: { emotions_some: { emotion_in: ['sad'] } } }
|
||||
@ -230,6 +242,35 @@ describe('mutations', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('TOGGLE_FILTER_BY_MY_GROUPS', () => {
|
||||
beforeEach(() => {
|
||||
testMutation = () => {
|
||||
mutations.TOGGLE_FILTER_BY_MY_GROUPS(state)
|
||||
return getters.filter(state)
|
||||
}
|
||||
})
|
||||
|
||||
describe('given empty filter', () => {
|
||||
beforeEach(() => {
|
||||
state = { filter: {} }
|
||||
})
|
||||
|
||||
it('sets postsInMyGroups filter to true', () => {
|
||||
expect(testMutation()).toEqual({ postsInMyGroups: true })
|
||||
})
|
||||
})
|
||||
|
||||
describe('already filtered', () => {
|
||||
beforeEach(() => {
|
||||
state = { filter: { postsInMyGroups: true } }
|
||||
})
|
||||
|
||||
it('removes postsInMyGroups filter', () => {
|
||||
expect(testMutation()).toEqual({})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('TOGGLE_ORDER', () => {
|
||||
beforeEach(() => {
|
||||
testMutation = (key) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user