From e1b9ccdef1d235965f24b331fb91fa260e585927 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 8 Sep 2020 17:24:37 +0300 Subject: [PATCH] First green test --- src/api/__mocks__/mediaProxyCache.js | 20 ++++++++++++ test/views/mediaProxyCache/index.test.js | 40 ++++++++++++++++++++++++ test/views/mediaProxyCache/store.conf.js | 21 +++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/api/__mocks__/mediaProxyCache.js create mode 100644 test/views/mediaProxyCache/index.test.js create mode 100644 test/views/mediaProxyCache/store.conf.js diff --git a/src/api/__mocks__/mediaProxyCache.js b/src/api/__mocks__/mediaProxyCache.js new file mode 100644 index 00000000..6849c8a7 --- /dev/null +++ b/src/api/__mocks__/mediaProxyCache.js @@ -0,0 +1,20 @@ +const urls = [ + 'http://example.com/media/a688346.jpg', + 'http://example.com/media/fb1f4d.jpg' +] + +export async function listBannedUrls(page, pageSize, authHost, token) { + return Promise.resolve({ data: { page_size: 1, count: 2, urls }}) +} + +export async function purgeUrls(urls, ban, authHost, token) { + return Promise.resolve() +} + +export async function removeBannedUrls(urls, authHost, token) { + return Promise.resolve() +} + +export async function searchBannedUrls(query, page, pageSize, authHost, token) { + +} diff --git a/test/views/mediaProxyCache/index.test.js b/test/views/mediaProxyCache/index.test.js new file mode 100644 index 00000000..ac397c4f --- /dev/null +++ b/test/views/mediaProxyCache/index.test.js @@ -0,0 +1,40 @@ +import Vuex from 'vuex' +import { mount, createLocalVue, config } from '@vue/test-utils' +import flushPromises from 'flush-promises' +import Element from 'element-ui' +import MediaProxyCache from '@/views/mediaProxyCache/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/nodeInfo') +jest.mock('@/api/mediaProxyCache') +jest.mock('@/api/settings') + +describe('', () => { + let store + + beforeEach(() => { + store = new Vuex.Store(cloneDeep(storeConfig)) + }) + + it('fetches initial list of urls', async (done) => { + const wrapper = mount(MediaProxyCache, { + store, + localVue, + sync: false + }) + + await flushPromises() + console.log(store.state) + console.log(wrapper.html()) + expect(wrapper.vm.urlsCount).toEqual(2) + done() + }) +}) \ No newline at end of file diff --git a/test/views/mediaProxyCache/store.conf.js b/test/views/mediaProxyCache/store.conf.js new file mode 100644 index 00000000..199fc904 --- /dev/null +++ b/test/views/mediaProxyCache/store.conf.js @@ -0,0 +1,21 @@ +import app from '@/store/modules/app' +import mediaProxyCache from '@/store/modules/mediaProxyCache' +import user from '@/store/modules/user' +import users from '@/store/modules/users' +import reports from '@/store/modules/reports' +import settings from '@/store/modules/settings' +import status from '@/store/modules/status' +import getters from '@/store/getters' + +export default { + modules: { + app, + mediaProxyCache, + user, + users, + reports, + settings, + status + }, + getters +}