2019-12-01 17:52:30 +08:00
|
|
|
import 'bootstrap'
|
2019-04-01 21:45:59 +08:00
|
|
|
import Vue from 'vue'
|
|
|
|
import { mount } from '@vue/test-utils'
|
2019-11-21 09:33:28 +08:00
|
|
|
import { flushPromises } from '../utils'
|
2019-12-01 17:52:30 +08:00
|
|
|
import { toast } from '@/scripts/notify'
|
2019-04-01 21:45:59 +08:00
|
|
|
import ApplyToPlayerDialog from '@/components/ApplyToPlayerDialog.vue'
|
|
|
|
|
2019-12-01 17:52:30 +08:00
|
|
|
jest.mock('@/scripts/notify')
|
|
|
|
|
2019-04-01 21:45:59 +08:00
|
|
|
test('submit applying texture', async () => {
|
2019-04-23 19:14:41 +08:00
|
|
|
Vue.prototype.$http.get.mockResolvedValue({ data: [{ pid: 1 }] })
|
2019-04-23 11:47:45 +08:00
|
|
|
Vue.prototype.$http.post.mockResolvedValueOnce({ code: 1 })
|
|
|
|
.mockResolvedValue({ code: 0, message: 'ok' })
|
2019-04-01 21:45:59 +08:00
|
|
|
const wrapper = mount(ApplyToPlayerDialog)
|
|
|
|
const button = wrapper.find('[data-test=submit]')
|
|
|
|
|
|
|
|
button.trigger('click')
|
2019-12-01 17:52:30 +08:00
|
|
|
expect(toast.info).toBeCalledWith('user.emptySelectedPlayer')
|
2019-04-01 21:45:59 +08:00
|
|
|
|
|
|
|
wrapper.setData({ selected: 1 })
|
|
|
|
button.trigger('click')
|
2019-12-01 17:52:30 +08:00
|
|
|
expect(toast.info).toBeCalledWith('user.emptySelectedTexture')
|
2019-04-01 21:45:59 +08:00
|
|
|
|
|
|
|
wrapper.setProps({ skin: 1 })
|
|
|
|
button.trigger('click')
|
|
|
|
expect(Vue.prototype.$http.post).toBeCalledWith(
|
2019-04-24 13:10:03 +08:00
|
|
|
'/user/player/set/1',
|
2019-04-01 21:45:59 +08:00
|
|
|
{
|
2019-04-24 13:10:03 +08:00
|
|
|
skin: 1,
|
|
|
|
cape: undefined,
|
2019-11-25 23:30:51 +08:00
|
|
|
},
|
2019-04-01 21:45:59 +08:00
|
|
|
)
|
|
|
|
wrapper.setProps({ skin: 0, cape: 1 })
|
|
|
|
button.trigger('click')
|
|
|
|
expect(Vue.prototype.$http.post).toBeCalledWith(
|
2019-04-24 13:10:03 +08:00
|
|
|
'/user/player/set/1',
|
2019-04-01 21:45:59 +08:00
|
|
|
{
|
2019-04-24 13:10:03 +08:00
|
|
|
skin: undefined,
|
|
|
|
cape: 1,
|
2019-11-25 23:30:51 +08:00
|
|
|
},
|
2019-04-01 21:45:59 +08:00
|
|
|
)
|
2019-11-21 09:33:28 +08:00
|
|
|
await flushPromises()
|
2019-12-01 17:52:30 +08:00
|
|
|
expect(toast.success).toBeCalledWith('ok')
|
2019-04-01 21:45:59 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('compute avatar URL', () => {
|
2019-04-23 19:14:41 +08:00
|
|
|
Vue.prototype.$http.get.mockResolvedValue({ data: {} })
|
2019-04-01 21:45:59 +08:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
const wrapper = mount<Vue & { avatarUrl(player: { tid_skin: number }): string }>(ApplyToPlayerDialog)
|
|
|
|
const { avatarUrl } = wrapper.vm
|
2020-01-12 09:27:39 +08:00
|
|
|
expect(avatarUrl({ tid_skin: 1 })).toBe('/avatar/1?size=35')
|
2019-04-01 21:45:59 +08:00
|
|
|
})
|