Emit an event after previewer mounted

This commit is contained in:
Pig Fang 2018-09-10 18:37:43 +08:00
parent 0d6cc52d23
commit 8ee01b7adb
2 changed files with 7 additions and 0 deletions

View File

@ -50,6 +50,7 @@
<script> <script>
import * as skinview3d from 'skinview3d'; import * as skinview3d from 'skinview3d';
import { emit } from '../../js/event';
import SkinSteve from '../../images/textures/steve.png'; import SkinSteve from '../../images/textures/steve.png';
export default { export default {
@ -103,6 +104,7 @@ export default {
}, },
mounted() { mounted() {
this.initPreviewer(); this.initPreviewer();
emit('skinViewerMounted', this.$refs.previewer);
}, },
beforeDestroy() { beforeDestroy() {
this.viewer.dispose(); this.viewer.dispose();

View File

@ -1,11 +1,16 @@
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Previewer from '@/components/common/Previewer'; import Previewer from '@/components/common/Previewer';
import * as emitter from '@/js/event';
import * as mockedSkinview3d from '../../__mocks__/skinview3d'; import * as mockedSkinview3d from '../../__mocks__/skinview3d';
test('initialize skinview3d', () => { test('initialize skinview3d', () => {
const stub = jest.fn();
emitter.on('skinViewerMounted', stub);
const wrapper = mount(Previewer); const wrapper = mount(Previewer);
expect(wrapper.vm.viewer).toBeInstanceOf(mockedSkinview3d.SkinViewer); expect(wrapper.vm.viewer).toBeInstanceOf(mockedSkinview3d.SkinViewer);
expect(wrapper.vm.viewer.camera.position.z).toBe(70); expect(wrapper.vm.viewer.camera.position.z).toBe(70);
expect(stub).toBeCalledWith(expect.any(HTMLElement));
}); });
test('dispose viewer before destroy', () => { test('dispose viewer before destroy', () => {