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

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-03-15 11:42:41 +08:00
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
2019-03-18 15:00:18 +08:00
import Update from '@/views/admin/Update.vue'
2018-09-13 18:10:23 +08:00
afterEach(() => {
2019-03-15 11:42:41 +08:00
window.blessing.extra = { canUpdate: true }
})
2018-09-13 18:10:23 +08:00
test('button should be disabled if update is unavailable', () => {
2019-03-15 11:42:41 +08:00
window.blessing.extra = { canUpdate: false }
const wrapper = mount(Update)
2019-03-30 18:36:01 +08:00
expect(wrapper.find('button').attributes('disabled')).toBe('disabled')
2019-03-15 11:42:41 +08:00
})
2019-03-17 10:21:18 +08:00
2018-09-13 18:10:23 +08:00
test('perform update', async () => {
2019-03-15 11:42:41 +08:00
window.$ = jest.fn(() => ({
modal() {},
}))
Vue.prototype.$http.post
2019-04-05 17:23:27 +08:00
.mockResolvedValueOnce({ errno: 1, msg: 'fail' })
2019-03-15 11:42:41 +08:00
.mockResolvedValue({})
const wrapper = mount(Update)
2019-03-30 18:36:01 +08:00
const button = wrapper.find('button')
2018-09-13 18:10:23 +08:00
2019-03-15 11:42:41 +08:00
button.trigger('click')
await flushPromises()
2019-04-05 17:23:27 +08:00
expect(Vue.prototype.$alert).toBeCalledWith('fail', { type: 'error' })
2019-03-15 11:42:41 +08:00
button.trigger('click')
jest.runOnlyPendingTimers()
await flushPromises()
2019-03-18 09:55:24 +08:00
expect($).toBeCalled()
2019-03-15 11:42:41 +08:00
expect(Vue.prototype.$http.get).toBeCalledWith(
'/admin/update/download',
2019-04-05 17:23:27 +08:00
{ action: 'progress' }
2019-03-15 11:42:41 +08:00
)
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/update/download',
2019-04-05 17:23:27 +08:00
{ action: 'download' }
2019-03-15 11:42:41 +08:00
)
2019-04-05 17:23:27 +08:00
})
test('polling for querying download progress', async () => {
const wrapper = mount<Vue & { polling(): Promise<void> }>(Update)
wrapper.setData({ updating: true })
await wrapper.vm.polling()
expect(Vue.prototype.$http.get).toBeCalledWith(
2019-03-15 11:42:41 +08:00
'/admin/update/download',
2019-04-05 17:23:27 +08:00
{ action: 'progress' }
2019-03-15 11:42:41 +08:00
)
})