diff --git a/tests/unit/transform-axis-mapping.test.ts b/tests/unit/transform-axis-mapping.test.ts new file mode 100644 index 00000000..2a401c20 --- /dev/null +++ b/tests/unit/transform-axis-mapping.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, it } from "vitest"; + +import { resolveDominantLocalAxisForWorldAxis } from "../../src/viewport-three/transform-axis-mapping"; + +describe("transform axis mapping", () => { + it("maps a world axis onto the dominant local axis for rotated targets", () => { + expect( + resolveDominantLocalAxisForWorldAxis( + { + x: 0, + y: 90, + z: 0 + }, + "x" + ) + ).toBe("z"); + + expect( + resolveDominantLocalAxisForWorldAxis( + { + x: 90, + y: 0, + z: 0 + }, + "y" + ) + ).toBe("z"); + }); + + it("keeps the same axis when the target is not rotated", () => { + expect( + resolveDominantLocalAxisForWorldAxis( + { + x: 0, + y: 0, + z: 0 + }, + "x" + ) + ).toBe("x"); + + expect( + resolveDominantLocalAxisForWorldAxis( + { + x: 0, + y: 0, + z: 0 + }, + "z" + ) + ).toBe("z"); + }); +});