blessing-skin-server/resources/assets/tests/views/admin/Plugins.test.ts

159 lines
4.7 KiB
TypeScript
Raw Normal View History

2019-03-15 11:42:41 +08:00
import Vue from 'vue'
import { mount } from '@vue/test-utils'
2019-03-18 15:00:18 +08:00
import Plugins from '@/views/admin/Plugins.vue'
2019-03-15 11:42:41 +08:00
import { flushPromises } from '../../utils'
2018-08-19 17:39:33 +08:00
2019-03-28 16:37:01 +08:00
jest.mock('@/scripts/notify')
2018-08-19 17:39:33 +08:00
test('render dependencies', async () => {
2019-03-15 11:42:41 +08:00
Vue.prototype.$http.get.mockResolvedValue([
2019-08-13 18:42:17 +08:00
{ name: 'a', dependencies: { all: {}, unsatisfied: {} } },
2019-03-15 11:42:41 +08:00
{
name: 'b',
dependencies: {
2019-08-13 18:42:17 +08:00
all: { a: '^1.0.0', c: '^2.0.0' }, unsatisfied: { c: '' },
2019-03-15 11:42:41 +08:00
},
},
])
const wrapper = mount(Plugins)
await flushPromises()
expect(wrapper.text()).toContain('admin.noDependencies')
expect(wrapper.find('span.label.bg-green').text()).toBe('a: ^1.0.0')
expect(wrapper.find('span.label.bg-red').text()).toBe('c: ^2.0.0')
})
2019-03-17 10:21:18 +08:00
2018-08-19 17:39:33 +08:00
test('render operation buttons', async () => {
2019-03-15 11:42:41 +08:00
Vue.prototype.$http.get.mockResolvedValue([
{
2019-08-13 18:42:17 +08:00
name: 'a', dependencies: { all: {}, unsatisfied: {} }, enabled: true, config: true,
2019-03-15 11:42:41 +08:00
},
{
2019-08-13 18:42:17 +08:00
name: 'b', dependencies: { all: {}, unsatisfied: {} }, enabled: true, config: false,
2019-03-15 11:42:41 +08:00
},
{
2019-08-13 18:42:17 +08:00
name: 'c', dependencies: { all: {}, unsatisfied: {} }, enabled: false,
2019-03-15 11:42:41 +08:00
},
])
const wrapper = mount(Plugins)
await flushPromises()
const tbody = wrapper.find('tbody')
expect(tbody.find('tr:nth-child(1)').text()).toContain('admin.disablePlugin')
expect(tbody.find('tr:nth-child(1)').text()).toContain('admin.configurePlugin')
expect(tbody.find('tr:nth-child(2)').text()).not.toContain('admin.configurePlugin')
expect(tbody.find('tr:nth-child(3)').text()).toContain('admin.enablePlugin')
expect(tbody.find('tr:nth-child(3)').text()).toContain('admin.deletePlugin')
})
2019-03-17 10:21:18 +08:00
2018-08-19 17:39:33 +08:00
test('enable plugin', async () => {
2019-03-15 11:42:41 +08:00
Vue.prototype.$http.get.mockResolvedValue([
{
2019-08-13 18:42:17 +08:00
name: 'a', dependencies: { all: {}, unsatisfied: {} }, enabled: false,
2019-03-15 11:42:41 +08:00
},
{
2019-08-15 11:57:55 +08:00
name: 'b', dependencies: { all: { c: '' }, unsatisfied: {} }, enabled: false,
2019-03-15 11:42:41 +08:00
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({
2019-08-25 15:54:29 +08:00
code: 1, message: '1', data: { reason: ['abc'] },
2019-03-15 11:42:41 +08:00
})
2019-04-23 11:47:45 +08:00
.mockResolvedValue({ code: 0, message: '0' })
2019-03-25 22:01:57 +08:00
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
2019-03-15 11:42:41 +08:00
const wrapper = mount(Plugins)
await flushPromises()
wrapper.findAll('.actions').at(0)
.find('a')
.trigger('click')
await flushPromises()
2019-03-25 22:01:57 +08:00
expect(Vue.prototype.$confirm).toBeCalledWith('admin.noDependenciesNotice', {
2019-03-15 11:42:41 +08:00
type: 'warning',
})
expect(Vue.prototype.$http.post).not.toBeCalled()
wrapper.findAll('.actions').at(0)
.find('a')
.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'enable', name: 'a' }
)
2019-08-25 15:54:29 +08:00
expect(Vue.prototype.$alert).toBeCalledWith('', ({
type: 'warning',
2019-08-25 17:32:39 +08:00
message: expect.anything(),
2019-08-25 15:54:29 +08:00
}))
2019-03-15 11:42:41 +08:00
wrapper.findAll('.actions').at(1)
.find('a')
.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('admin.disablePlugin')
})
2019-03-17 10:21:18 +08:00
2018-08-19 17:39:33 +08:00
test('disable plugin', async () => {
2019-03-15 11:42:41 +08:00
Vue.prototype.$http.get.mockResolvedValue([
{
2019-08-13 18:42:17 +08:00
name: 'a', dependencies: { all: {}, unsatisfied: {} }, enabled: true, config: false,
2019-03-15 11:42:41 +08:00
},
])
Vue.prototype.$http.post
2019-04-23 11:47:45 +08:00
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
2019-03-15 11:42:41 +08:00
const wrapper = mount(Plugins)
await flushPromises()
const button = wrapper.find('.actions').find('a')
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'disable', name: 'a' }
)
button.trigger('click')
await flushPromises()
2019-03-25 22:01:57 +08:00
expect(Vue.prototype.$message.success).toBeCalledWith('0')
2019-03-15 11:42:41 +08:00
expect(wrapper.text()).toContain('admin.enablePlugin')
})
2019-03-17 10:21:18 +08:00
2018-08-19 17:39:33 +08:00
test('delete plugin', async () => {
2019-03-15 11:42:41 +08:00
Vue.prototype.$http.get.mockResolvedValue([
{
2019-08-13 18:42:17 +08:00
name: 'a', dependencies: { all: {}, unsatisfied: {} }, enabled: false,
2019-03-15 11:42:41 +08:00
},
])
Vue.prototype.$http.post
2019-04-23 11:47:45 +08:00
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
2019-03-25 22:01:57 +08:00
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
2019-03-15 11:42:41 +08:00
const wrapper = mount(Plugins)
await flushPromises()
const button = wrapper.find('.actions').findAll('a')
.at(1)
button.trigger('click')
await flushPromises()
2019-03-25 22:01:57 +08:00
expect(Vue.prototype.$confirm).toBeCalledWith('admin.confirmDeletion', {
2019-03-15 11:42:41 +08:00
type: 'warning',
})
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'delete', name: 'a' }
)
2019-03-25 22:01:57 +08:00
expect(Vue.prototype.$message.warning).toBeCalledWith('1')
2019-03-15 11:42:41 +08:00
button.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('No data')
})