mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
test getters and setters for post type filters
This commit is contained in:
parent
fa4ecaa3f6
commit
153ef7ae14
@ -25,6 +25,18 @@ describe('getters', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('filteredPostTypes', () => {
|
||||
it('returns post types if filter is set', () => {
|
||||
state = { filter: { postType_in: ['Article', 'Event'] } }
|
||||
expect(getters.filteredPostTypes(state)).toEqual(['Article', 'Event'])
|
||||
})
|
||||
|
||||
it('returns empty array if post type filter is not set', () => {
|
||||
state = { filter: { author: { followedBy_some: { id: 7 } } } }
|
||||
expect(getters.filteredPostTypes(state)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('filteredLanguageCodes', () => {
|
||||
it('returns category ids if filter is set', () => {
|
||||
state = { filter: { language_in: ['en', 'de', 'pt'] } }
|
||||
@ -213,6 +225,46 @@ describe('mutations', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('TOGGLE_POST_TYPE', () => {
|
||||
beforeEach(() => {
|
||||
testMutation = (postType) => {
|
||||
mutations.TOGGLE_POST_TYPE(state, postType)
|
||||
return getters.filter(state)
|
||||
}
|
||||
})
|
||||
|
||||
it('creates post type filter if empty', () => {
|
||||
state = { filter: {} }
|
||||
expect(testMutation('Event')).toEqual({ postType_in: ['Event'] })
|
||||
})
|
||||
|
||||
it('adds post type not present', () => {
|
||||
state = { filter: { postType_in: ['Event'] } }
|
||||
expect(testMutation('Article')).toEqual({ postType_in: ['Event', 'Article'] })
|
||||
})
|
||||
|
||||
it('removes category id if present', () => {
|
||||
state = { filter: { postType_in: ['Event', 'Article'] } }
|
||||
const result = testMutation('Event')
|
||||
expect(result).toEqual({ postType_in: ['Article'] })
|
||||
})
|
||||
|
||||
it('removes category filter if empty', () => {
|
||||
state = { filter: { postType_in: ['Event'] } }
|
||||
expect(testMutation('Event')).toEqual({})
|
||||
})
|
||||
|
||||
it('does not get in the way of other filters', () => {
|
||||
state = {
|
||||
filter: {
|
||||
author: { followedBy_some: { id: 7 } },
|
||||
postType_in: ['Event'],
|
||||
},
|
||||
}
|
||||
expect(testMutation('Event')).toEqual({ author: { followedBy_some: { id: 7 } } })
|
||||
})
|
||||
})
|
||||
|
||||
describe('TOGGLE_FILTER_BY_FOLLOWED', () => {
|
||||
beforeEach(() => {
|
||||
testMutation = (userId) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user