diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index 88623f33..afb8363c 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -6,10 +6,47 @@ export async function deleteStatus(id, authHost, token) { return Promise.resolve() } -export async function fetchStatusesCount(instance, authHost, token) { - const data = { - 'status_visibility': - { 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 } - } +export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { + const 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' + }, + { + 'account': { + 'avatar': 'http://localhost:4000/images/avi.png', + 'display_name': 'sky', + 'url': 'http://localhost:4000/users/sky' + }, + '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 }) +} + +export async function fetchStatusesCount(instance, authHost, token) { + const data = instance === 'heaven.com' + ? { + 'status_visibility': + { 'direct': 1, 'private': 2, 'public': 3, 'unlisted': 0 } + } + : { + 'status_visibility': + { 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 } + } return Promise.resolve({ data }) } diff --git a/test/views/statuses/index.test.js b/test/views/statuses/index.test.js index d8ff6321..d83c4960 100644 --- a/test/views/statuses/index.test.js +++ b/test/views/statuses/index.test.js @@ -38,4 +38,24 @@ describe('Statuses', () => { expect(statusVisibilityCount.unlisted).toEqual(10) done() }) + + it('fetches statuses from selected instance and updates the count', async (done) => { + const wrapper = mount(Statuses, { + store, + localVue + }) + await flushPromises() + + store.dispatch('HandleFilterChange', 'heaven.com') + wrapper.vm.handleFilterChange() + await flushPromises() + const statusVisibilityCount = store.state.status.statusVisibility + + expect(statusVisibilityCount.direct).toEqual(1) + expect(statusVisibilityCount.private).toEqual(2) + expect(statusVisibilityCount.public).toEqual(3) + expect(statusVisibilityCount.unlisted).toEqual(0) + expect(store.state.status.fetchedStatuses.length).toEqual(2) + done() + }) }) diff --git a/test/views/statuses/store.conf.js b/test/views/statuses/store.conf.js index 0876f9d2..6e22b617 100644 --- a/test/views/statuses/store.conf.js +++ b/test/views/statuses/store.conf.js @@ -11,7 +11,7 @@ export default { peers, settings, status, - user + user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }} }, getters }