Files
snapcad-studio/tests/unit/architecturalFeaturesBatch.test.ts
T

133 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

import { describe, expect, it } from "vitest";
import { createAngledGuide, createGuide } from "@/lib/guidesSystem";
import type { ArchitecturalScene, WorkplaneShape } from "@/types/sketchforge";
describe("Architectural Features Batch — Protractor, Scenes & Components", () => {
it("creates angled guides for roof pitch and slope (Protractor Tool)", () => {
const guide30 = createAngledGuide(30, 0, 0);
expect(guide30.axis).toBe("angle");
expect(guide30.coordinate).toBe(30);
expect(guide30.angle).toBe(30);
expect(guide30.label).toContain("30°");
const guide45 = createAngledGuide(45, 10, -10, "45° Çatı Makası Kılavuzu");
expect(guide45.axis).toBe("angle");
expect(guide45.angle).toBe(45);
expect(guide45.originX).toBe(10);
expect(guide45.originZ).toBe(-10);
expect(guide45.label).toBe("45° Çatı Makası Kılavuzu");
});
it("handles architectural scenes structure for walkthroughs", () => {
const scene: ArchitecturalScene = {
id: "scene-facade",
name: "Ön Cephe Perspektifi",
cameraPosition: [0, 22, 110],
cameraTarget: [0, 16, 0],
twoPoint: true,
};
expect(scene.id).toBe("scene-facade");
expect(scene.twoPoint).toBe(true);
expect(scene.cameraPosition[1]).toBe(22);
});
it("links and synchronizes component properties across copies", () => {
const windowDefId = "comp-win-120";
const window1: WorkplaneShape = {
id: "win-1",
name: "Pencere 120x150",
kind: "box",
color: "#38bdf8",
x: 10,
z: 0,
width: 12,
depth: 4,
height: 15,
size: 15,
rotation: 0,
componentDefId: windowDefId,
componentName: "Pencere 120x150",
};
const window2: WorkplaneShape = {
id: "win-2",
name: "Pencere 120x150",
kind: "box",
color: "#38bdf8",
x: 40,
z: 0,
width: 12,
depth: 4,
height: 15,
size: 15,
rotation: 0,
componentDefId: windowDefId,
componentName: "Pencere 120x150",
};
const shapes = [window1, window2];
// Simulate resizing window1 width to 16
const updatedWidth = 16;
const syncedShapes = shapes.map((s) => {
if (s.componentDefId === windowDefId) {
return { ...s, width: updatedWidth };
}
return s;
});
expect(syncedShapes[0].width).toBe(16);
expect(syncedShapes[1].width).toBe(16);
// Positions remain independent
expect(syncedShapes[0].x).toBe(10);
expect(syncedShapes[1].x).toBe(40);
});
it("applies architectural textures and colors via Paint Bucket to shapes and linked components", () => {
const wall1: WorkplaneShape = {
id: "wall-1",
name: "Tuğla Duvar Paneli",
kind: "box",
color: "#cccccc",
x: 0,
z: 0,
width: 50,
depth: 5,
height: 30,
size: 30,
rotation: 0,
componentDefId: "comp-brick-wall",
};
const wall2: WorkplaneShape = {
id: "wall-2",
name: "Tuğla Duvar Paneli",
kind: "box",
color: "#cccccc",
x: 60,
z: 0,
width: 50,
depth: 5,
height: 30,
size: 30,
rotation: 0,
componentDefId: "comp-brick-wall",
};
const shapes = [wall1, wall2];
const newTexture = "brick";
const newColor = "#ef4444";
const paintedShapes = shapes.map((s) => {
if (s.componentDefId === "comp-brick-wall") {
return { ...s, texture: newTexture, color: newColor };
}
return s;
});
expect(paintedShapes[0].texture).toBe("brick");
expect(paintedShapes[0].color).toBe("#ef4444");
expect(paintedShapes[1].texture).toBe("brick");
expect(paintedShapes[1].color).toBe("#ef4444");
});
});