diff --git a/webapp/store/posts.js b/webapp/store/posts.js index 5d9891eff..e8602bb13 100644 --- a/webapp/store/posts.js +++ b/webapp/store/posts.js @@ -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') || [] }, diff --git a/webapp/store/posts.spec.js b/webapp/store/posts.spec.js index ed728bdd8..665b147ae 100644 --- a/webapp/store/posts.spec.js +++ b/webapp/store/posts.spec.js @@ -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) => {