Repository navigation
Conversation
Comment on lines
+1
to
+149
| import { expect, test } from "bun:test" | ||
| import { | ||
| type AssemblyExplosionMoveProps, | ||
| type AssemblyExplosionMovePropsInput, | ||
| type AssemblyExplosionStageProps, | ||
| type AssemblyExplosionStagePropsInput, | ||
| assemblyExplosionMoveProps, | ||
| assemblyExplosionProps, | ||
| assemblyExplosionStageProps, | ||
| assemblyProps, | ||
| assemblySubassemblyProps, | ||
| } from "lib" | ||
| import { createElement, type ReactNode } from "react" | ||
|
|
||
| test("exports stage and move through the nested explosion namespace", () => { | ||
| expect(assemblyProps.explosion).toBe(assemblyExplosionProps) | ||
| expect(assemblyProps.explosion.stage).toBe(assemblyExplosionStageProps) | ||
| expect(assemblyProps.explosion.move).toBe(assemblyExplosionMoveProps) | ||
| expect(Object.keys(assemblyProps.explosion).sort()).toEqual(["move", "stage"]) | ||
| }) | ||
|
|
||
| test("trims stage identities and ordering hints without adding defaults", () => { | ||
| const input: AssemblyExplosionStageProps = { | ||
| name: " remove-cover ", | ||
| prevStageRef: " remove-screws ", | ||
| nextStageRef: " cover.remove-window ", | ||
| } | ||
| const props: AssemblyExplosionStagePropsInput = input | ||
| expect(assemblyExplosionStageProps.parse(props)).toEqual({ | ||
| name: "remove-cover", | ||
| prevStageRef: "remove-screws", | ||
| nextStageRef: "cover.remove-window", | ||
| }) | ||
| expect(assemblyExplosionStageProps.parse({ name: "lift" })).toEqual({ | ||
| name: "lift", | ||
| }) | ||
| }) | ||
|
|
||
| test("rejects missing, blank, or invalid stage identities and hints", () => { | ||
| for (const input of [ | ||
| {}, | ||
| { name: "" }, | ||
| { name: " " }, | ||
| { name: 1 }, | ||
| { name: "lift", nextStageRef: " " }, | ||
| { name: "lift", prevStageRef: "" }, | ||
| { name: "lift", nextStageRef: null }, | ||
| { name: "lift", prevStageRef: 1 }, | ||
| ]) { | ||
| expect(assemblyExplosionStageProps.safeParse(input).success).toBe(false) | ||
| } | ||
| }) | ||
|
|
||
| test("converts signed offsets to finite millimeters and leaves absent axes omitted", () => { | ||
| const input: AssemblyExplosionMoveProps = { | ||
| targetRef: " cover ", | ||
| offX: "-2cm", | ||
| offY: 0, | ||
| offZ: "1in", | ||
| } | ||
| const props: AssemblyExplosionMovePropsInput = input | ||
| expect(assemblyExplosionMoveProps.parse(props)).toEqual({ | ||
| targetRef: "cover", | ||
| offX: -20, | ||
| offY: 0, | ||
| offZ: 25.4, | ||
| }) | ||
| for (const axis of ["offX", "offY", "offZ"] as const) { | ||
| expect( | ||
| assemblyExplosionMoveProps.parse({ targetRef: "cover", [axis]: 0 }), | ||
| ).toEqual({ targetRef: "cover", [axis]: 0 }) | ||
| expect( | ||
| assemblyExplosionMoveProps.parse({ | ||
| targetRef: "cover.window", | ||
| [axis]: "-5mm", | ||
| }), | ||
| ).toEqual({ targetRef: "cover.window", [axis]: -5 }) | ||
| } | ||
| }) | ||
|
|
||
| test("rejects invalid move targets, missing offsets, and nonfinite distances", () => { | ||
| for (const input of [ | ||
| {}, | ||
| { offZ: 10 }, | ||
| { targetRef: "", offZ: 10 }, | ||
| { targetRef: " ", offZ: 10 }, | ||
| { targetRef: 1, offZ: 10 }, | ||
| { targetRef: "cover" }, | ||
| ]) { | ||
| expect(assemblyExplosionMoveProps.safeParse(input).success).toBe(false) | ||
| } | ||
| for (const axis of ["offX", "offY", "offZ"] as const) { | ||
| for (const value of [ | ||
| "nonsense", | ||
| Number.NaN, | ||
| Number.POSITIVE_INFINITY, | ||
| Number.NEGATIVE_INFINITY, | ||
| null, | ||
| ]) { | ||
| expect( | ||
| assemblyExplosionMoveProps.safeParse({ | ||
| targetRef: "cover", | ||
| [axis]: value, | ||
| }).success, | ||
| ).toBe(false) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| test("TSX preserves move targets and ordered children inside subassemblies", () => { | ||
| // Props supplies validators; core supplies the namespaced JSX components. | ||
| const assembly = { | ||
| explosion: { | ||
| stage: (props: AssemblyExplosionStagePropsInput) => | ||
| createElement("assembly.explosion.stage", props), | ||
| move: (props: AssemblyExplosionMovePropsInput) => | ||
| createElement("assembly.explosion.move", props), | ||
| }, | ||
| } | ||
| const firstMove = <assembly.explosion.move targetRef="cover" offZ="12mm" /> | ||
| const secondMove = <assembly.explosion.move targetRef="cover" offX="60mm" /> | ||
| expect(assemblyExplosionMoveProps.parse(firstMove.props)).toEqual({ | ||
| targetRef: "cover", | ||
| offZ: 12, | ||
| }) | ||
| const stage = ( | ||
| <assembly.explosion.stage | ||
| name="remove-cover" | ||
| nextStageRef="cover.remove-window" | ||
| > | ||
| {firstMove} | ||
| {secondMove} | ||
| </assembly.explosion.stage> | ||
| ) | ||
| const parsed = assemblyExplosionStageProps.parse(stage.props) | ||
| expect(parsed.children).toBe(stage.props.children) | ||
| expect(parsed.children).toEqual([firstMove, secondMove]) | ||
| expect( | ||
| assemblySubassemblyProps.parse({ name: "module", children: stage }) | ||
| .children, | ||
| ).toBe(stage) | ||
| const emptyChildren: ReactNode = null | ||
| expect( | ||
| assemblyExplosionStageProps.parse({ | ||
| name: "pause", | ||
| children: emptyChildren, | ||
| }).children, | ||
| ).toBeNull() | ||
| }) |
Contributor
There was a problem hiding this comment.
This file contains 6 test(...) calls, but the style guide rule states that a *.test.ts (or *.test.tsx) file may have AT MOST one test(...). After that, the tests should be split into multiple numbered files, e.g., assembly-explosion1.test.tsx, assembly-explosion2.test.tsx, assembly-explosion3.test.tsx, etc. Please split this file into 6 separate numbered test files, each containing exactly one test(...) call.
Spotted by Graphite (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
seveibar
marked this pull request as draft
October 14, 2026 20:01
This was referenced Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds props for
<assembly.explosion.stage>and<assembly.explosion.move>so TSX authors can describe staged disassembly, including moving a subassembly intact before exploding its children at the displaced pose.Stages accept
name, optionalnextStageRef/prevStageRef, and preserved children. Moves accepttargetRefand signed, unit-awareoffX/offY/offZ, normalized to finite millimeters.targetRefavoids React's reservedrefprop. Validators and input types are exported individually and throughassemblyProps.explosion.The proposal documents document-order fallback, cross-assembly ordering references, accumulated motion, and automatic swept-path collision checks. This PR supplies props and validation; namespaced JSX components, stage scheduling, and collision checking require corresponding core support. No explosion container or run, detach, translate, or collision-check elements are introduced.
Validation:
bun test: 674 passed, 0 failed.tsc --noEmit: passed.biome format .: passed.Approval tracking: this PR remains draft and awaiting API approval. Related speculative drafts are core#4631 for constrained explosion views and PoppyGL renders, and poppygl#49 for guide lines. All three require approval before merge; core uses pinned previews until the upstream packages are approved and released.