From 6ec7d89a916d026f5413b82f6c3564f777601e50 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 11 May 2020 21:20:52 +0300 Subject: [PATCH] Add test for running on mounted actions in Statuses --- src/api/__mocks__/peers.js | 4 +++ src/api/__mocks__/status.js | 8 ++++++ test/views/statuses/index.test.js | 41 +++++++++++++++++++++++++++++++ test/views/statuses/store.conf.js | 17 +++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/api/__mocks__/peers.js create mode 100644 test/views/statuses/index.test.js create mode 100644 test/views/statuses/store.conf.js diff --git a/src/api/__mocks__/peers.js b/src/api/__mocks__/peers.js new file mode 100644 index 00000000..da61938f --- /dev/null +++ b/src/api/__mocks__/peers.js @@ -0,0 +1,4 @@ +export async function fetchPeers(authHost, token) { + const data = ['lain.com', 'heaven.com'] + return Promise.resolve({ data }) +} diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index 0e7bc9fb..88623f33 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -5,3 +5,11 @@ export async function changeStatusScope(id, sensitive, visibility, authHost, tok 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 } + } + return Promise.resolve({ data }) +} diff --git a/test/views/statuses/index.test.js b/test/views/statuses/index.test.js new file mode 100644 index 00000000..d8ff6321 --- /dev/null +++ b/test/views/statuses/index.test.js @@ -0,0 +1,41 @@ +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 './store.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('fetches peers and statuses count', async (done) => { + mount(Statuses, { + store, + localVue + }) + + await flushPromises() + const statusVisibilityCount = store.state.status.statusVisibility + expect(statusVisibilityCount.direct).toEqual(4) + expect(statusVisibilityCount.private).toEqual(10) + expect(statusVisibilityCount.public).toEqual(4) + expect(statusVisibilityCount.unlisted).toEqual(10) + done() + }) +}) diff --git a/test/views/statuses/store.conf.js b/test/views/statuses/store.conf.js new file mode 100644 index 00000000..0876f9d2 --- /dev/null +++ b/test/views/statuses/store.conf.js @@ -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, + user + }, + getters +}