mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Tests Added For Language Filter Of Posts
This commit is contained in:
parent
aeae72f691
commit
1dbd36c1e1
@ -3,6 +3,9 @@ import VTooltip from 'v-tooltip'
|
|||||||
import Styleguide from '@human-connection/styleguide'
|
import Styleguide from '@human-connection/styleguide'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import FilterPosts from './FilterPosts.vue'
|
import FilterPosts from './FilterPosts.vue'
|
||||||
|
import locales from '~/locales'
|
||||||
|
import orderBy from 'lodash/orderBy'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
|
|
||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
@ -12,6 +15,8 @@ localVue.use(Vuex)
|
|||||||
let mutations
|
let mutations
|
||||||
let getters
|
let getters
|
||||||
|
|
||||||
|
const languages = orderBy(locales, 'name')
|
||||||
|
|
||||||
describe('FilterPosts.vue', () => {
|
describe('FilterPosts.vue', () => {
|
||||||
let mocks
|
let mocks
|
||||||
let propsData
|
let propsData
|
||||||
@ -20,6 +25,8 @@ describe('FilterPosts.vue', () => {
|
|||||||
let environmentAndNatureButton
|
let environmentAndNatureButton
|
||||||
let democracyAndPoliticsButton
|
let democracyAndPoliticsButton
|
||||||
let happyEmotionButton
|
let happyEmotionButton
|
||||||
|
let englishButton
|
||||||
|
let spanishButton
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks = {
|
mocks = {
|
||||||
@ -54,6 +61,8 @@ describe('FilterPosts.vue', () => {
|
|||||||
'posts/RESET_CATEGORIES': jest.fn(),
|
'posts/RESET_CATEGORIES': jest.fn(),
|
||||||
'posts/TOGGLE_CATEGORY': jest.fn(),
|
'posts/TOGGLE_CATEGORY': jest.fn(),
|
||||||
'posts/TOGGLE_EMOTION': jest.fn(),
|
'posts/TOGGLE_EMOTION': jest.fn(),
|
||||||
|
'posts/TOGGLE_LANGUAGE': jest.fn(),
|
||||||
|
'posts/RESET_LANGUAGES': jest.fn(),
|
||||||
}
|
}
|
||||||
getters = {
|
getters = {
|
||||||
'posts/isActive': () => false,
|
'posts/isActive': () => false,
|
||||||
@ -64,6 +73,7 @@ describe('FilterPosts.vue', () => {
|
|||||||
'posts/filteredCategoryIds': jest.fn(() => []),
|
'posts/filteredCategoryIds': jest.fn(() => []),
|
||||||
'posts/filteredByUsersFollowed': jest.fn(),
|
'posts/filteredByUsersFollowed': jest.fn(),
|
||||||
'posts/filteredByEmotions': jest.fn(() => []),
|
'posts/filteredByEmotions': jest.fn(() => []),
|
||||||
|
'posts/filteredLanguagesCodes': jest.fn(() => []),
|
||||||
}
|
}
|
||||||
const openFilterPosts = () => {
|
const openFilterPosts = () => {
|
||||||
const store = new Vuex.Store({ mutations, getters })
|
const store = new Vuex.Store({ mutations, getters })
|
||||||
@ -97,6 +107,15 @@ describe('FilterPosts.vue', () => {
|
|||||||
expect(mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat4')
|
expect(mutations['posts/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat4')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('calls TOGGLE_LANGUAGE when clicked', () => {
|
||||||
|
const wrapper = openFilterPosts()
|
||||||
|
englishButton = wrapper
|
||||||
|
.findAll('button.language-buttons')
|
||||||
|
.at(languages.findIndex(l => l.code === 'en'))
|
||||||
|
englishButton.trigger('click')
|
||||||
|
expect(mutations['posts/TOGGLE_LANGUAGE']).toHaveBeenCalledWith({}, 'en')
|
||||||
|
})
|
||||||
|
|
||||||
it('sets category button attribute `primary` when corresponding category is filtered', () => {
|
it('sets category button attribute `primary` when corresponding category is filtered', () => {
|
||||||
getters['posts/filteredCategoryIds'] = jest.fn(() => ['cat9'])
|
getters['posts/filteredCategoryIds'] = jest.fn(() => ['cat9'])
|
||||||
const wrapper = openFilterPosts()
|
const wrapper = openFilterPosts()
|
||||||
@ -104,6 +123,15 @@ describe('FilterPosts.vue', () => {
|
|||||||
expect(democracyAndPoliticsButton.attributes().class).toContain('ds-button-primary')
|
expect(democracyAndPoliticsButton.attributes().class).toContain('ds-button-primary')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('sets language button attribute `primary` when corresponding language is filtered', () => {
|
||||||
|
getters['posts/filteredLanguagesCodes'] = jest.fn(() => ['es'])
|
||||||
|
const wrapper = openFilterPosts()
|
||||||
|
spanishButton = wrapper
|
||||||
|
.findAll('button.language-buttons')
|
||||||
|
.at(languages.findIndex(l => l.code === 'es'))
|
||||||
|
expect(spanishButton.attributes().class).toContain('ds-button-primary')
|
||||||
|
})
|
||||||
|
|
||||||
it('sets "filter-by-followed-authors-only" button attribute `primary`', () => {
|
it('sets "filter-by-followed-authors-only" button attribute `primary`', () => {
|
||||||
getters['posts/filteredByUsersFollowed'] = jest.fn(() => true)
|
getters['posts/filteredByUsersFollowed'] = jest.fn(() => true)
|
||||||
const wrapper = openFilterPosts()
|
const wrapper = openFilterPosts()
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
<ds-flex class="languages-menu">
|
<ds-flex class="languages-menu">
|
||||||
<ds-flex-item width="100%" class="language-menu-item">
|
<ds-flex-item width="100%" class="language-menu-item">
|
||||||
<ds-button
|
<ds-button
|
||||||
|
class="language-buttons"
|
||||||
icon="flag"
|
icon="flag"
|
||||||
:primary="filteredLanguagesCodes.includes(language.code)"
|
:primary="filteredLanguagesCodes.includes(language.code)"
|
||||||
@click.stop.prevent="toggleLanguage(language.code)"
|
@click.stop.prevent="toggleLanguage(language.code)"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user