From 2621d7cb510c43a64e5537fa46e410e07007d34a Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 24 May 2020 21:14:58 +0300 Subject: [PATCH] First green test, fetches single status --- src/api/__mocks__/status.js | 23 ++++++++++ test/views/statuses/show.test.js | 50 +++++++++++++++++++++ test/views/statuses/statusShowStore.conf.js | 21 +++++++++ test/views/users/show.test.js | 2 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/views/statuses/show.test.js create mode 100644 test/views/statuses/statusShowStore.conf.js diff --git a/src/api/__mocks__/status.js b/src/api/__mocks__/status.js index c8f98545..232ba69a 100644 --- a/src/api/__mocks__/status.js +++ b/src/api/__mocks__/status.js @@ -6,6 +6,29 @@ export async function deleteStatus(id, authHost, token) { return Promise.resolve() } +export async function fetchStatus(id, authHost, token) { + const data = { + account: { + id: '9n1bySks25olxWrku0', + avatar: 'http://localhost:4000/images/avi.png', + display_name: 'dolin', + tags: ['strip_media', 'sandbox', 'disable_any_subscription', 'force_nsfw'], + url: 'http://localhost:4000/users/dolin' + }, + content: 'pizza makes everything better', + created_at: '2020-05-22T17:34:34.000Z', + id: '9vJOO3iFPyjNaEhJ5s', + media_attachments: [], + poll: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + url: 'http://localhost:4000/notice/9vJOO3iFPyjNaEhJ5s' + } + + return Promise.resolve({ data }) +} + export async function fetchStatusesByInstance({ instance, authHost, token, pageSize, page }) { let data if (pageSize === 1) { diff --git a/test/views/statuses/show.test.js b/test/views/statuses/show.test.js new file mode 100644 index 00000000..4aec7c69 --- /dev/null +++ b/test/views/statuses/show.test.js @@ -0,0 +1,50 @@ +import Vuex from 'vuex' +import { mount, createLocalVue, config } from '@vue/test-utils' +import flushPromises from 'flush-promises' +import Element from 'element-ui' +import StatusShow from '@/views/statuses/show' +import storeConfig from './statusShowStore.conf' +import { cloneDeep } from 'lodash' + +config.mocks["$t"] = () => {} + +const localVue = createLocalVue() +localVue.use(Vuex) +localVue.use(Element) + +const $route = { + params: { + id: '9vJOO3iFPyjNaEhJ5s' + } +} + +jest.mock('@/api/app') +jest.mock('@/api/status') +jest.mock('@/api/peers') +jest.mock('@/api/nodeInfo') + +describe('Status show page', () => { + let store + + beforeEach(() => { + store = new Vuex.Store(cloneDeep(storeConfig)) + }) + + it('fetches status', async (done) => { + const wrapper = mount(StatusShow, { + store, + localVue, + sync: false, + stubs: ['router-link'], + mocks: { + $route + } + }) + await flushPromises() + + expect(wrapper.find('.status-container').isVisible()).toBe(true) + expect(store.state.status.fetchedStatus.id).toBe('9vJOO3iFPyjNaEhJ5s') + expect(store.state.status.fetchedStatus.account.display_name).toBe('dolin') + done() + }) +}) diff --git a/test/views/statuses/statusShowStore.conf.js b/test/views/statuses/statusShowStore.conf.js new file mode 100644 index 00000000..c83a8660 --- /dev/null +++ b/test/views/statuses/statusShowStore.conf.js @@ -0,0 +1,21 @@ +import app from '@/store/modules/app' +import peers from '@/store/modules/peers' +import user from '@/store/modules/user' +import userProfile from '@/store/modules/userProfile' +import users from '@/store/modules/users' +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, + userProfile, + users + }, + getters +} diff --git a/test/views/users/show.test.js b/test/views/users/show.test.js index b57501c5..2197d5f6 100644 --- a/test/views/users/show.test.js +++ b/test/views/users/show.test.js @@ -21,7 +21,7 @@ const $route = { jest.mock('@/api/nodeInfo') jest.mock('@/api/users') -describe('Search and filter users', () => { +describe('User profile', () => { let store beforeEach(() => {