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

119 lines
3.4 KiB
TypeScript
Raw Normal View History

2019-03-18 09:55:24 +08:00
import Vue from 'vue'
2019-03-15 11:42:41 +08:00
import { mount } from '@vue/test-utils'
2019-03-18 15:00:18 +08:00
import Previewer from '@/components/Previewer.vue'
2019-03-28 16:37:01 +08:00
import * as emitter from '@/scripts/event'
2019-03-18 15:00:18 +08:00
import * as mockedSkinview3d from '../__mocks__/skinview3d'
2018-07-27 09:54:23 +08:00
2019-03-18 09:55:24 +08:00
type Viewer = Vue & { viewer: mockedSkinview3d.SkinViewer }
interface Handles {
handles: {
run: { paused: boolean }
walk: { paused: boolean }
rotate: { paused: boolean }
}
}
2018-07-27 09:54:23 +08:00
test('initialize skinview3d', () => {
2019-03-15 11:42:41 +08:00
const stub = jest.fn()
emitter.on('skinViewerMounted', stub)
2019-03-18 09:55:24 +08:00
const wrapper = mount<Viewer>(Previewer)
2019-03-15 11:42:41 +08:00
expect(wrapper.vm.viewer).toBeInstanceOf(mockedSkinview3d.SkinViewer)
expect(wrapper.vm.viewer.camera.position.z).toBe(70)
expect(stub).toBeCalledWith(expect.any(HTMLElement))
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('dispose viewer before destroy', () => {
2019-03-18 09:55:24 +08:00
const wrapper = mount<Viewer>(Previewer)
2019-03-15 11:42:41 +08:00
wrapper.destroy()
expect(wrapper.vm.viewer.disposed).toBeTrue()
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('skin URL should be updated', () => {
2019-03-18 09:55:24 +08:00
const wrapper = mount<Viewer>(Previewer)
2019-03-15 11:42:41 +08:00
wrapper.setProps({ skin: 'abc' })
expect(wrapper.vm.viewer.skinUrl).toBe('abc')
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('cape URL should be updated', () => {
2019-03-18 09:55:24 +08:00
const wrapper = mount<Viewer>(Previewer)
2019-03-15 11:42:41 +08:00
wrapper.setProps({ cape: 'abc' })
expect(wrapper.vm.viewer.capeUrl).toBe('abc')
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('`footer` slot', () => {
2019-03-15 11:42:41 +08:00
const wrapper = mount(Previewer, {
slots: {
footer: '<div id="footer" />',
},
})
expect(wrapper.find('#footer').exists()).toBeTrue()
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('disable closet mode', () => {
2019-03-15 11:42:41 +08:00
const wrapper = mount(Previewer)
expect(wrapper.find('.badge').text()).toBe('')
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('enable closet mode', () => {
2019-03-15 11:42:41 +08:00
const wrapper = mount(Previewer, {
propsData: {
closetMode: true,
},
})
expect(wrapper.find('.badge').text()).toBe('')
wrapper.setProps({ skin: 'abc' })
expect(wrapper.find('.badge').text()).toBe('general.skin')
wrapper.setProps({ cape: 'abc', skin: '' })
expect(wrapper.find('.badge').text()).toBe('general.cape')
wrapper.setProps({ skin: 'abc', cape: 'abc' })
expect(wrapper.find('.badge').text()).toBe('general.skin & general.cape')
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('toggle pause', () => {
2019-03-15 11:42:41 +08:00
const wrapper = mount(Previewer)
const pauseButton = wrapper.find('.fa-pause')
expect(pauseButton.exists()).toBeTrue()
pauseButton.trigger('click')
expect(wrapper.find('.fa-play').exists()).toBeTrue()
expect(wrapper.find('.fa-pause').exists()).toBeFalse()
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('toggle run', () => {
2019-03-18 09:55:24 +08:00
const wrapper = mount<Vue & Handles>(Previewer)
2019-03-15 11:42:41 +08:00
wrapper.find('.fa-forward').trigger('click')
expect(wrapper.vm.handles.run.paused).toBeFalse()
expect(wrapper.vm.handles.walk.paused).toBeFalse()
2019-03-15 11:42:41 +08:00
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('toggle rotate', () => {
2019-03-18 09:55:24 +08:00
const wrapper = mount<Vue & Handles>(Previewer)
2019-03-15 11:42:41 +08:00
wrapper.find('.fa-redo-alt').trigger('click')
expect(wrapper.vm.handles.rotate.paused).toBeTrue()
})
2019-03-17 10:21:18 +08:00
2018-07-27 09:54:23 +08:00
test('reset', () => {
2019-03-18 09:55:24 +08:00
mockedSkinview3d.SkinViewer.prototype.dispose = jest.fn(
function (this: mockedSkinview3d.SkinViewer) {
this.disposed = true
}.bind(new mockedSkinview3d.SkinViewer())
)
const wrapper = mount<Viewer>(Previewer, {
propsData: {
model: 'alex',
},
})
2019-03-15 11:42:41 +08:00
wrapper.find('.fa-stop').trigger('click')
expect(mockedSkinview3d.SkinViewer.prototype.dispose).toBeCalled()
expect(wrapper.vm.viewer.playerObject.skin.slim).toBeTrue()
2019-03-15 11:42:41 +08:00
})
2019-03-17 10:21:18 +08:00
2018-08-11 11:59:11 +08:00
test('custom title', () => {
2019-03-15 11:42:41 +08:00
const wrapper = mount(Previewer, { propsData: { title: 'custom-title' } })
expect(wrapper.text()).toContain('custom-title')
})