have i18n as option for search groups, fix test

This commit is contained in:
Moriz Wahl 2022-10-23 13:02:04 +02:00
parent e27f9b00e6
commit 88b5fb9b46
3 changed files with 43 additions and 15 deletions

View File

@ -36,6 +36,7 @@ describe('SearchResults', () => {
} }
propsData = { propsData = {
pageSize: 12, pageSize: 12,
search: '',
} }
wrapper = Wrapper() wrapper = Wrapper()
}) })
@ -169,7 +170,7 @@ describe('SearchResults', () => {
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
await expect( await expect(
wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(), wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(),
).toMatchObject({ query: undefined, firstPosts: 12, postsOffset: 12 }) ).toMatchObject({ query: '', firstPosts: 12, postsOffset: 12 })
}) })
it('displays the next page button when next-button is clicked', async () => { it('displays the next page button when next-button is clicked', async () => {
@ -199,7 +200,7 @@ describe('SearchResults', () => {
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
await expect( await expect(
wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(), wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(),
).toMatchObject({ query: undefined, firstPosts: 12, postsOffset: 24 }) ).toMatchObject({ query: '', firstPosts: 12, postsOffset: 24 })
}) })
it('deactivates next page button when next-button is clicked twice', async () => { it('deactivates next page button when next-button is clicked twice', async () => {
@ -234,7 +235,7 @@ describe('SearchResults', () => {
await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
await expect( await expect(
wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(), wrapper.vm.$options.apollo.searchPosts.variables.bind(wrapper.vm)(),
).toMatchObject({ query: undefined, firstPosts: 12, postsOffset: 0 }) ).toMatchObject({ query: '', firstPosts: 12, postsOffset: 0 })
}) })
}) })
}) })

View File

@ -120,6 +120,7 @@ import PaginationButtons from '~/components/_new/generic/PaginationButtons/Pagin
import HcHashtag from '~/components/Hashtag/Hashtag' import HcHashtag from '~/components/Hashtag/Hashtag'
export default { export default {
name: 'SearchResults',
components: { components: {
TabNavigation, TabNavigation,
HcEmpty, HcEmpty,
@ -372,7 +373,7 @@ export default {
}, },
searchGroups: { searchGroups: {
query() { query() {
return searchGroups return searchGroups(this.i18n)
}, },
variables() { variables() {
const { firstGroups, groupsOffset, search } = this const { firstGroups, groupsOffset, search } = this

View File

@ -61,19 +61,45 @@ export const searchPosts = gql`
} }
` `
export const searchGroups = gql` export const searchGroups = (i18n) => {
${groupFragment} const lang = i18n ? i18n.locale().toUpperCase() : 'EN'
return gql`
query ($query: String!, $firstGroups: Int, $groupsOffset: Int) { query ($query: String!, $firstGroups: Int, $groupsOffset: Int) {
searchGroups(query: $query, firstGroups: $firstGroups, groupsOffset: $groupsOffset) { searchGroups(query: $query, firstGroups: $firstGroups, groupsOffset: $groupsOffset) {
groupCount groupCount
groups { groups {
__typename __typename
...group id
name
slug
createdAt
updatedAt
disabled
deleted
about
description
descriptionExcerpt
groupType
actionRadius
categories {
id
slug
name
icon
}
avatar {
url
}
locationName
location {
name: name${lang}
}
myRole
}
} }
} }
} `
` }
export const searchUsers = gql` export const searchUsers = gql`
${userFragment} ${userFragment}