Add test for pagination on Statuses page

This commit is contained in:
Angelina Filippova 2020-05-13 01:45:34 +03:00
parent bcc1ea16ff
commit cb99014af5
3 changed files with 115 additions and 27 deletions

View file

@ -7,34 +7,52 @@ export async function deleteStatus(id, authHost, token) {
} }
export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) {
const data = [ let data
{ if (pageSize === 1) {
'account': { data = page === 1 || page === 2
'avatar': 'http://localhost:4000/images/avi.png', ? [{
'display_name': 'sky', 'account': {
'url': 'http://localhost:4000/users/sky' 'avatar': 'http://localhost:4000/images/avi.png',
'display_name': 'sky',
'url': 'http://localhost:4000/users/sky'
},
'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.',
'created_at': '2020-01-31T18:20:01.000Z',
'id': '9rZIr0Jzao5Gjgfmro',
'sensitive': false,
'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98',
'visibility': 'unlisted'
}]
: []
} else {
data = [
{
'account': {
'avatar': 'http://localhost:4000/images/avi.png',
'display_name': 'sky',
'url': 'http://localhost:4000/users/sky'
},
'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.',
'created_at': '2020-01-31T18:20:01.000Z',
'id': '9rZIr0Jzao5Gjgfmro',
'sensitive': false,
'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98',
'visibility': 'unlisted'
}, },
'content': 'A nice young couple contacted us from Brazil to decorate their newly acquired apartment.', {
'created_at': '2020-01-31T18:20:01.000Z', 'account': {
'id': '9rZIr0Jzao5Gjgfmro', 'avatar': 'http://localhost:4000/images/avi.png',
'sensitive': false, 'display_name': 'sky',
'url': 'http://localhost:4000/objects/7af9abbd-fb6c-4318-aeb7-6636c138ac98', 'url': 'http://localhost:4000/users/sky'
'visibility': 'unlisted' },
}, 'content': 'the happiest man ever',
{ 'created_at': '2019-11-23T12:56:18.000Z',
'account': { 'id': '9pFoVfWMU3A96Rzq3k',
'avatar': 'http://localhost:4000/images/avi.png', 'sensitive': false,
'display_name': 'sky', 'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25',
'url': 'http://localhost:4000/users/sky' 'visibility': 'unlisted'
}, }]
'content': 'the happiest man ever', }
'created_at': '2019-11-23T12:56:18.000Z',
'id': '9pFoVfWMU3A96Rzq3k',
'sensitive': false,
'url': 'http://localhost:4000/objects/449c90fe-c457-4c64-baf2-fe6d0a59ca25',
'visibility': 'unlisted'
}
]
return Promise.resolve({ data }) return Promise.resolve({ data })
} }

View file

@ -0,0 +1,53 @@
import Vuex from 'vuex'
import { mount, createLocalVue, config } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import Element from 'element-ui'
import Statuses from '@/views/statuses/index'
import storeConfig from './storeForPagination.conf'
import { cloneDeep } from 'lodash'
config.mocks["$t"] = () => {}
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(Element)
jest.mock('@/api/app')
jest.mock('@/api/status')
jest.mock('@/api/peers')
jest.mock('@/api/nodeInfo')
describe('Statuses', () => {
let store
beforeEach(() => {
store = new Vuex.Store(cloneDeep(storeConfig))
})
it('pagination', async (done) => {
const wrapper = mount(Statuses, {
store,
localVue
})
await flushPromises()
store.dispatch('HandleFilterChange', 'heaven.com')
wrapper.vm.handleFilterChange()
await flushPromises()
expect(store.state.status.statusesByInstance.allLoaded).toBe(false)
expect(store.state.status.statusesByInstance.page).toBe(1)
wrapper.find('.statuses-pagination button').trigger('click')
await flushPromises()
expect(store.state.status.statusesByInstance.allLoaded).toBe(false)
expect(store.state.status.statusesByInstance.page).toBe(2)
wrapper.find('.statuses-pagination button').trigger('click')
await flushPromises()
expect(store.state.status.statusesByInstance.allLoaded).toBe(true)
done()
})
})

View file

@ -0,0 +1,17 @@
import app from '@/store/modules/app'
import peers from '@/store/modules/peers'
import user from '@/store/modules/user'
import settings from '@/store/modules/settings'
import status from '@/store/modules/status'
import getters from '@/store/getters'
export default {
modules: {
app,
peers,
settings,
status: { ...status, state: { ...status.state, statusesByInstance: { ...status.state.statusesByInstance, pageSize: 1 }}},
user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }}
},
getters
}