mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Allow filter by multiple emotions, test getters
- Co-authored-by: vardyb <brent.vardy@challengelogic.net> - Co-aurhored-by: mike aono <aonomike@gmail.com>
This commit is contained in:
parent
07c58fc03e
commit
30ea892aa1
@ -16,7 +16,7 @@ input _EMOTEDInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input _PostEMOTEDFilter {
|
input _PostEMOTEDFilter {
|
||||||
emotion: Emotion
|
emotion_in: [Emotion]
|
||||||
createdAt: String
|
createdAt: String
|
||||||
updatedAt: String
|
updatedAt: String
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ describe('FilterPosts.vue', () => {
|
|||||||
},
|
},
|
||||||
'postsFilter/filteredCategoryIds': jest.fn(() => []),
|
'postsFilter/filteredCategoryIds': jest.fn(() => []),
|
||||||
'postsFilter/filteredByUsersFollowed': jest.fn(),
|
'postsFilter/filteredByUsersFollowed': jest.fn(),
|
||||||
'postsFilter/filteredByEmotions': jest.fn(() => jest.fn()),
|
'postsFilter/filteredByEmotions': jest.fn(() => []),
|
||||||
}
|
}
|
||||||
const openFilterPosts = () => {
|
const openFilterPosts = () => {
|
||||||
const store = new Vuex.Store({ mutations, getters })
|
const store = new Vuex.Store({ mutations, getters })
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
</ds-flex-item>
|
</ds-flex-item>
|
||||||
</ds-flex>
|
</ds-flex>
|
||||||
</ds-flex-item>
|
</ds-flex-item>
|
||||||
<div v-for="emotion in Object.keys(PostsEmotionsCountByEmotion)" :key="emotion">
|
<div v-for="emotion in emotionsArray" :key="emotion">
|
||||||
<ds-flex-item :width="{ lg: '100%' }">
|
<ds-flex-item :width="{ lg: '100%' }">
|
||||||
<ds-button
|
<ds-button
|
||||||
size="large"
|
size="large"
|
||||||
@ -60,7 +60,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
PostsEmotionsCountByEmotion: { funny: 0, happy: 0, surprised: 0, cry: 0, angry: 0 },
|
emotionsArray: ['funny', 'happy', 'surprised', 'cry', 'angry'],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -75,7 +75,7 @@ export default {
|
|||||||
toogleFilteredByEmotions: 'postsFilter/TOGGLE_FILTER_BY_EMOTIONS',
|
toogleFilteredByEmotions: 'postsFilter/TOGGLE_FILTER_BY_EMOTIONS',
|
||||||
}),
|
}),
|
||||||
iconPath(emotion) {
|
iconPath(emotion) {
|
||||||
if (this.filteredByEmotions(emotion)) {
|
if (this.filteredByEmotions.includes(emotion)) {
|
||||||
return `/img/svg/emoji/${emotion}_color.svg`
|
return `/img/svg/emoji/${emotion}_color.svg`
|
||||||
}
|
}
|
||||||
return `/img/svg/emoji/${emotion}.svg`
|
return `/img/svg/emoji/${emotion}.svg`
|
||||||
|
|||||||
@ -42,16 +42,9 @@ export const mutations = {
|
|||||||
},
|
},
|
||||||
TOGGLE_FILTER_BY_EMOTIONS(state, emotion) {
|
TOGGLE_FILTER_BY_EMOTIONS(state, emotion) {
|
||||||
const filter = clone(state.filter)
|
const filter = clone(state.filter)
|
||||||
const emotionName = get(filter, 'emotions_in.emotions')
|
update(filter, 'emotions_some.emotion_in', emotions => xor(emotions, [emotion]))
|
||||||
if (emotionName) {
|
if (isEmpty(get(filter, 'emotions_some.emotion_in'))) delete filter.emotions_some
|
||||||
delete filter.emotions_in
|
state.filter = filter
|
||||||
state.filter = filter
|
|
||||||
} else {
|
|
||||||
state.filter = {
|
|
||||||
...filter,
|
|
||||||
emotions_in: { emotion: emotion },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +61,7 @@ export const getters = {
|
|||||||
filteredByUsersFollowed(state) {
|
filteredByUsersFollowed(state) {
|
||||||
return !!get(state.filter, 'author.followedBy_some.id')
|
return !!get(state.filter, 'author.followedBy_some.id')
|
||||||
},
|
},
|
||||||
filteredByEmotions: state => emotion => {
|
filteredByEmotions(state) {
|
||||||
return get(state.filter, 'emotions_in.emotion') === emotion
|
return get(state.filter, 'emotions_some.emotion_in') || []
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,6 +43,30 @@ describe('getters', () => {
|
|||||||
expect(getters.filteredByUsersFollowed(state)).toBe(false)
|
expect(getters.filteredByUsersFollowed(state)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('filteredByEmotions', () => {
|
||||||
|
it('returns an emotions array if filter is set', () => {
|
||||||
|
state = { filter: { emotions_some: { emotion_in: ['sad'] } } }
|
||||||
|
expect(getters.filteredByEmotions(state)).toEqual(['sad'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns an emotions array even when other filters are set', () => {
|
||||||
|
state = {
|
||||||
|
filter: { emotions_some: { emotion_in: ['sad'] }, categories_some: { id_in: [23] } },
|
||||||
|
}
|
||||||
|
expect(getters.filteredByEmotions(state)).toEqual(['sad'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns empty array if filter is not set', () => {
|
||||||
|
state = { filter: {} }
|
||||||
|
expect(getters.filteredByEmotions(state)).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns empty array if another filter is set, but not emotions', () => {
|
||||||
|
state = { filter: { categories_some: { id_in: [23] } } }
|
||||||
|
expect(getters.filteredByEmotions(state)).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mutations', () => {
|
describe('mutations', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user