mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
test: user + pagination ok, rest WIP
This commit is contained in:
parent
6e934ed6b2
commit
cccb6cec83
@ -1,14 +1,20 @@
|
||||
import { config, mount } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import SearchResults from './SearchResults'
|
||||
import { post } from '~/components/PostTeaser/PostTeaser.story'
|
||||
import { user } from '~/components/UserTeaser/UserTeaser.story'
|
||||
|
||||
import helpers from '~/storybook/helpers'
|
||||
|
||||
helpers.init()
|
||||
|
||||
|
||||
const localVue = global.localVue
|
||||
localVue.directive('scrollTo', jest.fn())
|
||||
|
||||
config.stubs['client-only'] = '<span><slot /></span>'
|
||||
config.stubs['nuxt-link'] = '<span><slot /></span>'
|
||||
|
||||
|
||||
|
||||
describe('SearchResults', () => {
|
||||
let mocks, getters, propsData, wrapper
|
||||
const Wrapper = () => {
|
||||
@ -44,37 +50,74 @@ describe('SearchResults', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('contains posts', () => {
|
||||
|
||||
describe('contains users less as 25 results', () => {
|
||||
beforeEach(() => {
|
||||
console.log
|
||||
wrapper.setData({ posts: [post], activeTab: 'Post' })
|
||||
wrapper.setData( { users: helpers.fakeUser(1), userCount:1, activeTab: 'User' })
|
||||
})
|
||||
|
||||
it('renders post-teaser component', () => {
|
||||
expect(wrapper.find('.post-teaser').exists()).toBe(true)
|
||||
it('renders pagination', () => {
|
||||
expect(wrapper.find('.pagination-buttons').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('contains users', () => {
|
||||
it('show NOT pagination', () => {
|
||||
|
||||
expect(wrapper.find('.pagination-buttons').attributes().style).toBe('display: none;')
|
||||
|
||||
})
|
||||
|
||||
describe('contains users more as 25 results', () => {
|
||||
beforeEach(() => {
|
||||
wrapper.setData({ users: [user], activeTab: 'User' })
|
||||
wrapper.setData( { users: helpers.fakeUser(52), userCount:52, activeTab: 'User' })
|
||||
})
|
||||
|
||||
it('renders user-list', () => {
|
||||
it('renders user-list pagination', () => {
|
||||
expect(wrapper.find('.user-list').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('switchTab', () => {
|
||||
beforeEach(() => {
|
||||
wrapper.setData({ posts: [post], users: [user], activeTab: 'Post' })
|
||||
wrapper.find('.tab-navigation').vm.$emit('switchTab', 'User')
|
||||
it('renders pagination', () => {
|
||||
expect(wrapper.find('.pagination-buttons').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('switches activeTab when event is emitted', () => {
|
||||
expect(wrapper.find('.user-list').exists()).toBe(true)
|
||||
it('show pagination', () => {
|
||||
|
||||
expect(wrapper.find('.pagination-buttons').attributes().style).toBe('')
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
describe('contains posts', () => {
|
||||
beforeEach(() => {
|
||||
console.log
|
||||
wrapper.setData({ posts: [post], activeTab: 'Post' })
|
||||
})
|
||||
|
||||
it('renders post-teaser component', () => {
|
||||
expect(wrapper.find('.post-teaser').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
/*
|
||||
describe('switchTab', () => {
|
||||
beforeEach(() => {
|
||||
wrapper.setData({ posts: [post], users: [user], activeTab: 'Post' })
|
||||
wrapper.find('.tab-navigation').vm.$emit('switchTab', 'User')
|
||||
})
|
||||
|
||||
it('switches activeTab when event is emitted', () => {
|
||||
expect(wrapper.find('.user-list').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -145,7 +145,6 @@ export default {
|
||||
postsOffset: 0,
|
||||
usersOffset: 0,
|
||||
hashtagsOffset: 0,
|
||||
searchCount: 0,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -198,6 +197,9 @@ export default {
|
||||
hasMoreHashtags() {
|
||||
return (this.hashtagPage + 1) * this.pageSize < this.hashtagCount
|
||||
},
|
||||
searchCount() {
|
||||
return this.postCount + this.userCount + this.hashtagCount
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
clearPage() {
|
||||
@ -252,7 +254,6 @@ export default {
|
||||
update({ searchPosts }) {
|
||||
this.posts = searchPosts.posts
|
||||
this.postCount = searchPosts.postCount
|
||||
this.searchCount = this.postCount + this.userCount + this.hashtagCount
|
||||
this.clearPage()
|
||||
if (this.postCount > 0) this.activeTab = 'Post'
|
||||
},
|
||||
@ -276,7 +277,6 @@ export default {
|
||||
update({ searchUsers }) {
|
||||
this.users = searchUsers.users
|
||||
this.userCount = searchUsers.userCount
|
||||
this.searchCount = this.postCount + this.userCount + this.hashtagCount
|
||||
this.clearPage()
|
||||
if (this.postCount === 0 && this.userCount > 0) this.activeTab = 'User'
|
||||
},
|
||||
@ -300,7 +300,6 @@ export default {
|
||||
update({ searchHashtags }) {
|
||||
this.hashtags = searchHashtags.hashtags
|
||||
this.hashtagCount = searchHashtags.hashtagCount
|
||||
this.searchCount = this.postCount + this.userCount + this.hashtagCount
|
||||
this.clearPage()
|
||||
if (this.postCount === 0 && this.userCount === 0 && this.hashtagCount > 0)
|
||||
this.activeTab = 'Hashtag'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user