|
| 1 | +import { test, describe, expect, vi } from 'vitest'; |
| 2 | +import { BuildVolume } from '../build-volume'; |
| 3 | +import { AxesHelper } from 'three'; |
| 4 | +import { Grid } from '../helpers/grid'; |
| 5 | +import { LineBox } from '../helpers/line-box'; |
| 6 | + |
| 7 | +describe('BuildVolume', () => { |
| 8 | + test('it has a default color', () => { |
| 9 | + const buildVolume = new BuildVolume(); |
| 10 | + |
| 11 | + expect(buildVolume.color).toEqual(0x888888); |
| 12 | + }); |
| 13 | + |
| 14 | + test('it has size properties', () => { |
| 15 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 16 | + |
| 17 | + expect(buildVolume.x).toEqual(10); |
| 18 | + expect(buildVolume.y).toEqual(20); |
| 19 | + expect(buildVolume.z).toEqual(30); |
| 20 | + }); |
| 21 | + |
| 22 | + describe('.createAxes', () => { |
| 23 | + test('it creates an AxesHelper', () => { |
| 24 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 25 | + |
| 26 | + const axes = buildVolume.createAxes(); |
| 27 | + |
| 28 | + expect(axes).toBeDefined(); |
| 29 | + expect(axes).toBeInstanceOf(AxesHelper); |
| 30 | + }); |
| 31 | + |
| 32 | + test('it scales the axes', () => { |
| 33 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 34 | + |
| 35 | + const axes = buildVolume.createAxes(); |
| 36 | + |
| 37 | + expect(axes.scale).toEqual({ x: 1, y: 1, z: -1 }); |
| 38 | + }); |
| 39 | + |
| 40 | + test('it positions the axes', () => { |
| 41 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 42 | + |
| 43 | + const axes = buildVolume.createAxes(); |
| 44 | + |
| 45 | + expect(axes.position).toEqual({ x: -5, y: 0, z: 10 }); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('.createGrid', () => { |
| 50 | + test('it creates a Grid', () => { |
| 51 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 52 | + |
| 53 | + const grid = buildVolume.createGrid(); |
| 54 | + |
| 55 | + expect(grid).toBeDefined(); |
| 56 | + expect(grid).toBeInstanceOf(Grid); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('.createGroup', () => { |
| 61 | + test('it creates a group for all the objects', () => { |
| 62 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 63 | + |
| 64 | + const group = buildVolume.createGroup(); |
| 65 | + |
| 66 | + expect(group).toBeDefined(); |
| 67 | + expect(group.children.length).toEqual(3); |
| 68 | + |
| 69 | + expect(group.children[0]).toBeInstanceOf(LineBox); |
| 70 | + expect(group.children[1]).toBeInstanceOf(Grid); |
| 71 | + expect(group.children[2]).toBeInstanceOf(AxesHelper); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('.dispose', () => { |
| 76 | + test('it calls dispose on all disposables', () => { |
| 77 | + const buildVolume = new BuildVolume(10, 20, 30); |
| 78 | + |
| 79 | + const axes = buildVolume.createAxes(); |
| 80 | + const grid = buildVolume.createGrid(); |
| 81 | + const lineBox = buildVolume.createLineBox(); |
| 82 | + |
| 83 | + const axesSpy = vi.spyOn(axes, 'dispose'); |
| 84 | + const gridSpy = vi.spyOn(grid, 'dispose'); |
| 85 | + const lineBoxSpy = vi.spyOn(lineBox, 'dispose'); |
| 86 | + |
| 87 | + buildVolume.dispose(); |
| 88 | + |
| 89 | + expect(axesSpy).toHaveBeenCalled(); |
| 90 | + expect(gridSpy).toHaveBeenCalled(); |
| 91 | + expect(lineBoxSpy).toHaveBeenCalled(); |
| 92 | + }); |
| 93 | + }); |
| 94 | +}); |
0 commit comments