blessing-skin-server/resources/assets/tests/components/AddPlayerDialog.test.ts
2019-11-28 21:35:27 +08:00

35 lines
1.0 KiB
TypeScript

import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../utils'
import Modal from '@/components/Modal.vue'
import AddPlayerDialog from '@/components/AddPlayerDialog.vue'
window.blessing.extra = {
rule: 'rule',
length: 'length',
}
test('add player', async () => {
Vue.prototype.$http.get.mockResolvedValueOnce([])
Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(AddPlayerDialog)
const modal = wrapper.find(Modal)
wrapper.find('input[type="text"]').setValue('the-new')
modal.vm.$emit('confirm')
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/player/add',
{ name: 'the-new' },
)
await flushPromises()
expect(wrapper.text()).not.toContain('the-new')
expect(Vue.prototype.$message.warning).toBeCalledWith('fail')
modal.vm.$emit('confirm')
await flushPromises()
expect(wrapper.emitted().add).toBeDefined()
expect(Vue.prototype.$message.success).toBeCalledWith('ok')
})