admin-fe/test/views/settings/index.test.js

88 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2020-03-16 19:47:08 +00:00
import Vuex from 'vuex'
import { mount, createLocalVue, config } from '@vue/test-utils'
import Element from 'element-ui'
import Settings from '@/views/settings/index'
import flushPromises from 'flush-promises'
import app from '@/store/modules/app'
import settings from '@/store/modules/settings'
2020-09-18 22:46:37 +00:00
import user from '@/store/modules/user'
2020-03-19 22:06:22 +00:00
import getters from '@/store/getters'
2021-02-06 23:39:36 +00:00
import _ from 'lodash'
2020-03-16 19:47:08 +00:00
config.mocks["$t"] = () => {}
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(Element)
2020-10-13 13:00:19 +00:00
jest.mock('@/api/app')
jest.mock('@/api/nodeInfo')
jest.mock('@/api/settings')
2020-03-16 19:47:08 +00:00
describe('Settings search', () => {
let store
let actions
2020-04-17 22:27:00 +00:00
let appActions
2021-02-06 23:39:36 +00:00
let $route
let $router
2020-03-16 19:47:08 +00:00
beforeEach(() => {
2020-04-17 22:27:00 +00:00
appActions = { ...app.actions, NeedReboot: jest.fn() }
actions = { ...settings.actions, FetchSettings: jest.fn(), GetNodeInfo: jest.fn() }
store = new Vuex.Store({
modules: {
2020-04-17 22:27:00 +00:00
app: { ...app, actions: appActions },
2020-09-18 22:46:37 +00:00
settings: { ...settings, actions },
user: { ...user, state: { ...user.state, authHost: 'localhost:4000' }}
},
getters
})
2021-02-06 23:39:36 +00:00
$route = { path: '/settings/path' }
2021-02-11 22:15:17 +00:00
$router = { push: jest.fn(), currentRoute: {} }
2020-03-16 19:47:08 +00:00
})
it('shows search input', async (done) => {
const wrapper = mount(Settings, {
store,
2021-02-06 23:39:36 +00:00
mocks: {
$route,
$router
},
2020-03-16 19:47:08 +00:00
localVue
})
await flushPromises()
const searchInput = wrapper.find('.settings-search-input')
expect(searchInput.exists()).toBe(true)
done()
})
2021-02-11 22:15:17 +00:00
it('changes tab when search value was selected', async (done) => {
const wrapper = mount(Settings, {
store,
2021-02-06 23:39:36 +00:00
mocks: {
$route,
$router
},
localVue
})
wrapper.vm.handleSearchSelect({ group: 'Pleroma.Upload', key: 'Pleroma.Upload' })
2021-02-06 23:39:36 +00:00
expect(store.state.settings.searchQuery).toBe('Pleroma.Upload')
2021-02-11 22:15:17 +00:00
expect($router.push).toHaveBeenCalledWith({ path: '/settings/upload' })
wrapper.vm.handleSearchSelect({ group: ':swoosh', key: ':serve_mailbox' })
2021-02-06 23:39:36 +00:00
expect(store.state.settings.searchQuery).toBe(':serve_mailbox')
2021-02-11 22:15:17 +00:00
expect($router.push).toHaveBeenCalledWith({ path: '/settings/mailer' })
wrapper.vm.handleSearchSelect({ group: ':pleroma', key: ':admin_token' })
2021-02-06 23:39:36 +00:00
expect(store.state.settings.searchQuery).toBe(':admin_token')
2021-02-11 22:15:17 +00:00
expect($router.push).toHaveBeenCalledWith({ path: '/settings/instance' })
wrapper.vm.handleSearchSelect({ group: ':media_proxy', key: ':ssl_options' })
2021-02-06 23:39:36 +00:00
expect(store.state.settings.searchQuery).toBe(':ssl_options')
2021-02-11 22:15:17 +00:00
expect($router.push).toHaveBeenCalledWith({ path: '/settings/media-proxy' })
2020-03-19 22:06:22 +00:00
done()
})
2020-03-16 19:47:08 +00:00
})