blessing-skin-server/resources/assets/tests/components/AddPlayerDialog.test.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-04-01 21:45:59 +08:00
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../utils'
import { toast } from '@/scripts/notify'
2019-11-28 21:35:27 +08:00
import Modal from '@/components/Modal.vue'
2019-04-01 21:45:59 +08:00
import AddPlayerDialog from '@/components/AddPlayerDialog.vue'
jest.mock('@/scripts/notify')
2019-04-01 21:45:59 +08:00
window.blessing.extra = {
rule: 'rule',
length: 'length',
}
test('add player', async () => {
Vue.prototype.$http.get.mockResolvedValueOnce([])
Vue.prototype.$http.post
2019-04-23 11:47:45 +08:00
.mockResolvedValueOnce({ code: 1, message: 'fail' })
.mockResolvedValue({ code: 0, message: 'ok' })
2019-04-01 21:45:59 +08:00
const wrapper = mount(AddPlayerDialog)
2019-11-28 21:35:27 +08:00
const modal = wrapper.find(Modal)
2019-04-01 21:45:59 +08:00
wrapper.find('input[type="text"]').setValue('the-new')
2019-11-28 21:35:27 +08:00
modal.vm.$emit('confirm')
2019-04-01 21:45:59 +08:00
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/player/add',
2019-11-25 23:30:51 +08:00
{ name: 'the-new' },
2019-04-01 21:45:59 +08:00
)
await flushPromises()
expect(wrapper.text()).not.toContain('the-new')
expect(toast.error).toBeCalledWith('fail')
2019-04-01 21:45:59 +08:00
2019-11-28 21:35:27 +08:00
modal.vm.$emit('confirm')
2019-04-01 21:45:59 +08:00
await flushPromises()
expect(wrapper.emitted().add).toBeDefined()
expect(toast.success).toBeCalledWith('ok')
2019-04-01 21:45:59 +08:00
})