blessing-skin-server/resources/assets/tests/views/admin/Market.test.ts
2019-04-23 11:47:45 +08:00

103 lines
3.0 KiB
TypeScript

import Vue from 'vue'
import { mount } from '@vue/test-utils'
import Market from '@/views/admin/Market.vue'
import { flushPromises } from '../../utils'
test('render dependencies', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{ name: 'a', dependencies: { requirements: [] } },
{
name: 'b',
dependencies: {
requirements: { a: '^1.0.0', c: '^2.0.0' }, unsatisfiedRequirements: { c: {} },
},
},
])
const wrapper = mount(Market)
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')
})
test('render operation buttons', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a', dependencies: { requirements: [] }, installed: true, update_available: true,
},
{
name: 'b', dependencies: { requirements: [] }, installed: true, enabled: true,
},
{
name: 'c', dependencies: { requirements: [] }, installed: true,
},
{
name: 'd', dependencies: { requirements: [] }, installed: false,
},
])
const wrapper = mount(Market)
await flushPromises()
const tbody = wrapper.find('tbody')
expect(tbody.find('tr:nth-child(1)').text()).toContain('admin.updatePlugin')
expect(tbody.find('tr:nth-child(2)').text()).toContain('admin.statusEnabled')
expect(tbody.find('tr:nth-child(3)').text()).toContain('admin.enablePlugin')
expect(tbody.find('tr:nth-child(4)').text()).toContain('admin.installPlugin')
})
test('install plugin', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'd', dependencies: { requirements: [] }, installed: false,
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Market)
await flushPromises()
const button = wrapper.find('button')
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/market/download',
{ name: 'd' }
)
button.trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('admin.enablePlugin')
})
test('update plugin', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a',
version: '2.0.0',
dependencies: { requirements: [] },
installed: '1.0.0',
update_available: true,
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' })
Vue.prototype.$confirm
.mockRejectedValueOnce('')
.mockResolvedValue('confirm')
const wrapper = mount(Market)
await flushPromises()
const button = wrapper.find('button')
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/market/download',
{ name: 'a' }
)
})