|
1 | | -import { test, expect } from 'vitest'; |
| 1 | +import { test, expect, describe } from 'vitest'; |
2 | 2 | import { Path, PathType } from '../path'; |
3 | 3 | import { ExtrusionGeometry } from '../extrusion-geometry'; |
4 | 4 | import { BufferGeometry } from 'three'; |
@@ -64,70 +64,96 @@ test('.path returns an array of Vector3', () => { |
64 | 64 | expect(result[1]).toEqual({ x: 1, y: 2, z: 3 }); |
65 | 65 | }); |
66 | 66 |
|
67 | | -test('.geometry returns an ExtrusionGeometry from the path', () => { |
68 | | - const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 67 | +describe('.geometry', () => { |
| 68 | + test('returns an ExtrusionGeometry from the path', () => { |
| 69 | + const path = new Path(PathType.Travel, undefined, undefined, undefined); |
69 | 70 |
|
70 | | - path.addPoint(0, 0, 0); |
71 | | - path.addPoint(1, 2, 3); |
| 71 | + path.addPoint(0, 0, 0); |
| 72 | + path.addPoint(1, 2, 3); |
72 | 73 |
|
73 | | - const result = path.geometry() as ExtrusionGeometry; |
| 74 | + const result = path.geometry() as ExtrusionGeometry; |
74 | 75 |
|
75 | | - expect(result).not.toBeNull(); |
76 | | - expect(result).toBeInstanceOf(ExtrusionGeometry); |
77 | | - expect(result.parameters.points.length).toEqual(2); |
78 | | - expect(result.parameters.closed).toEqual(false); |
79 | | -}); |
| 76 | + expect(result).not.toBeNull(); |
| 77 | + expect(result).toBeInstanceOf(ExtrusionGeometry); |
| 78 | + expect(result.parameters.points.length).toEqual(2); |
| 79 | + expect(result.parameters.closed).toEqual(false); |
| 80 | + }); |
80 | 81 |
|
81 | | -test('.geometry returns an ExtrusionGeometry with the path extrusion width', () => { |
82 | | - const path = new Path(PathType.Travel, 9, undefined, undefined); |
| 82 | + test('returns an ExtrusionGeometry with the path extrusion width', () => { |
| 83 | + const path = new Path(PathType.Travel, 9, undefined, undefined); |
83 | 84 |
|
84 | | - path.addPoint(0, 0, 0); |
85 | | - path.addPoint(1, 2, 3); |
| 85 | + path.addPoint(0, 0, 0); |
| 86 | + path.addPoint(1, 2, 3); |
86 | 87 |
|
87 | | - const result = path.geometry() as ExtrusionGeometry; |
| 88 | + const result = path.geometry() as ExtrusionGeometry; |
88 | 89 |
|
89 | | - expect(result.parameters.lineWidth).toEqual(9); |
90 | | -}); |
| 90 | + expect(result.parameters.lineWidth).toEqual(9); |
| 91 | + }); |
91 | 92 |
|
92 | | -test('.geometry returns an ExtrusionGeometry with the path line height', () => { |
93 | | - const path = new Path(PathType.Travel, undefined, 5, undefined); |
| 93 | + test('returns an ExtrusionGeometry with the path line height', () => { |
| 94 | + const path = new Path(PathType.Travel, undefined, 5, undefined); |
94 | 95 |
|
95 | | - path.addPoint(0, 0, 0); |
96 | | - path.addPoint(1, 2, 3); |
| 96 | + path.addPoint(0, 0, 0); |
| 97 | + path.addPoint(1, 2, 3); |
97 | 98 |
|
98 | | - const result = path.geometry() as ExtrusionGeometry; |
| 99 | + const result = path.geometry() as ExtrusionGeometry; |
99 | 100 |
|
100 | | - expect(result.parameters.lineHeight).toEqual(5); |
101 | | -}); |
| 101 | + expect(result.parameters.lineHeight).toEqual(5); |
| 102 | + }); |
102 | 103 |
|
103 | | -test('.geometry returns an empty BufferGeometry if there are less than 3 vertices', () => { |
104 | | - const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 104 | + test('returns an ExtrusionGeometry with the extrusionWidthOverride when passed', () => { |
| 105 | + const path = new Path(PathType.Travel, 9, undefined, undefined); |
105 | 106 |
|
106 | | - const result = path.geometry(); |
| 107 | + path.addPoint(0, 0, 0); |
| 108 | + path.addPoint(1, 2, 3); |
107 | 109 |
|
108 | | - expect(result).not.toBeNull(); |
109 | | - expect(result).toBeInstanceOf(BufferGeometry); |
110 | | -}); |
| 110 | + const result = path.geometry({ extrusionWidthOverride: 2 }) as ExtrusionGeometry; |
111 | 111 |
|
112 | | -test('.line returns a BufferGeometry from the path', () => { |
113 | | - const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 112 | + expect(result.parameters.lineWidth).toEqual(2); |
| 113 | + }); |
114 | 114 |
|
115 | | - path.addPoint(0, 0, 0); |
116 | | - path.addPoint(1, 2, 3); |
| 115 | + test('returns an ExtrusionGeometry with the lineHeightOverride when passed', () => { |
| 116 | + const path = new Path(PathType.Travel, undefined, 5, undefined); |
117 | 117 |
|
118 | | - const result = path.line(); |
| 118 | + path.addPoint(0, 0, 0); |
| 119 | + path.addPoint(1, 2, 3); |
119 | 120 |
|
120 | | - expect(result).not.toBeNull(); |
121 | | - const points = result.attributes['instanceStart'].array; |
122 | | - expect(points).toEqual(Float32Array.from([0, 0, 0, 1, 2, 3])); |
| 121 | + const result = path.geometry({ lineHeightOverride: 7 }) as ExtrusionGeometry; |
| 122 | + |
| 123 | + expect(result.parameters.lineHeight).toEqual(7); |
| 124 | + }); |
| 125 | + |
| 126 | + test('returns an empty BufferGeometry if there are less than 3 vertices', () => { |
| 127 | + const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 128 | + |
| 129 | + const result = path.geometry(); |
| 130 | + |
| 131 | + expect(result).not.toBeNull(); |
| 132 | + expect(result).toBeInstanceOf(BufferGeometry); |
| 133 | + }); |
123 | 134 | }); |
124 | 135 |
|
125 | | -test('.line returns a BufferGeometry when there are no vertices', () => { |
126 | | - const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 136 | +describe('.line', () => { |
| 137 | + test('returns a BufferGeometry from the path', () => { |
| 138 | + const path = new Path(PathType.Travel, undefined, undefined, undefined); |
127 | 139 |
|
128 | | - const result = path.line(); |
| 140 | + path.addPoint(0, 0, 0); |
| 141 | + path.addPoint(1, 2, 3); |
129 | 142 |
|
130 | | - expect(result).not.toBeNull(); |
131 | | - const points = result.attributes['instanceStart'].array; |
132 | | - expect(points.length).toEqual(0); |
| 143 | + const result = path.line(); |
| 144 | + |
| 145 | + expect(result).not.toBeNull(); |
| 146 | + const points = result.attributes['instanceStart'].array; |
| 147 | + expect(points).toEqual(Float32Array.from([0, 0, 0, 1, 2, 3])); |
| 148 | + }); |
| 149 | + |
| 150 | + test('returns a BufferGeometry when there are no vertices', () => { |
| 151 | + const path = new Path(PathType.Travel, undefined, undefined, undefined); |
| 152 | + |
| 153 | + const result = path.line(); |
| 154 | + |
| 155 | + expect(result).not.toBeNull(); |
| 156 | + const points = result.attributes['instanceStart'].array; |
| 157 | + expect(points.length).toEqual(0); |
| 158 | + }); |
133 | 159 | }); |
0 commit comments