|
| 1 | +import { expect, test } from "bun:test" |
| 2 | +import { Circuit } from "tscircuit" |
| 3 | +import { renderGLTFToPNGBufferFromGLBBuffer } from "poppygl" |
| 4 | +import { convertCircuitJsonTo3D, convertCircuitJsonToGltf } from "../../lib" |
| 5 | +import { getBestCameraPosition } from "../../lib/utils/camera-position" |
| 6 | + |
| 7 | +const Repro12Testpoint = () => ( |
| 8 | + <board width="18mm" height="12mm"> |
| 9 | + <testpoint name="T1" pcbX={-7} pcbY={3} padDiameter="0.8mm" /> |
| 10 | + <testpoint name="T2" pcbX={7} pcbY={3} padDiameter="0.8mm" /> |
| 11 | + <testpoint name="M1" pcbX={-7} pcbY={0} padDiameter="0.8mm" /> |
| 12 | + <testpoint name="M2" pcbX={7} pcbY={0} padDiameter="0.8mm" /> |
| 13 | + <testpoint name="B1" pcbX={-7} pcbY={-3} padDiameter="0.8mm" /> |
| 14 | + <testpoint name="B2" pcbX={7} pcbY={-3} padDiameter="0.8mm" /> |
| 15 | + </board> |
| 16 | +) |
| 17 | + |
| 18 | +export default Repro12Testpoint |
| 19 | + |
| 20 | +test("repro12 testpoint 3d snapshot", async () => { |
| 21 | + const circuit = new Circuit() |
| 22 | + circuit.add(<Repro12Testpoint />) |
| 23 | + |
| 24 | + const circuitJson = await circuit.getCircuitJson() |
| 25 | + const scene = await convertCircuitJsonTo3D(circuitJson, { |
| 26 | + showBoundingBoxes: false, |
| 27 | + renderBoardTextures: true, |
| 28 | + textureResolution: 512, |
| 29 | + }) |
| 30 | + |
| 31 | + expect(scene.boxes).toHaveLength(7) |
| 32 | + |
| 33 | + const glb = await convertCircuitJsonToGltf(circuitJson, { |
| 34 | + format: "glb", |
| 35 | + boardTextureResolution: 512, |
| 36 | + includeModels: true, |
| 37 | + showBoundingBoxes: false, |
| 38 | + }) |
| 39 | + |
| 40 | + expect(glb).toBeInstanceOf(ArrayBuffer) |
| 41 | + expect((glb as ArrayBuffer).byteLength).toBeGreaterThan(0) |
| 42 | + |
| 43 | + expect( |
| 44 | + renderGLTFToPNGBufferFromGLBBuffer( |
| 45 | + glb as ArrayBuffer, |
| 46 | + getBestCameraPosition(circuitJson), |
| 47 | + ), |
| 48 | + ).toMatchPngSnapshot(import.meta.path) |
| 49 | +}) |
0 commit comments