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

59 lines
1.6 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'
import { showModal } from '@/scripts/notify'
2019-03-18 15:00:18 +08:00
import Update from '@/views/admin/Update.vue'
2018-09-13 18:10:23 +08:00
jest.mock('@/scripts/notify')
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-23 11:47:45 +08:00
.mockResolvedValueOnce({ code: 1, message: '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()
expect(showModal).toBeCalledWith({
mode: 'alert',
text: 'fail',
type: 'danger',
okButtonType: 'outline-light',
})
2019-04-05 17:23:27 +08:00
2019-03-15 11:42:41 +08:00
button.trigger('click')
jest.runOnlyPendingTimers()
await flushPromises()
expect(Vue.prototype.$http.get).toBeCalledWith(
'/admin/update/download',
2019-11-25 23:30:51 +08:00
{ action: 'progress' },
2019-03-15 11:42:41 +08:00
)
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/update/download',
2019-11-25 23:30:51 +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-11-25 23:30:51 +08:00
{ action: 'progress' },
2019-03-15 11:42:41 +08:00
)
})