blessing-skin-server/resources/assets/tests/components/AddPlayerDialog.test.ts
2019-04-23 23:03:12 +08:00

36 lines
1.1 KiB
TypeScript

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