import { PerspectiveCamera } from 'three'
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable no-console */
// @vitest-environment happy-dom
import { mount } from '@vue/test-utils'
import { describe, expect, vi } from 'vitest'
import GL from 'gl'
import TresCanvas from './TresCanvas.vue'
import Tres from '/@/'
import { MeshNormalMaterial, Scene, SphereGeometry } from 'three'
const window = new Window()
const document = window.document
document.body.innerHTML = ''
let canvas = document.querySelector('canvas')
const glContext = GL(100, 100)
describe('TresCanvas.vue', () => {
beforeEach(() => {
canvas = document.querySelector('canvas')
canvas.addEventListener = function (_event: any, _func: any, _bind_: any) {}
console.error = vi.fn()
})
test('should render a canvas template', () => {
const wrapper = mount(TresCanvas, {
props: {
gl: glContext,
},
global: {
plugins: [Tres],
},
slots: {
default: {
template: `
`,
},
},
})
expect(wrapper.html()).toContain('canvas')
})
test('should create a create a default PerspectiveCamera', () => {
const wrapper = mount(TresCanvas, {
props: {
gl: glContext,
},
global: {
plugins: [Tres],
},
slots: {
default: {
template: `
`,
},
},
})
expect(wrapper.vm.camera).toBeInstanceOf(PerspectiveCamera)
})
test('should create a Scene instance', () => {
const wrapper = mount(TresCanvas, {
props: {
gl: glContext,
},
global: {
plugins: [Tres],
},
slots: {
default: {
template: `
`,
},
},
})
expect(wrapper.vm.scene).toBeInstanceOf(Scene)
})
test('should create a Sphere Mesh with the provided position', () => {
const wrapper = mount(TresCanvas, {
props: {
gl: glContext,
},
global: {
plugins: [Tres],
},
slots: {
default: {
template: `
`,
},
},
})
const mesh = wrapper.vm.scene.children.find(child => child.type === 'Mesh')
expect(mesh.position).toEqual({ x: 0, y: 2, z: 3 })
expect(mesh.geometry).toBeInstanceOf(SphereGeometry)
})
test('should create a Sphere Mesh with the a MeshNormalMaterial', () => {
const wrapper = mount(TresCanvas, {
props: {
gl: glContext,
},
global: {
plugins: [Tres],
},
slots: {
default: {
template: `
`,
},
},
})
const mesh = wrapper.vm.scene.children.find(child => child.type === 'Mesh')
expect(mesh.material).toBeInstanceOf(MeshNormalMaterial)
})
})