Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
feat: SnapCAD Studio'yu YakHub deposuna taşı
- DWG/DXF içe aktarma ve .skf yeniden açma düzeltmeleri - YakNet Bulut eşitlemede boş/eski kopya koruması ve yerel-only proje bildirimi - Panelden içe aktarma duyuruları ve erişilebilir Türkçe hata mesajları - AGPL-3.0 lisansı, README ve YakHub bağlantıları
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import * as THREE from "three";
|
||||
import {
|
||||
ARCHITECTURAL_TEXTURES,
|
||||
getTextureDefinition,
|
||||
type ArchitecturalTextureId,
|
||||
} from "../../apps/web/src/lib/architecturalTextures";
|
||||
import {
|
||||
DEFAULT_SECTION_PLANE,
|
||||
createSectionClippingPlane,
|
||||
createSectionPlaneGizmo,
|
||||
updateSectionGizmoTransform,
|
||||
type SectionPlaneSettings,
|
||||
} from "../../apps/web/src/lib/sectionPlaneSystem";
|
||||
import { PhysicsSandbox } from "../../apps/web/src/lib/physicsSandbox";
|
||||
import type { WorkplaneShape } from "../../apps/web/src/types/sketchforge";
|
||||
|
||||
describe("Architectural Materials & Textures System", () => {
|
||||
it("provides comprehensive texture definitions including brick, wood, marble, glass, metal", () => {
|
||||
expect(ARCHITECTURAL_TEXTURES.length).toBeGreaterThanOrEqual(9);
|
||||
|
||||
const ids = ARCHITECTURAL_TEXTURES.map((t) => t.id);
|
||||
expect(ids).toContain("none");
|
||||
expect(ids).toContain("brick");
|
||||
expect(ids).toContain("wood");
|
||||
expect(ids).toContain("tiles");
|
||||
expect(ids).toContain("marble");
|
||||
expect(ids).toContain("concrete");
|
||||
expect(ids).toContain("metal");
|
||||
expect(ids).toContain("glass");
|
||||
expect(ids).toContain("grass");
|
||||
});
|
||||
|
||||
it("retrieves valid texture definitions with correct physical material properties", () => {
|
||||
const glassDef = getTextureDefinition("glass");
|
||||
expect(glassDef.name).toBe("Buzlu / Cam");
|
||||
expect(glassDef.transparent).toBe(true);
|
||||
expect(glassDef.opacity).toBeLessThan(1);
|
||||
expect(glassDef.roughness).toBeLessThan(0.3);
|
||||
|
||||
const metalDef = getTextureDefinition("metal");
|
||||
expect(metalDef.metalness).toBeGreaterThan(0.8);
|
||||
|
||||
const woodDef = getTextureDefinition("wood");
|
||||
expect(woodDef.category).toBe("Doğal");
|
||||
|
||||
const fallbackDef = getTextureDefinition("none");
|
||||
expect(fallbackDef.id).toBe("none");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Architectural Section Plane System (SketchUp Style)", () => {
|
||||
it("creates accurate clipping plane along Y axis (Elevation / Floor Plan Cut)", () => {
|
||||
const settings: SectionPlaneSettings = {
|
||||
enabled: true,
|
||||
axis: "y",
|
||||
offset: 25,
|
||||
invert: false,
|
||||
showGizmo: true,
|
||||
};
|
||||
|
||||
const plane = createSectionClippingPlane(settings);
|
||||
// Y-axis normal pointing down by default: (0, -1, 0)
|
||||
expect(plane.normal.x).toBe(0);
|
||||
expect(plane.normal.y).toBe(-1);
|
||||
expect(plane.normal.z).toBe(0);
|
||||
// Point on plane at y=25: distanceToPoint((0, 25, 0)) should be 0
|
||||
expect(plane.distanceToPoint(new THREE.Vector3(0, 25, 0))).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
it("inverts plane normal when invert flag is true", () => {
|
||||
const normalCut: SectionPlaneSettings = {
|
||||
enabled: true,
|
||||
axis: "x",
|
||||
offset: 10,
|
||||
invert: false,
|
||||
showGizmo: true,
|
||||
};
|
||||
const invertedCut: SectionPlaneSettings = {
|
||||
...normalCut,
|
||||
invert: true,
|
||||
};
|
||||
|
||||
const p1 = createSectionClippingPlane(normalCut);
|
||||
const p2 = createSectionClippingPlane(invertedCut);
|
||||
|
||||
expect(p1.normal.x).toBe(-p2.normal.x);
|
||||
});
|
||||
|
||||
it("builds and updates visual section gizmo with plane, border, and direction arrow", () => {
|
||||
const settings: SectionPlaneSettings = {
|
||||
...DEFAULT_SECTION_PLANE,
|
||||
offset: 40,
|
||||
};
|
||||
|
||||
const gizmo = createSectionPlaneGizmo(settings, 200);
|
||||
expect(gizmo.name).toBe("section-plane-gizmo");
|
||||
expect(gizmo.children.length).toBeGreaterThanOrEqual(4);
|
||||
|
||||
// Position check
|
||||
expect(gizmo.position.y).toBe(40);
|
||||
|
||||
// Update transform to X axis
|
||||
updateSectionGizmoTransform(gizmo, { ...settings, axis: "x", offset: -30 });
|
||||
expect(gizmo.position.x).toBe(-30);
|
||||
expect(gizmo.position.y).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Physics & Gravity Simulation Engine (Cannon-es)", () => {
|
||||
it("initializes physics world and maps 3D shapes to rigid bodies", () => {
|
||||
const shapes: WorkplaneShape[] = [
|
||||
{
|
||||
id: "box-1",
|
||||
name: "Kutu 1",
|
||||
kind: "box",
|
||||
color: "#3b82f6",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 0,
|
||||
size: 20,
|
||||
width: 20,
|
||||
depth: 20,
|
||||
height: 20,
|
||||
rotation: 0,
|
||||
},
|
||||
{
|
||||
id: "box-2",
|
||||
name: "Kutu 2 (Üstte)",
|
||||
kind: "box",
|
||||
color: "#ef4444",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 20,
|
||||
size: 20,
|
||||
width: 20,
|
||||
depth: 20,
|
||||
height: 20,
|
||||
rotation: 0,
|
||||
},
|
||||
];
|
||||
|
||||
const meshMap = new Map<string, THREE.Object3D>();
|
||||
for (const s of shapes) {
|
||||
const mesh = new THREE.Mesh();
|
||||
mesh.position.set(s.x, (s.elevation ?? 0) + s.height / 2, s.z);
|
||||
meshMap.set(s.id, mesh);
|
||||
}
|
||||
|
||||
let statusReport: any = null;
|
||||
const sandbox = new PhysicsSandbox((st) => {
|
||||
statusReport = st;
|
||||
});
|
||||
|
||||
sandbox.initWorld(shapes, meshMap);
|
||||
expect(statusReport).not.toBeNull();
|
||||
expect(statusReport.active).toBe(true);
|
||||
expect(statusReport.bodiesCount).toBe(2);
|
||||
|
||||
// Start simulation
|
||||
sandbox.start();
|
||||
expect(statusReport.running).toBe(true);
|
||||
|
||||
// Pause simulation
|
||||
sandbox.pause();
|
||||
expect(statusReport.running).toBe(false);
|
||||
|
||||
// Reset restores meshes
|
||||
sandbox.reset();
|
||||
expect(meshMap.get("box-2")!.position.y).toBe(30);
|
||||
|
||||
sandbox.stop();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const getComponentSource = (filename: string) => {
|
||||
const filePath = path.resolve(__dirname, "../../apps/web/src/components/snapcad", filename);
|
||||
return fs.readFileSync(filePath, "utf-8");
|
||||
};
|
||||
|
||||
const getAppLayoutSource = () => {
|
||||
const filePath = path.resolve(__dirname, "../../apps/web/src/app/layout.tsx");
|
||||
return fs.readFileSync(filePath, "utf-8");
|
||||
};
|
||||
|
||||
const getPageSource = () => {
|
||||
const filePath = path.resolve(__dirname, "../../apps/web/src/app/page.tsx");
|
||||
return fs.readFileSync(filePath, "utf-8");
|
||||
};
|
||||
|
||||
describe("Page Transition, Preloader & Google Cloud Console Cascade Loading", () => {
|
||||
it("renders non-blocking Google Cloud Console linear progress bar and skeleton grid", () => {
|
||||
const pageSrc = getPageSource();
|
||||
expect(pageSrc).toContain("gcp-linear-progress");
|
||||
expect(pageSrc).toContain("gcp-skeleton-grid");
|
||||
expect(pageSrc).toContain("project-card-skeleton");
|
||||
expect(pageSrc).toContain('role="progressbar"');
|
||||
expect(pageSrc).toContain('aria-hidden="true"');
|
||||
});
|
||||
|
||||
it("hides transient visual skeleton cards from screen readers to prevent cluttering accessibility tree", () => {
|
||||
const pageSrc = getPageSource();
|
||||
expect(pageSrc).not.toContain("kart ${num} / 6");
|
||||
expect(pageSrc).not.toContain("kart ${num} / 3");
|
||||
expect(pageSrc).toContain('className="project-grid gcp-skeleton-grid"\n aria-hidden="true"');
|
||||
});
|
||||
|
||||
it("page.tsx implements Google Cloud Console top-to-bottom cascade waterfall classes without robotic initial announcements", () => {
|
||||
const pageSrc = getPageSource();
|
||||
expect(pageSrc).toContain("gcp-cascade-topbar");
|
||||
expect(pageSrc).toContain("gcp-cascade-sidebar");
|
||||
expect(pageSrc).toContain("gcp-cascade-actions");
|
||||
expect(pageSrc).toContain("gcp-cascade-starters");
|
||||
expect(pageSrc).toContain("gcp-cascade-header");
|
||||
expect(pageSrc).toContain("gcp-cascade-card");
|
||||
expect(pageSrc).toContain("gcp-cascade-footer");
|
||||
// Sayfa açılışında ekran okuyucuya yapay/aşağılayıcı anons yapılmaz
|
||||
expect(pageSrc).not.toContain("SnapCAD Studio çalışma alanı üstten alta başarıyla yüklendi");
|
||||
});
|
||||
|
||||
it("RootLayout includes NextTopLoader and inline anti-FOUC theme script to prevent white flash", () => {
|
||||
const layoutSrc = getAppLayoutSource();
|
||||
expect(layoutSrc).toContain("NextTopLoader");
|
||||
expect(layoutSrc).toContain("AppErrorBoundary");
|
||||
expect(layoutSrc).toContain("sketchforge.theme.preference");
|
||||
expect(layoutSrc).toContain("document.documentElement.style.backgroundColor");
|
||||
});
|
||||
|
||||
it("AppErrorBoundary safely catches exceptions and prevents white screen of death", () => {
|
||||
const errorBoundarySrc = getComponentSource("AppErrorBoundary.tsx");
|
||||
expect(errorBoundarySrc).toContain("SnapCAD Studio Yükleme Kurtarma");
|
||||
expect(errorBoundarySrc).toContain("Sayfayı Yeniden Yükle");
|
||||
expect(errorBoundarySrc).toContain("Güvenli Modda Başlat");
|
||||
});
|
||||
|
||||
it("strictly prohibits banned competitor name", () => {
|
||||
const preloaderSrc = getComponentSource("SnapCADAppPreloader.tsx");
|
||||
const errorBoundarySrc = getComponentSource("AppErrorBoundary.tsx");
|
||||
expect(preloaderSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
expect(errorBoundarySrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,133 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
describe("Architectural Layers & Tags System", () => {
|
||||
const sampleShapes: WorkplaneShape[] = [
|
||||
{
|
||||
id: "wall-1",
|
||||
name: "Dış Duvar",
|
||||
kind: "box",
|
||||
color: "#f8fafc",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 50,
|
||||
depth: 40,
|
||||
height: 30,
|
||||
size: 50,
|
||||
rotation: 0,
|
||||
tag: "Duvarlar",
|
||||
hidden: false,
|
||||
},
|
||||
{
|
||||
id: "roof-1",
|
||||
name: "Kırma Çatı",
|
||||
kind: "pyramid",
|
||||
color: "#ef4444",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 30,
|
||||
width: 54,
|
||||
depth: 44,
|
||||
height: 20,
|
||||
size: 54,
|
||||
rotation: 0,
|
||||
tag: "Çatı",
|
||||
hidden: false,
|
||||
},
|
||||
{
|
||||
id: "door-1",
|
||||
name: "Giriş Kapısı Boşluğu",
|
||||
kind: "box",
|
||||
hole: true,
|
||||
color: "#000000",
|
||||
x: 0,
|
||||
z: 20,
|
||||
width: 10,
|
||||
depth: 12,
|
||||
height: 20,
|
||||
size: 20,
|
||||
rotation: 0,
|
||||
tag: "Kapı & Boşluklar",
|
||||
hidden: false,
|
||||
},
|
||||
];
|
||||
|
||||
it("correctly groups shapes into distinct architectural tags", () => {
|
||||
const tagMap = new Map<string, WorkplaneShape[]>();
|
||||
sampleShapes.forEach((s) => {
|
||||
const tag = s.tag || "Katman 0 (Genel)";
|
||||
const list = tagMap.get(tag) || [];
|
||||
list.push(s);
|
||||
tagMap.set(tag, list);
|
||||
});
|
||||
|
||||
expect(tagMap.has("Duvarlar")).toBe(true);
|
||||
expect(tagMap.has("Çatı")).toBe(true);
|
||||
expect(tagMap.has("Kapı & Boşluklar")).toBe(true);
|
||||
expect(tagMap.get("Çatı")?.length).toBe(1);
|
||||
expect(tagMap.get("Çatı")?.[0].id).toBe("roof-1");
|
||||
});
|
||||
|
||||
it("toggling tag visibility hides only shapes in the target tag", () => {
|
||||
const targetTag = "Çatı";
|
||||
const updated = sampleShapes.map((s) => {
|
||||
if (s.tag === targetTag) {
|
||||
return { ...s, hidden: true };
|
||||
}
|
||||
return s;
|
||||
});
|
||||
|
||||
const roof = updated.find((s) => s.id === "roof-1");
|
||||
const wall = updated.find((s) => s.id === "wall-1");
|
||||
const door = updated.find((s) => s.id === "door-1");
|
||||
|
||||
expect(roof?.hidden).toBe(true);
|
||||
expect(wall?.hidden).toBe(false);
|
||||
expect(door?.hidden).toBe(false);
|
||||
});
|
||||
|
||||
it("defaults un-tagged shapes to 'Katman 0 (Genel)'", () => {
|
||||
const genericShape: WorkplaneShape = {
|
||||
id: "cube-new",
|
||||
name: "Kutu",
|
||||
kind: "box",
|
||||
color: "#cbd5e1",
|
||||
x: 20,
|
||||
z: 20,
|
||||
width: 20,
|
||||
depth: 20,
|
||||
height: 20,
|
||||
size: 20,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
const assignedTag = (genericShape.tag && genericShape.tag.trim()) || "Katman 0 (Genel)";
|
||||
expect(assignedTag).toBe("Katman 0 (Genel)");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,184 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
polygon2dUnion,
|
||||
polygon2dDifference,
|
||||
polygon2dIntersection,
|
||||
polygon2dXor,
|
||||
cadBezierArcLength,
|
||||
sampleCadBezier,
|
||||
cadBezierNormal,
|
||||
cadBezierTangent,
|
||||
cadBezierOffset,
|
||||
cadBezierIntersections,
|
||||
applyHorizontalConstraint,
|
||||
applyVerticalConstraint,
|
||||
applyDistanceConstraint,
|
||||
applyParallelConstraint,
|
||||
applyPerpendicularConstraint,
|
||||
applyTangentConstraint,
|
||||
applyConcentricConstraint,
|
||||
type CadBezierCurve,
|
||||
type Point2D,
|
||||
} from "@/lib/cad2dEngine";
|
||||
|
||||
describe("2D CAD Engine - Polygon Booleans via polygon-clipping", () => {
|
||||
const squareA: Point2D[] = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 20, y: 0 },
|
||||
{ x: 20, y: 20 },
|
||||
{ x: 0, y: 20 },
|
||||
];
|
||||
|
||||
const squareB: Point2D[] = [
|
||||
{ x: 10, y: 10 },
|
||||
{ x: 30, y: 10 },
|
||||
{ x: 30, y: 30 },
|
||||
{ x: 10, y: 30 },
|
||||
];
|
||||
|
||||
it("calculates 2D boolean union of two overlapping squares", () => {
|
||||
const unionResult = polygon2dUnion(squareA, squareB);
|
||||
expect(unionResult.length).toBe(1);
|
||||
expect(unionResult[0].outer.length).toBeGreaterThanOrEqual(6); // L-like merged contour
|
||||
});
|
||||
|
||||
it("calculates 2D boolean difference (A - B)", () => {
|
||||
const diffResult = polygon2dDifference(squareA, squareB);
|
||||
expect(diffResult.length).toBe(1);
|
||||
// Difference cuts out the overlapping [10,10]->[20,20] area
|
||||
expect(diffResult[0].outer.length).toBeGreaterThanOrEqual(6);
|
||||
});
|
||||
|
||||
it("calculates 2D boolean difference creating an inner hole when B is inside A", () => {
|
||||
const innerSquare: Point2D[] = [
|
||||
{ x: 5, y: 5 },
|
||||
{ x: 15, y: 5 },
|
||||
{ x: 15, y: 15 },
|
||||
{ x: 5, y: 15 },
|
||||
];
|
||||
const holeResult = polygon2dDifference(squareA, innerSquare);
|
||||
expect(holeResult.length).toBe(1);
|
||||
expect(holeResult[0].holes.length).toBe(1);
|
||||
expect(holeResult[0].holes[0].length).toBe(4);
|
||||
});
|
||||
|
||||
it("calculates 2D boolean intersection (A ∩ B)", () => {
|
||||
const intersectResult = polygon2dIntersection(squareA, squareB);
|
||||
expect(intersectResult.length).toBe(1);
|
||||
expect(intersectResult[0].outer.length).toBe(4); // 10x10 square
|
||||
});
|
||||
|
||||
it("calculates 2D boolean XOR", () => {
|
||||
const xorResult = polygon2dXor(squareA, squareB);
|
||||
expect(xorResult.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("2D CAD Engine - Parametric Bezier Engine via bezier-js", () => {
|
||||
const curve: CadBezierCurve = {
|
||||
p0: { x: 0, y: 0 },
|
||||
p1: { x: 10, y: 30 },
|
||||
p2: { x: 30, y: 30 },
|
||||
p3: { x: 40, y: 0 },
|
||||
};
|
||||
|
||||
it("computes exact arc length of cubic Bezier curve", () => {
|
||||
const length = cadBezierArcLength(curve);
|
||||
expect(length).toBeGreaterThan(40);
|
||||
expect(length).toBeLessThan(100);
|
||||
});
|
||||
|
||||
it("samples discrete polyline points along the curve", () => {
|
||||
const samples = sampleCadBezier(curve, 10);
|
||||
expect(samples.length).toBe(11);
|
||||
expect(samples[0]).toEqual({ x: 0, y: 0 });
|
||||
expect(samples[samples.length - 1]).toEqual({ x: 40, y: 0 });
|
||||
});
|
||||
|
||||
it("calculates tangent and normal direction unit vectors", () => {
|
||||
const tangent = cadBezierTangent(curve, 0.5);
|
||||
const normal = cadBezierNormal(curve, 0.5);
|
||||
|
||||
expect(Math.hypot(tangent.x, tangent.y)).toBeCloseTo(1, 2);
|
||||
expect(Math.hypot(normal.x, normal.y)).toBeCloseTo(1, 2);
|
||||
// Tangent and normal must be orthogonal (dot product = 0)
|
||||
expect(tangent.x * normal.x + tangent.y * normal.y).toBeCloseTo(0, 2);
|
||||
});
|
||||
|
||||
it("calculates parallel offset curves for CAD wall/et kalınlığı", () => {
|
||||
const offsets = cadBezierOffset(curve, 5);
|
||||
expect(offsets.length).toBeGreaterThan(0);
|
||||
expect(offsets[0].length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("calculates intersection points between two Bezier curves", () => {
|
||||
const crossingCurve: CadBezierCurve = {
|
||||
p0: { x: 20, y: -10 },
|
||||
p1: { x: 20, y: 15 },
|
||||
p2: { x: 20, y: 25 },
|
||||
p3: { x: 20, y: 40 },
|
||||
};
|
||||
const intersections = cadBezierIntersections(curve, crossingCurve);
|
||||
expect(intersections.length).toBeGreaterThanOrEqual(1);
|
||||
expect(intersections[0].x).toBeCloseTo(20, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("2D CAD Engine - Geometric Constraints & Snapping", () => {
|
||||
it("enforces horizontal constraint (Y alignment)", () => {
|
||||
const p1 = { x: 10, y: 25 };
|
||||
const p2 = { x: 50, y: 80 };
|
||||
const adjusted = applyHorizontalConstraint(p1, p2);
|
||||
expect(adjusted).toEqual({ x: 50, y: 25 });
|
||||
});
|
||||
|
||||
it("enforces vertical constraint (X alignment)", () => {
|
||||
const p1 = { x: 10, y: 25 };
|
||||
const p2 = { x: 50, y: 80 };
|
||||
const adjusted = applyVerticalConstraint(p1, p2);
|
||||
expect(adjusted).toEqual({ x: 10, y: 80 });
|
||||
});
|
||||
|
||||
it("enforces fixed distance constraint along direction vector", () => {
|
||||
const p1 = { x: 0, y: 0 };
|
||||
const p2 = { x: 30, y: 40 }; // Current distance is 50
|
||||
const adjusted = applyDistanceConstraint(p1, p2, 100);
|
||||
expect(Math.hypot(adjusted.x - p1.x, adjusted.y - p1.y)).toBeCloseTo(100, 3);
|
||||
expect(adjusted.x).toBeCloseTo(60, 3);
|
||||
expect(adjusted.y).toBeCloseTo(80, 3);
|
||||
});
|
||||
|
||||
it("enforces parallel constraint between two segments", () => {
|
||||
const fixed: [Point2D, Point2D] = [{ x: 0, y: 0 }, { x: 10, y: 0 }]; // Horizontal line
|
||||
const moving: [Point2D, Point2D] = [{ x: 5, y: 5 }, { x: 15, y: 25 }]; // Slanted line of length ~22.36
|
||||
const [m1, m2] = applyParallelConstraint(fixed, moving);
|
||||
expect(m1).toEqual({ x: 5, y: 5 });
|
||||
expect(m2.y).toBeCloseTo(5, 3); // Must be strictly horizontal now
|
||||
});
|
||||
|
||||
it("enforces perpendicular constraint (90 degrees)", () => {
|
||||
const fixed: [Point2D, Point2D] = [{ x: 0, y: 0 }, { x: 10, y: 0 }]; // Horizontal line
|
||||
const moving: [Point2D, Point2D] = [{ x: 5, y: 5 }, { x: 20, y: 10 }]; // Slanted
|
||||
const [m1, m2] = applyPerpendicularConstraint(fixed, moving);
|
||||
expect(m1).toEqual({ x: 5, y: 5 });
|
||||
expect(m2.x).toBeCloseTo(5, 3); // Must be strictly vertical
|
||||
});
|
||||
|
||||
it("enforces tangent constraint between circle and line", () => {
|
||||
const center = { x: 50, y: 50 };
|
||||
const radius = 20;
|
||||
const lineStart = { x: 0, y: 50 };
|
||||
const [start, tangent] = applyTangentConstraint(center, radius, lineStart);
|
||||
expect(start).toEqual(lineStart);
|
||||
// Distance from circle center to tangent point must equal radius
|
||||
const distToCenter = Math.hypot(tangent.x - center.x, tangent.y - center.y);
|
||||
expect(distToCenter).toBeCloseTo(radius, 2);
|
||||
});
|
||||
|
||||
it("enforces concentric constraint", () => {
|
||||
const fixedCenter = { x: 100, y: 200 };
|
||||
const concentric = applyConcentricConstraint(fixedCenter, 35);
|
||||
expect(concentric.center).toEqual(fixedCenter);
|
||||
expect(concentric.radius).toBe(35);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,175 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { compileBlocksToCpp, DEFAULT_BLOCKS } from "@/components/snapcad/circuits/blocksEngine";
|
||||
import {
|
||||
COMPONENTS_CATALOG,
|
||||
COMPONENT_CATEGORIES,
|
||||
getPinsForComponent,
|
||||
} from "@/components/snapcad/circuits/componentsCatalog";
|
||||
import { ARDUINO_LIBRARIES } from "@/components/snapcad/circuits/librariesData";
|
||||
import { executeSimulationTick } from "@/components/snapcad/circuits/simulationEngine";
|
||||
import { CIRCUIT_TEMPLATES } from "@/components/snapcad/circuits/templates";
|
||||
import type { CircuitComponent } from "@/components/snapcad/circuits/types";
|
||||
|
||||
describe("Circuits Studio - Components Catalog & Studio Parity", () => {
|
||||
it("contains all essential circuit components", () => {
|
||||
const keys = Object.keys(COMPONENTS_CATALOG);
|
||||
expect(keys).toContain("arduino_uno");
|
||||
expect(keys).toContain("arduino_nano");
|
||||
expect(keys).toContain("esp32");
|
||||
expect(keys).toContain("stepper_motor");
|
||||
expect(keys).toContain("dht11");
|
||||
expect(keys).toContain("joystick");
|
||||
expect(keys).toContain("oscilloscope");
|
||||
expect(keys).toContain("breadboard");
|
||||
expect(keys).toContain("battery_9v");
|
||||
expect(keys).toContain("rgb_led");
|
||||
expect(keys).toContain("seven_segment");
|
||||
expect(keys).toContain("servo");
|
||||
expect(keys).toContain("dc_motor");
|
||||
expect(keys).toContain("pir_sensor");
|
||||
expect(keys).toContain("ultrasonic");
|
||||
expect(keys).toContain("lcd16x2");
|
||||
expect(keys).toContain("oled128x64");
|
||||
expect(keys).toContain("relay");
|
||||
expect(keys).toContain("keypad4x4");
|
||||
expect(keys.length).toBeGreaterThanOrEqual(34);
|
||||
});
|
||||
|
||||
it("provides valid categories with descriptions", () => {
|
||||
expect(COMPONENT_CATEGORIES.length).toBe(6);
|
||||
for (const cat of COMPONENT_CATEGORIES) {
|
||||
expect(cat.label).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
it("calculates transformed pin coordinates when component is rotated", () => {
|
||||
const defaultUno: CircuitComponent = {
|
||||
id: "uno1",
|
||||
kind: "arduino_uno",
|
||||
name: "Uno",
|
||||
x: 100,
|
||||
y: 100,
|
||||
rotation: 0,
|
||||
};
|
||||
const rot0Pins = getPinsForComponent(defaultUno);
|
||||
const d13Pin0 = rot0Pins.find((p) => p.id === "D13");
|
||||
expect(d13Pin0).toBeDefined();
|
||||
|
||||
const rot90Uno: CircuitComponent = {
|
||||
...defaultUno,
|
||||
rotation: 90,
|
||||
};
|
||||
const rot90Pins = getPinsForComponent(rot90Uno);
|
||||
const d13Pin90 = rot90Pins.find((p) => p.id === "D13");
|
||||
expect(d13Pin90).toBeDefined();
|
||||
expect(d13Pin90?.relX).not.toBe(d13Pin0?.relX);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Circuits Studio - Arduino Simulation Engine", () => {
|
||||
it("activates danger alarm pins when ultrasonic distance is under 25cm", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "uno1", kind: "arduino_uno", name: "Uno", x: 0, y: 0 },
|
||||
{ id: "ult1", kind: "ultrasonic", name: "Sonar", x: 100, y: 100, distanceCm: 15 },
|
||||
];
|
||||
const code = "if (distanceCm < 25) { digitalWrite(13, HIGH); tone(8, 880); }";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.buzzerActive).toBe(true);
|
||||
expect(result.activePins[13]?.digital).toBe(true);
|
||||
expect(result.activePins[8]?.digital).toBe(true);
|
||||
expect(result.plotterValues["Mesafe_cm"]).toBe(15);
|
||||
});
|
||||
|
||||
it("calculates servo angle from potentiometer analog values", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "uno1", kind: "arduino_uno", name: "Uno", x: 0, y: 0 },
|
||||
{ id: "pot1", kind: "potentiometer", name: "Pot", x: 100, y: 100, potValue: 1023 },
|
||||
{ id: "srv1", kind: "servo", name: "Servo", x: 200, y: 100, servoAngle: 0 },
|
||||
];
|
||||
const code = "myServo.write(aci);";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.componentsPatch["srv1"]?.servoAngle).toBe(180);
|
||||
expect(result.plotterValues["Servo_Aci"]).toBe(180);
|
||||
});
|
||||
|
||||
it("simulates pure DC battery circuits without microcontroller", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "bat1", kind: "battery_9v", name: "9V Pil", x: 0, y: 0, batteryVoltage: 9 },
|
||||
{ id: "sw1", kind: "slide_switch", name: "Anahtar", x: 50, y: 0, switchOn: true },
|
||||
];
|
||||
const code = "// Pil devresi";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.activePins[13]?.voltage).toBe(9);
|
||||
expect(result.plotterValues["V_Bat"]).toBe(9);
|
||||
});
|
||||
it("simulates stepper motor step rotation and ULN2003 coil switching", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "nano1", kind: "arduino_nano", name: "Nano", x: 0, y: 0 },
|
||||
{ id: "stp1", kind: "stepper_motor", name: "28BYJ-48", x: 100, y: 100, stepperAngle: 0, stepperCoils: 0 },
|
||||
];
|
||||
const code = "stepper.step(1);";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.componentsPatch["stp1"]?.stepperAngle).toBe(22.5);
|
||||
expect(result.componentsPatch["stp1"]?.stepperCoils).toEqual([false, true, false, false]);
|
||||
expect(result.activePins[9]?.digital).toBe(true);
|
||||
expect(result.plotterValues["Step_Aci"]).toBe(22.5);
|
||||
});
|
||||
|
||||
it("simulates joystick coordinate tracking and servo steering", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "esp1", kind: "esp32", name: "ESP32", x: 0, y: 0 },
|
||||
{ id: "joy1", kind: "joystick", name: "Joystick", x: 100, y: 100, joystickX: 900, joystickY: 512, joystickPressed: false },
|
||||
{ id: "srv1", kind: "servo", name: "Servo", x: 200, y: 100, servoAngle: 90 },
|
||||
];
|
||||
const code = "servo.write(map(analogRead(A0), 0, 1023, 0, 180));";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.componentsPatch["srv1"]?.servoAngle).toBe(158);
|
||||
expect(result.plotterValues["Joy_X"]).toBe(900);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Circuits Studio - Block Coding & C++ Compiler", () => {
|
||||
it("compiles visual blocks into valid Arduino C++ setup and loop syntax", () => {
|
||||
const code = compileBlocksToCpp(DEFAULT_BLOCKS);
|
||||
expect(code).toContain("void setup()");
|
||||
expect(code).toContain("void loop()");
|
||||
expect(code).toContain("pinMode(13, OUTPUT);");
|
||||
expect(code).toContain("digitalWrite(13, HIGH);");
|
||||
expect(code).toContain("delay(1000);");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Circuits Studio - Arduino Libraries & Templates", () => {
|
||||
it("includes all requested standard Arduino libraries with documentation", () => {
|
||||
expect(ARDUINO_LIBRARIES.length).toBeGreaterThanOrEqual(12);
|
||||
const headers = ARDUINO_LIBRARIES.map((l) => l.header);
|
||||
expect(headers).toContain("<Servo.h>");
|
||||
expect(headers).toContain("<LiquidCrystal_I2C.h>");
|
||||
expect(headers).toContain("<Adafruit_NeoPixel.h>");
|
||||
expect(headers).toContain("<DHT.h>");
|
||||
expect(headers).toContain("<WiFi.h>");
|
||||
expect(headers).toContain("<SPI.h>");
|
||||
expect(headers).toContain("<AccelStepper.h>");
|
||||
expect(headers).toContain("<PubSubClient.h>");
|
||||
});
|
||||
|
||||
it("contains rich working project templates", () => {
|
||||
expect(CIRCUIT_TEMPLATES.length).toBeGreaterThanOrEqual(14);
|
||||
const ids = CIRCUIT_TEMPLATES.map((t) => t.id);
|
||||
expect(ids).toContain("stepper-motor-uln2003");
|
||||
expect(ids).toContain("dht11-weather-station");
|
||||
expect(ids).toContain("joystick-servo-control");
|
||||
expect(ids).toContain("esp32-iot-smart-device");
|
||||
|
||||
for (const tpl of CIRCUIT_TEMPLATES) {
|
||||
expect(tpl.components.length).toBeGreaterThan(0);
|
||||
expect(tpl.code).toContain("void setup");
|
||||
expect(tpl.code).toContain("void loop");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
describe("SnapCAD Classrooms & Collaborative Workspaces", () => {
|
||||
it("validates SNAP-XXXX class code format", () => {
|
||||
const isValidClassCode = (code: string) => /^SNAP-[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}$/.test(code);
|
||||
|
||||
expect(isValidClassCode("SNAP-ABCD")).toBe(true);
|
||||
expect(isValidClassCode("SNAP-8X9Y")).toBe(true);
|
||||
expect(isValidClassCode("SNAP-3333")).toBe(true);
|
||||
|
||||
// Invalid codes
|
||||
expect(isValidClassCode("SNAP-1234")).toBe(false); // 1 is excluded for visual ambiguity
|
||||
expect(isValidClassCode("SNAP-OOO0")).toBe(false); // O and 0 are excluded
|
||||
expect(isValidClassCode("snap-abcd")).toBe(false); // must be uppercase
|
||||
expect(isValidClassCode("INVALID")).toBe(false);
|
||||
expect(isValidClassCode("SNAP-ABC")).toBe(false);
|
||||
});
|
||||
|
||||
it("distinguishes between teacher, registered student, and K-12 guest student roles", () => {
|
||||
type MemberRole = "teacher" | "student" | "guest_student";
|
||||
|
||||
const resolveRolePermissions = (role: MemberRole) => ({
|
||||
canCreateActivity: role === "teacher",
|
||||
canGradeProjects: role === "teacher",
|
||||
canSubmitProject: role === "student" || role === "guest_student",
|
||||
requiresYakNetAccount: role === "teacher" || role === "student",
|
||||
isZeroBarrierK12: role === "guest_student",
|
||||
});
|
||||
|
||||
const teacherPerms = resolveRolePermissions("teacher");
|
||||
expect(teacherPerms.canCreateActivity).toBe(true);
|
||||
expect(teacherPerms.canGradeProjects).toBe(true);
|
||||
expect(teacherPerms.requiresYakNetAccount).toBe(true);
|
||||
|
||||
const studentPerms = resolveRolePermissions("student");
|
||||
expect(studentPerms.canCreateActivity).toBe(false);
|
||||
expect(studentPerms.canGradeProjects).toBe(false);
|
||||
expect(studentPerms.canSubmitProject).toBe(true);
|
||||
expect(studentPerms.requiresYakNetAccount).toBe(true);
|
||||
|
||||
const guestPerms = resolveRolePermissions("guest_student");
|
||||
expect(guestPerms.canSubmitProject).toBe(true);
|
||||
expect(guestPerms.requiresYakNetAccount).toBe(false);
|
||||
expect(guestPerms.isZeroBarrierK12).toBe(true);
|
||||
});
|
||||
|
||||
it("validates K-12 guest student nicknames", () => {
|
||||
const isValidNickname = (nickname: string) => {
|
||||
const trimmed = nickname.trim();
|
||||
return trimmed.length >= 2 && trimmed.length <= 32 && /^[a-zA-Z0-9_.-]+$/.test(trimmed);
|
||||
};
|
||||
|
||||
expect(isValidNickname("ahmet_8a")).toBe(true);
|
||||
expect(isValidNickname("can10")).toBe(true);
|
||||
expect(isValidNickname("zeynep.y")).toBe(true);
|
||||
expect(isValidNickname("a")).toBe(false); // too short
|
||||
expect(isValidNickname("")).toBe(false); // empty
|
||||
expect(isValidNickname("invalid nickname with spaces")).toBe(false);
|
||||
});
|
||||
|
||||
it("handles classroom project submission and teacher evaluation contract", () => {
|
||||
interface ClassroomProjectPayload {
|
||||
classroom_id: number;
|
||||
project_uid: string;
|
||||
title: string;
|
||||
studio_type: "3d-solid" | "circuits" | "codeblocks" | "drawing";
|
||||
shapes_count: number;
|
||||
project_json: { shapes: Array<{ id: string; name: string }> };
|
||||
teacher_grade?: string;
|
||||
teacher_feedback?: string;
|
||||
}
|
||||
|
||||
const project: ClassroomProjectPayload = {
|
||||
classroom_id: 42,
|
||||
project_uid: "project-abc-123",
|
||||
title: "Robot Gövdesi ve Sensör Yuvası",
|
||||
studio_type: "3d-solid",
|
||||
shapes_count: 5,
|
||||
project_json: {
|
||||
shapes: [
|
||||
{ id: "shape-1", name: "Gövde Küpü" },
|
||||
{ id: "shape-2", name: "Ultrasonik Sensör Deliği" },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(project.classroom_id).toBe(42);
|
||||
expect(project.studio_type).toBe("3d-solid");
|
||||
expect(project.project_json.shapes.length).toBe(2);
|
||||
|
||||
// Öğretmen notlandırması
|
||||
project.teacher_grade = "100/100";
|
||||
project.teacher_feedback = "Ölçüler ve toleranslar mükemmel hesaplanmış. Tebrikler!";
|
||||
|
||||
expect(project.teacher_grade).toBe("100/100");
|
||||
expect(project.teacher_feedback).toContain("toleranslar mükemmel");
|
||||
});
|
||||
|
||||
it("handles classroom edit validation and permission contract", () => {
|
||||
interface ClassroomEditPayload {
|
||||
classroom_id: number;
|
||||
teacher_user_id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
grade_level: string;
|
||||
subject: string;
|
||||
}
|
||||
|
||||
const validateEdit = (currentUserId: number, payload: ClassroomEditPayload) => {
|
||||
if (currentUserId <= 0) return { ok: false, error: "Giriş yapılmalı" };
|
||||
if (payload.classroom_id <= 0) return { ok: false, error: "Geçersiz sınıf ID" };
|
||||
if (!payload.title.trim()) return { ok: false, error: "Başlık zorunludur" };
|
||||
if (currentUserId !== payload.teacher_user_id) return { ok: false, error: "Yetkisiz işlem: Sadece sınıf öğretmeni düzenleyebilir" };
|
||||
return { ok: true, error: null };
|
||||
};
|
||||
|
||||
const payload: ClassroomEditPayload = {
|
||||
classroom_id: 10,
|
||||
teacher_user_id: 100,
|
||||
title: "Robotik Kulübü (Güncellendi)",
|
||||
description: "Yeni dönem çalışma planı",
|
||||
grade_level: "Lise (9-12. Sınıf)",
|
||||
subject: "3D CAD & Tasarım",
|
||||
};
|
||||
|
||||
// Öğretmen kendisi düzenlerse başarılı
|
||||
expect(validateEdit(100, payload)).toEqual({ ok: true, error: null });
|
||||
|
||||
// Başka bir kullanıcı düzenlemeye çalışırsa yetkisiz
|
||||
expect(validateEdit(999, payload).ok).toBe(false);
|
||||
|
||||
// Boş başlık reddedilir
|
||||
expect(validateEdit(100, { ...payload, title: "" }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it("handles classroom deletion cascade and permissions contract", () => {
|
||||
interface ClassroomDeleteRecord {
|
||||
id: number;
|
||||
teacher_user_id: number;
|
||||
title: string;
|
||||
}
|
||||
|
||||
const canDeleteClassroom = (userId: number, classroom: ClassroomDeleteRecord) => {
|
||||
return userId > 0 && userId === classroom.teacher_user_id;
|
||||
};
|
||||
|
||||
const classroom: ClassroomDeleteRecord = {
|
||||
id: 5,
|
||||
teacher_user_id: 42,
|
||||
title: "Teknoloji Tasarım 7-B",
|
||||
};
|
||||
|
||||
expect(canDeleteClassroom(42, classroom)).toBe(true);
|
||||
expect(canDeleteClassroom(99, classroom)).toBe(false);
|
||||
expect(canDeleteClassroom(0, classroom)).toBe(false);
|
||||
});
|
||||
|
||||
it("verifies aria-live polite announcements auto-clear after 5 seconds", () => {
|
||||
let announcement = "";
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const announce = (msg: string, autoClearMs = 5000) => {
|
||||
announcement = msg;
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
announcement = "";
|
||||
}, autoClearMs);
|
||||
};
|
||||
|
||||
announce("Sınıf listesi yüklendi.");
|
||||
expect(announcement).toBe("Sınıf listesi yüklendi.");
|
||||
|
||||
// Simüle edilen süre sonrasında temizleme fonksiyonu çalışır
|
||||
clearTimeout(timer!);
|
||||
announcement = "";
|
||||
expect(announcement).toBe("");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
estimateCloudProjectJsonBytes,
|
||||
formatByteSize,
|
||||
measureCloudProjectJsonBytes,
|
||||
shouldApplyCloudProjectShapes,
|
||||
shouldUploadLocalProjectToCloud,
|
||||
} from "@/lib/cloudProjectSync";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
function meshShape(id: string, positionCount: number): WorkplaneShape {
|
||||
return {
|
||||
id,
|
||||
name: id,
|
||||
kind: "box",
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
width: 10,
|
||||
height: 10,
|
||||
depth: 10,
|
||||
rotation: 0,
|
||||
color: "#ffffff",
|
||||
importedMesh: {
|
||||
positions: new Array(positionCount).fill(0.5),
|
||||
baseWidth: 10,
|
||||
baseDepth: 10,
|
||||
baseHeight: 10,
|
||||
triangleCount: Math.floor(positionCount / 9),
|
||||
sourceFormat: "dwg",
|
||||
},
|
||||
} as WorkplaneShape;
|
||||
}
|
||||
|
||||
describe("cloudProjectSync", () => {
|
||||
it("never lets an empty cloud copy erase local geometry", () => {
|
||||
expect(
|
||||
shouldApplyCloudProjectShapes({
|
||||
cloudRevision: 5_000,
|
||||
cloudShapeCount: 0,
|
||||
localRevision: 1_000,
|
||||
localShapeCount: 3,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("restores geometry from the cloud when the local copy is empty", () => {
|
||||
expect(
|
||||
shouldApplyCloudProjectShapes({
|
||||
cloudRevision: 5_000,
|
||||
cloudShapeCount: 2,
|
||||
localRevision: 9_000,
|
||||
localShapeCount: 0,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps local geometry when the local revision is newer", () => {
|
||||
expect(
|
||||
shouldApplyCloudProjectShapes({
|
||||
cloudRevision: 1_000,
|
||||
cloudShapeCount: 2,
|
||||
localRevision: 2_000,
|
||||
localShapeCount: 2,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("applies a cloud copy that is at least as new as the local copy", () => {
|
||||
expect(
|
||||
shouldApplyCloudProjectShapes({
|
||||
cloudRevision: 2_000,
|
||||
cloudShapeCount: 2,
|
||||
localRevision: 2_000,
|
||||
localShapeCount: 2,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not upload an empty payload for a project that reports shapes", () => {
|
||||
expect(shouldUploadLocalProjectToCloud({ metadataShapeCount: 4, resolvedShapeCount: 0 })).toBe(false);
|
||||
expect(shouldUploadLocalProjectToCloud({ metadataShapeCount: 0, resolvedShapeCount: 0 })).toBe(true);
|
||||
expect(shouldUploadLocalProjectToCloud({ metadataShapeCount: 4, resolvedShapeCount: 4 })).toBe(true);
|
||||
});
|
||||
|
||||
it("skips DWG-scale meshes before serializing them", () => {
|
||||
const shapes = [meshShape("dwg", 3_873_672)];
|
||||
const estimate = estimateCloudProjectJsonBytes(shapes);
|
||||
expect(estimate).toBeGreaterThan(4 * 1024 * 1024);
|
||||
const measured = measureCloudProjectJsonBytes(shapes, { shapes }, 4 * 1024 * 1024);
|
||||
expect(measured).toBe(estimate);
|
||||
});
|
||||
|
||||
it("measures small payloads exactly in UTF-8 bytes", () => {
|
||||
const shapes = [meshShape("small", 9)];
|
||||
const payload = { shapes, name: "Apartman Projesi" };
|
||||
expect(measureCloudProjectJsonBytes(shapes, payload, 4 * 1024 * 1024)).toBe(
|
||||
new TextEncoder().encode(JSON.stringify(payload)).length,
|
||||
);
|
||||
});
|
||||
|
||||
it("formats byte sizes for screen readers", () => {
|
||||
expect(formatByteSize(0)).toBe("0 KB");
|
||||
expect(formatByteSize(1536)).toBe("2 KB");
|
||||
expect(formatByteSize(7 * 1024 * 1024)).toBe("7,0 MB");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const getComponentSource = (filename: string) => {
|
||||
const filePath = path.resolve(__dirname, "../../apps/web/src/components/snapcad", filename);
|
||||
return fs.readFileSync(filePath, "utf-8");
|
||||
};
|
||||
|
||||
const getPageSource = (pagePath: string) => {
|
||||
const filePath = path.resolve(__dirname, "../../apps/web/src/app", pagePath, "page.tsx");
|
||||
return fs.readFileSync(filePath, "utf-8");
|
||||
};
|
||||
|
||||
describe("Corporate Legal Pages & YakNet Affiliation", () => {
|
||||
describe("PlatformFooter", () => {
|
||||
const footerSrc = getComponentSource("PlatformFooter.tsx");
|
||||
|
||||
it("explicitly states it is an official YakNet service and YakHub ecosystem platform", () => {
|
||||
expect(footerSrc).toContain("Resmi YakNet Hizmeti • YakHub Ekosistemi");
|
||||
expect(footerSrc).toContain("Resmi bir YakNet hizmetidir");
|
||||
expect(footerSrc).toContain("YakHub Ekosistemi");
|
||||
});
|
||||
|
||||
it("does not include the removed 'TR / Türkçe' language indicator", () => {
|
||||
expect(footerSrc).not.toContain("TR / Türkçe");
|
||||
expect(footerSrc).not.toContain("TR / Türkçe");
|
||||
});
|
||||
|
||||
it("includes functional links for KVKK & Gizlilik, Kullanım Koşulları, and Kurumsal Güvenlik", () => {
|
||||
expect(footerSrc).toContain("KVKK & Gizlilik");
|
||||
expect(footerSrc).toContain("Kullanım Koşulları");
|
||||
expect(footerSrc).toContain("Kurumsal Güvenlik");
|
||||
expect(footerSrc).toContain("/kvkk");
|
||||
expect(footerSrc).toContain("/kullanim-kosullari");
|
||||
expect(footerSrc).toContain("/kurumsal-guvenlik");
|
||||
});
|
||||
|
||||
it("does not mention banned competitor name", () => {
|
||||
expect(footerSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
});
|
||||
});
|
||||
|
||||
describe("KVKKPageContent & /kvkk route", () => {
|
||||
const kvkkSrc = getComponentSource("KVKKPageContent.tsx");
|
||||
const kvkkPageSrc = getPageSource("kvkk");
|
||||
|
||||
it("declares YakNet data controller and 6698 KVKK compliance", () => {
|
||||
expect(kvkkSrc).toContain("KVKK ve Gizlilik Politikası");
|
||||
expect(kvkkSrc).toContain("YakNet Bilgi ve İletişim Ağı (YakHub)");
|
||||
expect(kvkkSrc).toContain("6698");
|
||||
expect(kvkkSrc).toContain("[email protected]");
|
||||
expect(kvkkSrc).toContain("Local-First");
|
||||
expect(kvkkSrc).toContain("Resmi YakNet Hizmet Beyanı");
|
||||
});
|
||||
|
||||
it("has a valid Next.js App Router page for /kvkk", () => {
|
||||
expect(kvkkPageSrc).toContain("KVKKPageContent");
|
||||
expect(kvkkPageSrc).toContain("PlatformFooter");
|
||||
expect(kvkkPageSrc).toContain("Resmi YakNet Hizmeti • YakHub Ekosistemi");
|
||||
});
|
||||
|
||||
it("does not mention banned competitor name", () => {
|
||||
expect(kvkkSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
expect(kvkkPageSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
});
|
||||
});
|
||||
|
||||
describe("TermsPageContent & /kullanim-kosullari route", () => {
|
||||
const termsSrc = getComponentSource("TermsPageContent.tsx");
|
||||
const termsPageSrc = getPageSource("kullanim-kosullari");
|
||||
|
||||
it("guarantees 100% intellectual property ownership of 3D designs to user", () => {
|
||||
expect(termsSrc).toContain("Kullanım Koşulları");
|
||||
expect(termsSrc).toContain("3B Modellerinizin Mülkiyeti: %100 Size Aittir");
|
||||
expect(termsSrc).toContain("AGPLv3");
|
||||
expect(termsSrc).toContain("YakNet");
|
||||
expect(termsSrc).toContain("Resmi YakNet ve YakHub Ekosistemi Hizmeti");
|
||||
});
|
||||
|
||||
it("has a valid Next.js App Router page for /kullanim-kosullari", () => {
|
||||
expect(termsPageSrc).toContain("TermsPageContent");
|
||||
expect(termsPageSrc).toContain("PlatformFooter");
|
||||
expect(termsPageSrc).toContain("Resmi YakNet Hizmeti • YakHub Ekosistemi");
|
||||
});
|
||||
|
||||
it("does not mention banned competitor name", () => {
|
||||
expect(termsSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
expect(termsPageSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
});
|
||||
});
|
||||
|
||||
describe("SecurityPageContent & /kurumsal-guvenlik route", () => {
|
||||
const secSrc = getComponentSource("SecurityPageContent.tsx");
|
||||
const secPageSrc = getPageSource("kurumsal-guvenlik");
|
||||
|
||||
it("documents client-side WASM geometry processing, TLS 1.3, and YakNet SSO", () => {
|
||||
expect(secSrc).toContain("Kurumsal Güvenlik");
|
||||
expect(secSrc).toContain("Zero-Knowledge");
|
||||
expect(secSrc).toContain("TLS 1.3");
|
||||
expect(secSrc).toContain("AES-256");
|
||||
expect(secSrc).toContain("YakNet SSO");
|
||||
expect(secSrc).toContain("YakNet Kurumsal Güvenlik Şemsiyesi");
|
||||
});
|
||||
|
||||
it("has a valid Next.js App Router page for /kurumsal-guvenlik", () => {
|
||||
expect(secPageSrc).toContain("SecurityPageContent");
|
||||
expect(secPageSrc).toContain("PlatformFooter");
|
||||
expect(secPageSrc).toContain("Resmi YakNet Hizmeti • YakHub Ekosistemi");
|
||||
});
|
||||
|
||||
it("does not mention banned competitor name", () => {
|
||||
expect(secSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
expect(secPageSrc.toLowerCase()).not.toContain("tinker" + "cad");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {
|
||||
MAX_DWG_BYTES,
|
||||
convertDwgBytesToDxf,
|
||||
importedShapeFromDwg,
|
||||
loadLibreDwgKernel,
|
||||
readDwgVersion,
|
||||
} from "@/lib/dwgKernel";
|
||||
|
||||
function asciiBytes(text: string) {
|
||||
return new Uint8Array(Array.from(text, (char) => char.charCodeAt(0)));
|
||||
}
|
||||
|
||||
describe("LibreDWG WebAssembly Kernel", () => {
|
||||
it("initializes LibreDWG WebAssembly module with virtual filesystem and cwrap", async () => {
|
||||
const wasm = await loadLibreDwgKernel();
|
||||
expect(wasm).toBeDefined();
|
||||
expect(wasm.FS).toBeDefined();
|
||||
expect(typeof wasm.FS.writeFile).toBe("function");
|
||||
expect(typeof wasm.FS.readFile).toBe("function");
|
||||
expect(typeof wasm.cwrap).toBe("function");
|
||||
});
|
||||
|
||||
it("reads the DWG version signature", () => {
|
||||
expect(readDwgVersion(asciiBytes("AC1032"))).toBe("AC1032");
|
||||
expect(readDwgVersion(asciiBytes("AC1015xxxxxxxx"))).toBe("AC1015");
|
||||
expect(readDwgVersion(asciiBytes("DXF"))).toBeNull();
|
||||
expect(readDwgVersion(asciiBytes("hello world"))).toBeNull();
|
||||
expect(readDwgVersion(new Uint8Array([]))).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects files without a DWG signature with a clear Turkish message", async () => {
|
||||
const notADwg = asciiBytes("Bu bir metin dosyasi, DWG degil. ".repeat(4));
|
||||
await expect(convertDwgBytesToDxf(notADwg)).rejects.toThrow(
|
||||
/geçerli bir AutoCAD DWG çizimi değil/,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects unsupported DWG versions with the supported range", async () => {
|
||||
const futureDwg = asciiBytes(`AC1035${"x".repeat(120)}`);
|
||||
await expect(convertDwgBytesToDxf(futureDwg)).rejects.toThrow(
|
||||
/Bu DWG sürümü \(AC1035\) desteklenmiyor/,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects oversized DWG files before loading the kernel", async () => {
|
||||
const tooLarge = new Uint8Array(MAX_DWG_BYTES + 1);
|
||||
tooLarge.set(asciiBytes("AC1032"), 0);
|
||||
await expect(convertDwgBytesToDxf(tooLarge)).rejects.toThrow(/DWG dosyası çok büyük/);
|
||||
});
|
||||
|
||||
it("handles corrupted/truncated DWG files with clear descriptive error", async () => {
|
||||
// Valid version signature but no readable DWG sections at all.
|
||||
const fakeDwgBytes = asciiBytes("AC1015\u0000\u0000\u0000\u0000");
|
||||
await expect(convertDwgBytesToDxf(fakeDwgBytes)).rejects.toThrow(
|
||||
/DWG çizimi DXF'e dönüştürülemedi \(dosya sürümü: AC1015/,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects empty bytes immediately", async () => {
|
||||
await expect(convertDwgBytesToDxf(new Uint8Array([]))).rejects.toThrow(
|
||||
/Geçersiz veya boş DWG dosyası/,
|
||||
);
|
||||
});
|
||||
|
||||
it("converts a real AutoCAD DWG file to DXF and constructs a 3D solid shape", async () => {
|
||||
const dwgPath = path.resolve(process.cwd(), "test_circle_2010.dwg");
|
||||
if (fs.existsSync(dwgPath)) {
|
||||
const bytes = fs.readFileSync(dwgPath);
|
||||
const shape = await importedShapeFromDwg("test_circle_2010.dwg", bytes);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
expect(shape.importedMesh?.baseWidth).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,645 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { exportMeshesToDxf, type DxfExportMesh } from "@/lib/dxfExport";
|
||||
import { dxfExtrusionDepthForSpan, importedShapeFromDxf } from "@/lib/dxfImport";
|
||||
|
||||
function makePrismMesh(): DxfExportMesh {
|
||||
// A simple 10x20x30 prism made of 12 triangles (6 rectangular faces)
|
||||
// X: 0 to 10, Y: 0 to 20, Z: 0 to 30
|
||||
const v = [
|
||||
[0, 0, 0], [10, 0, 0], [10, 20, 0], [0, 20, 0], // bottom (Z=0)
|
||||
[0, 0, 30], [10, 0, 30], [10, 20, 30], [0, 20, 30], // top (Z=30)
|
||||
] as [number, number, number][];
|
||||
|
||||
const faces: [number, number, number][] = [
|
||||
// Bottom (normal -Z)
|
||||
[0, 2, 1], [0, 3, 2],
|
||||
// Top (normal +Z)
|
||||
[4, 5, 6], [4, 6, 7],
|
||||
// Front (normal -Y)
|
||||
[0, 1, 5], [0, 5, 4],
|
||||
// Right (normal +X)
|
||||
[1, 2, 6], [1, 6, 5],
|
||||
// Back (normal +Y)
|
||||
[2, 3, 7], [2, 7, 6],
|
||||
// Left (normal -X)
|
||||
[3, 0, 4], [3, 4, 7],
|
||||
];
|
||||
|
||||
return {
|
||||
name: "prism_box",
|
||||
vertices: v,
|
||||
faces,
|
||||
};
|
||||
}
|
||||
|
||||
describe("DXF export and import", () => {
|
||||
it("exports 3D mesh triangles into valid AutoCAD DXF with 3DFACE entities and layers", () => {
|
||||
const mesh = makePrismMesh();
|
||||
const dxfString = exportMeshesToDxf([mesh]);
|
||||
|
||||
// Check DXF structure sections
|
||||
expect(dxfString).toContain("SECTION");
|
||||
expect(dxfString).toContain("HEADER");
|
||||
expect(dxfString).toContain("TABLES");
|
||||
expect(dxfString).toContain("ENTITIES");
|
||||
expect(dxfString).toContain("EOF");
|
||||
|
||||
// Check layer definitions
|
||||
expect(dxfString).toContain("3D_GEOMETRY");
|
||||
expect(dxfString).toContain("CUT_OUTLINE");
|
||||
|
||||
// Check 3DFACE entity generation
|
||||
expect(dxfString).toContain("3DFACE");
|
||||
const faceCount = (dxfString.match(/3DFACE/g) || []).length;
|
||||
expect(faceCount).toBe(mesh.faces.length);
|
||||
});
|
||||
|
||||
it("imports 3D DXF file and reconstructs a valid watertight WorkplaneShape", () => {
|
||||
const mesh = makePrismMesh();
|
||||
const dxfString = exportMeshesToDxf([mesh]);
|
||||
|
||||
const shape = importedShapeFromDxf("prism.dxf", dxfString);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.sourceFormat).toBe("dxf");
|
||||
expect(shape.importedMesh?.triangleCount).toBe(12);
|
||||
|
||||
// Bounding dimensions should match the prism: width=10 (X), height=20 (Y), depth=30 (Z)
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(10, 1);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(20, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(30, 1);
|
||||
|
||||
// Positions array length should be triangleCount * 9 (3 vertices * 3 coords)
|
||||
expect(shape.importedMesh?.positions.length).toBe(12 * 9);
|
||||
expect(shape.importedMesh?.normals?.length).toBe(12 * 9);
|
||||
});
|
||||
|
||||
it("imports 2D DXF with LWPOLYLINE contour and extrudes it into a 3D solid", () => {
|
||||
// Standard minimal 2D AutoCAD DXF with closed LWPOLYLINE (40x20 rectangle)
|
||||
const dxf2d = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
0
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
40.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
40.0
|
||||
20
|
||||
20.0
|
||||
10
|
||||
0.0
|
||||
20
|
||||
20.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("bracket_plate.dxf", dxf2d);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.sourceFormat).toBe("dxf");
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
|
||||
// 40x20 dimensions with default extrusion height (4mm)
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(40, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(20, 1);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(4, 1);
|
||||
});
|
||||
|
||||
it("imports 2D DXF with separate chained LINE entities and extrudes into a solid", () => {
|
||||
// DXF with 4 LINE entities forming a closed 30x30 square
|
||||
const dxfLines = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
0
|
||||
20
|
||||
0
|
||||
11
|
||||
30
|
||||
21
|
||||
0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
30
|
||||
20
|
||||
0
|
||||
11
|
||||
30
|
||||
21
|
||||
30
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
30
|
||||
20
|
||||
30
|
||||
11
|
||||
0
|
||||
21
|
||||
30
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
0
|
||||
20
|
||||
30
|
||||
11
|
||||
0
|
||||
21
|
||||
0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("square_contour.dxf", dxfLines);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.sourceFormat).toBe("dxf");
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(30, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(30, 1);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(4, 1);
|
||||
});
|
||||
|
||||
it("imports 2D DXF with CIRCLE entity and creates a cylindrical 3D solid", () => {
|
||||
// DXF with a CIRCLE of radius 15 at center (10, 10)
|
||||
const dxfCircle = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
CIRCLE
|
||||
8
|
||||
CUT_LAYER
|
||||
10
|
||||
10
|
||||
20
|
||||
10
|
||||
40
|
||||
15
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("spacer_disc.dxf", dxfCircle);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.sourceFormat).toBe("dxf");
|
||||
// Diameter is 2 * 15 = 30
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(30, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(30, 1);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(4, 1);
|
||||
});
|
||||
|
||||
it("correctly identifies inner hole in 2D profile and produces pierced solid body", () => {
|
||||
// Outer 50x50 rectangle with inner 20x20 hole (both LWPOLYLINEs)
|
||||
const dxfWithHole = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
OUTLINE
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
50.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
50.0
|
||||
20
|
||||
50.0
|
||||
10
|
||||
0.0
|
||||
20
|
||||
50.0
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
HOLES
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
15.0
|
||||
20
|
||||
15.0
|
||||
10
|
||||
35.0
|
||||
20
|
||||
15.0
|
||||
10
|
||||
35.0
|
||||
20
|
||||
35.0
|
||||
10
|
||||
15.0
|
||||
20
|
||||
35.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("flange_with_hole.dxf", dxfWithHole);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(50, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(50, 1);
|
||||
// Has both top/bottom triangulation and side walls for both outer and hole loops
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThanOrEqual(16);
|
||||
});
|
||||
|
||||
it("imports DXF with ARC entities and reconstructs watertight extruded solid using dxf-parser", () => {
|
||||
const dxfWithArc = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
40.0
|
||||
21
|
||||
0.0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
40.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
40.0
|
||||
21
|
||||
30.0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
40.0
|
||||
20
|
||||
30.0
|
||||
11
|
||||
0.0
|
||||
21
|
||||
30.0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
OUTLINE
|
||||
10
|
||||
0.0
|
||||
20
|
||||
30.0
|
||||
11
|
||||
0.0
|
||||
21
|
||||
0.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("bracket_with_lines.dxf", dxfWithArc);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(40, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(30, 1);
|
||||
});
|
||||
|
||||
it("imports AutoCAD DWG/DXF where entities reside inside *MODEL_SPACE block", () => {
|
||||
// Typical AutoCAD DWG conversion where ENTITIES section is empty and geometry is inside *MODEL_SPACE
|
||||
const dxfModelSpace = `0
|
||||
SECTION
|
||||
2
|
||||
BLOCKS
|
||||
0
|
||||
BLOCK
|
||||
2
|
||||
*MODEL_SPACE
|
||||
70
|
||||
0
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
30
|
||||
0.0
|
||||
3
|
||||
*MODEL_SPACE
|
||||
0
|
||||
LINE
|
||||
8
|
||||
WALLS
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
60.0
|
||||
21
|
||||
0.0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
WALLS
|
||||
10
|
||||
60.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
60.0
|
||||
21
|
||||
40.0
|
||||
0
|
||||
ENDBLK
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("floor_plan_modelspace.dxf", dxfModelSpace);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
expect(shape.importedMesh?.baseWidth).toBeGreaterThanOrEqual(60);
|
||||
expect(shape.importedMesh?.baseWidth).toBeLessThan(63);
|
||||
expect(shape.importedMesh?.baseDepth).toBeGreaterThanOrEqual(40);
|
||||
expect(shape.importedMesh?.baseDepth).toBeLessThan(43);
|
||||
});
|
||||
|
||||
it("imports unclosed architectural wall lines and extrudes into 3D wall ribbons", () => {
|
||||
// Open T-junction wall lines (cannot form any closed loop)
|
||||
const dxfOpenWalls = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LINE
|
||||
8
|
||||
WALLS
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
100.0
|
||||
21
|
||||
0.0
|
||||
0
|
||||
LINE
|
||||
8
|
||||
PARTITIONS
|
||||
10
|
||||
50.0
|
||||
20
|
||||
0.0
|
||||
11
|
||||
50.0
|
||||
21
|
||||
80.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("architectural_open_walls.dxf", dxfOpenWalls);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
// Should extrude without throwing any error, adding ribbon wall thickness
|
||||
expect(shape.importedMesh?.baseWidth).toBeGreaterThanOrEqual(100);
|
||||
expect(shape.importedMesh?.baseWidth).toBeLessThan(103);
|
||||
expect(shape.importedMesh?.baseDepth).toBeGreaterThanOrEqual(80);
|
||||
expect(shape.importedMesh?.baseDepth).toBeLessThan(83);
|
||||
expect(shape.importedMesh?.baseHeight).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("imports ELLIPSE and SOLID entities into watertight 3D solid mesh", () => {
|
||||
const dxfEllipseSolid = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
ELLIPSE
|
||||
8
|
||||
0
|
||||
10
|
||||
50.0
|
||||
20
|
||||
50.0
|
||||
30
|
||||
0.0
|
||||
11
|
||||
20.0
|
||||
21
|
||||
0.0
|
||||
31
|
||||
0.0
|
||||
40
|
||||
0.6
|
||||
41
|
||||
0.0
|
||||
42
|
||||
6.283185307179586
|
||||
0
|
||||
SOLID
|
||||
8
|
||||
0
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
30
|
||||
0.0
|
||||
11
|
||||
20.0
|
||||
21
|
||||
0.0
|
||||
31
|
||||
0.0
|
||||
12
|
||||
20.0
|
||||
22
|
||||
20.0
|
||||
32
|
||||
0.0
|
||||
13
|
||||
0.0
|
||||
23
|
||||
20.0
|
||||
33
|
||||
0.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
const shape = importedShapeFromDxf("ellipse_and_solid.dxf", dxfEllipseSolid);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("handles degenerate hairline loops gracefully without throwing 'konturların geçerli bir alanı bulunamadı'", () => {
|
||||
// A closed polyline with area = 0 (collinear back and forth line)
|
||||
const dxfDegenerate = `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
0
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
50.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
50.0
|
||||
20
|
||||
0.00001
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
|
||||
// Must not throw, instead converts hairline loop to wall ribbon
|
||||
const shape = importedShapeFromDxf("hairline_loop.dxf", dxfDegenerate);
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.triangleCount).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
function rectangleDxf(width: number, height: number) {
|
||||
return `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
0
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
${width}
|
||||
20
|
||||
0.0
|
||||
10
|
||||
${width}
|
||||
20
|
||||
${height}
|
||||
10
|
||||
0.0
|
||||
20
|
||||
${height}
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
}
|
||||
|
||||
describe("DXF extrusion depth scales with drawing size", () => {
|
||||
it("keeps a visible minimum thickness for small drawings", () => {
|
||||
expect(dxfExtrusionDepthForSpan(0)).toBe(4);
|
||||
expect(dxfExtrusionDepthForSpan(-10)).toBe(4);
|
||||
expect(dxfExtrusionDepthForSpan(Number.NaN)).toBe(4);
|
||||
expect(dxfExtrusionDepthForSpan(40)).toBe(4);
|
||||
expect(dxfExtrusionDepthForSpan(200)).toBe(4);
|
||||
});
|
||||
|
||||
it("grows proportionally for architectural-scale drawings", () => {
|
||||
expect(dxfExtrusionDepthForSpan(1000)).toBeCloseTo(10, 5);
|
||||
expect(dxfExtrusionDepthForSpan(3_426_521)).toBeCloseTo(34_265.21, 2);
|
||||
});
|
||||
|
||||
it("caps extremely large drawings so they stay editable", () => {
|
||||
expect(dxfExtrusionDepthForSpan(10_000_000)).toBe(50_000);
|
||||
expect(dxfExtrusionDepthForSpan(Number.POSITIVE_INFINITY)).toBe(4);
|
||||
});
|
||||
|
||||
it("extrudes a 40 m x 20 m plan into a solid hundreds of units thick", () => {
|
||||
const shape = importedShapeFromDxf("site_plan.dxf", rectangleDxf(40_000, 20_000));
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(40_000, 0);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(20_000, 0);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(400, 0);
|
||||
});
|
||||
});
|
||||
@@ -3,9 +3,12 @@ import { projectExportFileName } from "@/lib/exportNames";
|
||||
|
||||
describe("project export filenames", () => {
|
||||
it("uses the project name for each supported export format", () => {
|
||||
expect(projectExportFileName("Gearbox Prototype", "3mf")).toBe("Gearbox Prototype.3mf");
|
||||
expect(projectExportFileName("Gearbox Prototype", "stl")).toBe("Gearbox Prototype.stl");
|
||||
expect(projectExportFileName("Gearbox Prototype", "obj")).toBe("Gearbox Prototype.obj");
|
||||
expect(projectExportFileName("Gearbox Prototype", "step")).toBe("Gearbox Prototype.step");
|
||||
expect(projectExportFileName("Gearbox Prototype", "dxf")).toBe("Gearbox Prototype.dxf");
|
||||
expect(projectExportFileName("Gearbox Prototype", "glb")).toBe("Gearbox Prototype.glb");
|
||||
expect(projectExportFileName("Gearbox Prototype", "svg")).toBe("Gearbox Prototype.svg");
|
||||
expect(projectExportFileName("Gearbox Prototype", "skf")).toBe("Gearbox Prototype.skf");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
generateFollowMeShape,
|
||||
createProfileShape,
|
||||
createSweepCurvePath,
|
||||
FOLLOW_ME_PROFILE_PRESETS,
|
||||
} from "@/lib/followMeKernel";
|
||||
|
||||
describe("Follow Me / Sweep Kernel (Beni Takip Et / Süpürme)", () => {
|
||||
it("has complete preset profiles for architecture", () => {
|
||||
expect(FOLLOW_ME_PROFILE_PRESETS.length).toBeGreaterThanOrEqual(6);
|
||||
const ids = FOLLOW_ME_PROFILE_PRESETS.map((p) => p.id);
|
||||
expect(ids).toContain("molding");
|
||||
expect(ids).toContain("baseboard");
|
||||
expect(ids).toContain("handrail");
|
||||
expect(ids).toContain("pipe");
|
||||
expect(ids).toContain("beam");
|
||||
});
|
||||
|
||||
it("creates valid 2D shapes for all profile types", () => {
|
||||
for (const preset of FOLLOW_ME_PROFILE_PRESETS) {
|
||||
const shape = createProfileShape(preset.id, 20, 30, 3);
|
||||
expect(shape.curves.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("creates valid 3D sweep curve paths", () => {
|
||||
const straightPath = createSweepCurvePath("straight", { pathLength: 150 });
|
||||
expect(straightPath.curves.length).toBe(1);
|
||||
|
||||
const cornerPath = createSweepCurvePath("l-corner", { roomWidth: 100, roomDepth: 80 });
|
||||
expect(cornerPath.curves.length).toBe(2);
|
||||
|
||||
const perimeterPath = createSweepCurvePath("perimeter", { roomWidth: 200, roomDepth: 150 });
|
||||
expect(perimeterPath.curves.length).toBe(4);
|
||||
});
|
||||
|
||||
it("generates a complete 3D WorkplaneShape with valid mesh data", () => {
|
||||
const shape = generateFollowMeShape({
|
||||
profileType: "molding",
|
||||
pathPreset: "perimeter",
|
||||
width: 25,
|
||||
height: 30,
|
||||
roomWidth: 200,
|
||||
roomDepth: 150,
|
||||
texture: "wood",
|
||||
});
|
||||
|
||||
expect(shape.id).toBeDefined();
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.name).toContain("Kartonpiyer");
|
||||
expect(shape.texture).toBe("wood");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh!.positions.length).toBeGreaterThan(100);
|
||||
expect(shape.importedMesh!.normals?.length).toBeGreaterThan(100);
|
||||
expect(shape.width).toBeGreaterThan(150);
|
||||
expect(shape.depth).toBeGreaterThan(100);
|
||||
});
|
||||
|
||||
it("supports straight pipe / handrail generation", () => {
|
||||
const pipe = generateFollowMeShape({
|
||||
profileType: "pipe",
|
||||
pathPreset: "straight",
|
||||
width: 20,
|
||||
height: 20,
|
||||
pathLength: 300,
|
||||
texture: "metal",
|
||||
});
|
||||
|
||||
expect(pipe.importedMesh).toBeDefined();
|
||||
expect(pipe.width).toBeGreaterThan(250);
|
||||
expect(pipe.texture).toBe("metal");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { analyzeStructuralStability } from "@/lib/fxSystem";
|
||||
import { executeSimulationTick } from "@/components/snapcad/circuits/simulationEngine";
|
||||
import type { CircuitComponent } from "@/components/snapcad/circuits/types";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
describe("FX & Structural Stability System", () => {
|
||||
it("evaluates a well-proportioned architectural structure as structurally sound", () => {
|
||||
// A stable, wide base building (width 80, depth 60, height 40) at elevation 0
|
||||
const shapes: WorkplaneShape[] = [
|
||||
{
|
||||
id: "base1",
|
||||
name: "Temel ve Zemin Kat",
|
||||
kind: "box",
|
||||
color: "#cbd5e1",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 0,
|
||||
size: 80,
|
||||
width: 80,
|
||||
depth: 60,
|
||||
height: 40,
|
||||
rotation: 0,
|
||||
},
|
||||
{
|
||||
id: "roof1",
|
||||
name: "Çatı Katı",
|
||||
kind: "roof",
|
||||
color: "#b91c1c",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 40,
|
||||
size: 70,
|
||||
width: 70,
|
||||
depth: 50,
|
||||
height: 20,
|
||||
rotation: 0,
|
||||
},
|
||||
];
|
||||
|
||||
const result = analyzeStructuralStability(shapes);
|
||||
expect(result.passed).toBe(true);
|
||||
expect(result.score).toBeGreaterThanOrEqual(60);
|
||||
expect(result.slendernessRatio).toBeLessThanOrEqual(2.5);
|
||||
expect(result.strengths.length).toBeGreaterThan(0);
|
||||
expect(result.flaws.length).toBe(0);
|
||||
});
|
||||
|
||||
it("fails a dangerously slender tower under earthquake simulation", () => {
|
||||
// A needle-like tower: width 10, depth 10, height 120 (slenderness = 12)
|
||||
const shapes: WorkplaneShape[] = [
|
||||
{
|
||||
id: "tower1",
|
||||
name: "Narin Kule",
|
||||
kind: "box",
|
||||
color: "#475569",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 0,
|
||||
size: 10,
|
||||
width: 10,
|
||||
depth: 10,
|
||||
height: 120,
|
||||
rotation: 0,
|
||||
},
|
||||
];
|
||||
|
||||
const result = analyzeStructuralStability(shapes);
|
||||
expect(result.passed).toBe(false);
|
||||
expect(result.score).toBeLessThan(60);
|
||||
expect(result.slendernessRatio).toBeGreaterThan(4.2);
|
||||
expect(result.flaws.some((f) => f.includes("Narin"))).toBe(true);
|
||||
expect(result.recommendations.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("detects floating buildings with no ground foundation contact", () => {
|
||||
const shapes: WorkplaneShape[] = [
|
||||
{
|
||||
id: "floating1",
|
||||
name: "Havada Asılı Yapı",
|
||||
kind: "box",
|
||||
color: "#38bdf8",
|
||||
x: 0,
|
||||
z: 0,
|
||||
elevation: 35, // Floating 35mm in the air!
|
||||
size: 30,
|
||||
width: 30,
|
||||
depth: 30,
|
||||
height: 30,
|
||||
rotation: 0,
|
||||
},
|
||||
];
|
||||
|
||||
const result = analyzeStructuralStability(shapes);
|
||||
expect(result.passed).toBe(false);
|
||||
expect(result.flaws.some((f) => f.includes("Temel Bağlantısı Eksik"))).toBe(true);
|
||||
});
|
||||
|
||||
it("handles empty scenes safely", () => {
|
||||
const result = analyzeStructuralStability([]);
|
||||
expect(result.passed).toBe(false);
|
||||
expect(result.score).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Circuits Studio - Short Circuit & Explosion Detection", () => {
|
||||
it("detects over-current when LED is connected to 9V battery with no resistor", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "bat1", kind: "battery_9v", name: "9V Pil", x: 0, y: 0, batteryVoltage: 9 },
|
||||
{ id: "led1", kind: "led", name: "Kırmızı LED", x: 100, y: 0, ledColor: "red" },
|
||||
{ id: "sw1", kind: "slide_switch", name: "Anahtar", x: 50, y: 0, switchOn: true },
|
||||
];
|
||||
// No resistor in the circuit!
|
||||
const result = executeSimulationTick(1, "// Dirençsiz devre", components);
|
||||
|
||||
expect(result.shortCircuit).toBe(true);
|
||||
expect(result.shortCircuitReason).toMatch(/direnç/i);
|
||||
expect(result.explodedComponentId).toBe("led1");
|
||||
expect(result.logLines.some((l) => l.includes("KRİTİK ALARM"))).toBe(true);
|
||||
});
|
||||
|
||||
it("detects code-triggered short circuit tests", () => {
|
||||
const components: CircuitComponent[] = [
|
||||
{ id: "uno1", kind: "arduino_uno", name: "Uno", x: 0, y: 0 },
|
||||
];
|
||||
const code = "// KISA_DEVRE_TESTI: VCC ile GND temas ettirildi";
|
||||
const result = executeSimulationTick(1, code, components);
|
||||
|
||||
expect(result.shortCircuit).toBe(true);
|
||||
expect(result.shortCircuitReason).toContain("Kısa Devre");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { soundEngine } from "@/lib/audioFx";
|
||||
|
||||
describe("SnapCAD Dynamic Features — Gamification & Web Audio Synthesizer", () => {
|
||||
it("manages soundEngine enabled status and toggle correctly", () => {
|
||||
const initialStatus = soundEngine.isEnabled();
|
||||
expect(typeof initialStatus).toBe("boolean");
|
||||
|
||||
soundEngine.setEnabled(false);
|
||||
expect(soundEngine.isEnabled()).toBe(false);
|
||||
|
||||
soundEngine.setEnabled(true);
|
||||
expect(soundEngine.isEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it("calculates level and XP progression accurately", () => {
|
||||
const calculateGamificationLevel = (xp: number) => {
|
||||
const level = Math.floor(xp / 250) + 1;
|
||||
const currentLevelXp = xp % 250;
|
||||
const progressPercent = Math.min(100, Math.round((currentLevelXp / 250) * 100));
|
||||
return { level, currentLevelXp, progressPercent };
|
||||
};
|
||||
|
||||
expect(calculateGamificationLevel(0)).toEqual({ level: 1, currentLevelXp: 0, progressPercent: 0 });
|
||||
expect(calculateGamificationLevel(125)).toEqual({ level: 1, currentLevelXp: 125, progressPercent: 50 });
|
||||
expect(calculateGamificationLevel(250)).toEqual({ level: 2, currentLevelXp: 0, progressPercent: 0 });
|
||||
expect(calculateGamificationLevel(550)).toEqual({ level: 3, currentLevelXp: 50, progressPercent: 20 });
|
||||
});
|
||||
|
||||
it("validates visual style shader palette definitions", () => {
|
||||
type VisualStyle = "shaded" | "blueprint" | "cyberpunk" | "clay";
|
||||
|
||||
const getStyleBackground = (style: VisualStyle, defaultBg: string) => {
|
||||
switch (style) {
|
||||
case "blueprint":
|
||||
return "#0a2540";
|
||||
case "cyberpunk":
|
||||
return "#050914";
|
||||
case "clay":
|
||||
return "#e5e1d8";
|
||||
default:
|
||||
return defaultBg;
|
||||
}
|
||||
};
|
||||
|
||||
expect(getStyleBackground("blueprint", "#ffffff")).toBe("#0a2540");
|
||||
expect(getStyleBackground("cyberpunk", "#ffffff")).toBe("#050914");
|
||||
expect(getStyleBackground("clay", "#ffffff")).toBe("#e5e1d8");
|
||||
expect(getStyleBackground("shaded", "#f8fafc")).toBe("#f8fafc");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { exportMeshesToGlb } from "@/lib/glbExport";
|
||||
import { importedShapeFromGlb } from "@/lib/glbImport";
|
||||
import type { ObjExportMesh } from "@/lib/objExport";
|
||||
|
||||
function makeSimpleCubeMesh(): ObjExportMesh {
|
||||
return {
|
||||
name: "test_cube",
|
||||
vertices: [
|
||||
[-5, -5, -5],
|
||||
[5, -5, -5],
|
||||
[5, 5, -5],
|
||||
[-5, 5, -5],
|
||||
[-5, -5, 5],
|
||||
[5, -5, 5],
|
||||
[5, 5, 5],
|
||||
[-5, 5, 5],
|
||||
],
|
||||
faces: [
|
||||
[0, 2, 1], [0, 3, 2],
|
||||
[4, 5, 6], [4, 6, 7],
|
||||
[0, 1, 5], [0, 5, 4],
|
||||
[2, 3, 7], [2, 7, 6],
|
||||
[0, 4, 7], [0, 7, 3],
|
||||
[1, 2, 6], [1, 6, 5],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
describe("GLB export and import", () => {
|
||||
it("exports meshes to binary glTF (.glb) buffer with valid glTF header", async () => {
|
||||
const mesh = makeSimpleCubeMesh();
|
||||
const glbBuffer = await exportMeshesToGlb([mesh], { test_cube: "#ef4444" });
|
||||
|
||||
expect(glbBuffer).toBeInstanceOf(ArrayBuffer);
|
||||
expect(glbBuffer.byteLength).toBeGreaterThan(50);
|
||||
|
||||
// Verify GLB magic header 0x46546C67 ("glTF")
|
||||
const view = new DataView(glbBuffer);
|
||||
const magic = view.getUint32(0, true);
|
||||
expect(magic).toBe(0x46546c67);
|
||||
|
||||
// Version should be 2 (glTF 2.0)
|
||||
const version = view.getUint32(4, true);
|
||||
expect(version).toBe(2);
|
||||
});
|
||||
|
||||
it("imports binary GLB and reconstitutes a valid WorkplaneShape", async () => {
|
||||
const mesh = makeSimpleCubeMesh();
|
||||
const glbBuffer = await exportMeshesToGlb([mesh], { test_cube: "#3b82f6" });
|
||||
|
||||
const shape = await importedShapeFromGlb("cube.glb", glbBuffer);
|
||||
|
||||
expect(shape.kind).toBe("mesh");
|
||||
expect(shape.importedMesh).toBeDefined();
|
||||
expect(shape.importedMesh?.sourceFormat).toBe("glb");
|
||||
expect(shape.importedMesh?.triangleCount).toBe(12);
|
||||
|
||||
// Dimensions of 10x10x10 cube
|
||||
expect(shape.importedMesh?.baseWidth).toBeCloseTo(10, 1);
|
||||
expect(shape.importedMesh?.baseHeight).toBeCloseTo(10, 1);
|
||||
expect(shape.importedMesh?.baseDepth).toBeCloseTo(10, 1);
|
||||
|
||||
expect(shape.importedMesh?.positions.length).toBe(12 * 9);
|
||||
expect(shape.importedMesh?.normals?.length).toBe(12 * 9);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
IMAGE_PLATE_TRANSPARENT_WARNING,
|
||||
IMAGE_PLATE_WHITE_WARNING,
|
||||
summarizeImageVisibility,
|
||||
} from "@/lib/imagePlate";
|
||||
|
||||
function pixels(entries: Array<[number, number, number, number]>) {
|
||||
const data = new Uint8ClampedArray(entries.length * 4);
|
||||
entries.forEach(([r, g, b, a], index) => {
|
||||
data[index * 4] = r;
|
||||
data[index * 4 + 1] = g;
|
||||
data[index * 4 + 2] = b;
|
||||
data[index * 4 + 3] = a;
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
describe("image plate visibility", () => {
|
||||
it("warns when the image is fully transparent", () => {
|
||||
const result = summarizeImageVisibility(pixels([
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
]), 1);
|
||||
expect(result.warning).toBe(IMAGE_PLATE_TRANSPARENT_WARNING);
|
||||
expect(result.transparentRatio).toBe(1);
|
||||
expect(result.visibleRatio).toBe(0);
|
||||
});
|
||||
|
||||
it("warns when the image is fully opaque white", () => {
|
||||
const result = summarizeImageVisibility(pixels([
|
||||
[255, 255, 255, 255],
|
||||
[255, 255, 255, 255],
|
||||
[255, 255, 255, 255],
|
||||
[255, 255, 255, 255],
|
||||
]), 1);
|
||||
expect(result.warning).toBe(IMAGE_PLATE_WHITE_WARNING);
|
||||
expect(result.transparentRatio).toBe(0);
|
||||
expect(result.nearWhiteRatio).toBe(1);
|
||||
});
|
||||
|
||||
it("warns when only a thin dark line is visible on a transparent background", () => {
|
||||
const entries: Array<[number, number, number, number]> = [];
|
||||
for (let index = 0; index < 100; index += 1) {
|
||||
entries.push(index === 50 ? [17, 24, 39, 255] : [0, 0, 0, 0]);
|
||||
}
|
||||
const result = summarizeImageVisibility(pixels(entries), 1);
|
||||
expect(result.warning).toBe(IMAGE_PLATE_TRANSPARENT_WARNING);
|
||||
});
|
||||
|
||||
it("does not warn for a normal opaque image", () => {
|
||||
const result = summarizeImageVisibility(pixels([
|
||||
[220, 38, 38, 255],
|
||||
[37, 99, 235, 255],
|
||||
[22, 163, 74, 255],
|
||||
[202, 138, 4, 255],
|
||||
]), 1);
|
||||
expect(result.warning).toBeNull();
|
||||
});
|
||||
|
||||
it("does not warn for a drawing on white paper with visible ink", () => {
|
||||
const entries: Array<[number, number, number, number]> = [];
|
||||
for (let index = 0; index < 100; index += 1) {
|
||||
entries.push(index % 20 === 0 ? [15, 23, 42, 255] : [255, 255, 255, 255]);
|
||||
}
|
||||
const result = summarizeImageVisibility(pixels(entries), 1);
|
||||
expect(result.warning).toBeNull();
|
||||
});
|
||||
|
||||
it("handles empty pixel buffers without throwing", () => {
|
||||
const result = summarizeImageVisibility(new Uint8ClampedArray(0), 1);
|
||||
expect(result.warning).toBe(IMAGE_PLATE_TRANSPARENT_WARNING);
|
||||
});
|
||||
});
|
||||
@@ -2,12 +2,18 @@ import { describe, expect, it } from "vitest";
|
||||
import { importExtensionSupported } from "@/lib/importExtensions";
|
||||
|
||||
describe("importExtensionSupported", () => {
|
||||
it("accepts STL, OBJ, and SVG imports", () => {
|
||||
it("accepts STL, OBJ, SVG, DXF, and GLB imports", () => {
|
||||
expect(importExtensionSupported("part.stl")).toBe(true);
|
||||
expect(importExtensionSupported("assembly.obj")).toBe(true);
|
||||
expect(importExtensionSupported("MODEL.OBJ")).toBe(true);
|
||||
expect(importExtensionSupported("logo.svg")).toBe(true);
|
||||
expect(importExtensionSupported("profile.SVG")).toBe(true);
|
||||
expect(importExtensionSupported("drawing.dxf")).toBe(true);
|
||||
expect(importExtensionSupported("CAD.DXF")).toBe(true);
|
||||
expect(importExtensionSupported("scene.glb")).toBe(true);
|
||||
expect(importExtensionSupported("mesh.gltf")).toBe(true);
|
||||
expect(importExtensionSupported("floorplan.dwg")).toBe(true);
|
||||
expect(importExtensionSupported("AUTOCAD.DWG")).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects unsupported dashboard import extensions", () => {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TUTORIAL_STEPS } from "@/lib/academyTutorialData";
|
||||
|
||||
describe("Interactive Tutorial (SnapCAD Akademi) Unit Tests", () => {
|
||||
it("has exactly 10 comprehensive hands-on tutorial steps", () => {
|
||||
expect(TUTORIAL_STEPS.length).toBe(10);
|
||||
});
|
||||
|
||||
it("covers all essential architectural and modeling skills", () => {
|
||||
const titles = TUTORIAL_STEPS.map((s) => s.title);
|
||||
expect(titles.some((t) => t.includes("Gezinti") || t.includes("Kamera"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Duvar") || t.includes("Kütle"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("İt / Çek") || t.includes("Push/Pull"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Akıllı Çarpışmasız") || t.includes("Çatı"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Boya Kovası") || t.includes("Dokular"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Bileşenler") || t.includes("Components"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Röntgen") || t.includes("X-Ray"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Yürüme") || t.includes("WASD"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Fizik") || t.includes("Deprem"))).toBe(true);
|
||||
expect(titles.some((t) => t.includes("Masamda Gör") || t.includes("AR"))).toBe(true);
|
||||
});
|
||||
|
||||
it("has action buttons on interactive steps", () => {
|
||||
const stepsWithActions = TUTORIAL_STEPS.filter((s) => Boolean(s.actionButton));
|
||||
expect(stepsWithActions.length).toBeGreaterThanOrEqual(8);
|
||||
|
||||
const actionTypes = stepsWithActions.map((s) => s.actionButton?.actionType);
|
||||
expect(actionTypes).toContain("add_sample_wall");
|
||||
expect(actionTypes).toContain("trigger_push_pull");
|
||||
expect(actionTypes).toContain("add_sample_roof");
|
||||
expect(actionTypes).toContain("open_paint_bucket");
|
||||
expect(actionTypes).toContain("create_component_sample");
|
||||
expect(actionTypes).toContain("toggle_xray");
|
||||
expect(actionTypes).toContain("start_walk_mode");
|
||||
expect(actionTypes).toContain("trigger_structural_test");
|
||||
expect(actionTypes).toContain("open_ar_preview");
|
||||
});
|
||||
|
||||
it("ensures step numbers and identifiers are sequential and unique", () => {
|
||||
const ids = new Set<string>();
|
||||
TUTORIAL_STEPS.forEach((step, index) => {
|
||||
expect(step.stepNumber).toBe(index + 1);
|
||||
expect(ids.has(step.id)).toBe(false);
|
||||
ids.add(step.id);
|
||||
expect(step.body.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { exportMeshesToObj, type ObjExportMesh } from "@/lib/objExport";
|
||||
import { exportMeshesToObj, generateMtlContent, type ObjExportMesh } from "@/lib/objExport";
|
||||
|
||||
function duplicatedTetrahedron(): ObjExportMesh {
|
||||
const a: [number, number, number] = [0, 0, 0];
|
||||
@@ -40,4 +40,16 @@ describe("OBJ export", () => {
|
||||
expect(faces).toHaveLength(4);
|
||||
expect([...edgeUse.values()].every((count) => count === 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("generates companion .mtl material library and references it in .obj", () => {
|
||||
const mesh = duplicatedTetrahedron();
|
||||
const colors = { closed_tetrahedron: "#ff5500" };
|
||||
const mtl = generateMtlContent([mesh], colors);
|
||||
const obj = exportMeshesToObj([mesh], { mtlFileName: "model.mtl", colors });
|
||||
|
||||
expect(mtl).toContain("newmtl Material_closed_tetrahedron");
|
||||
expect(mtl).toContain("Kd 1 0.3333 0");
|
||||
expect(obj).toContain("mtllib model.mtl");
|
||||
expect(obj).toContain("usemtl Material_closed_tetrahedron");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { offsetPolygon, polygonSignedArea, offsetSketchProfile, type Point2D } from "@/lib/offsetKernel";
|
||||
|
||||
describe("Offset Tool Kernel (Ofset Aracı & Duvar Kalınlığı)", () => {
|
||||
it("calculates signed area of a rectangle correctly", () => {
|
||||
// 100 x 50 rectangle (CCW)
|
||||
const rect: Point2D[] = [
|
||||
{ x: 0, z: 0 },
|
||||
{ x: 100, z: 0 },
|
||||
{ x: 100, z: 50 },
|
||||
{ x: 0, z: 50 },
|
||||
];
|
||||
const area = polygonSignedArea(rect);
|
||||
expect(area).toBe(5000);
|
||||
});
|
||||
|
||||
it("offsets a rectangle outward by 10mm", () => {
|
||||
const rect: Point2D[] = [
|
||||
{ x: 0, z: 0 },
|
||||
{ x: 100, z: 0 },
|
||||
{ x: 100, z: 50 },
|
||||
{ x: 0, z: 50 },
|
||||
];
|
||||
const outset = offsetPolygon(rect, 10);
|
||||
expect(outset.length).toBe(4);
|
||||
// Outward expands by 10 on all sides: width becomes 120, height becomes 70
|
||||
const minX = Math.min(...outset.map((p) => p.x));
|
||||
const maxX = Math.max(...outset.map((p) => p.x));
|
||||
const minZ = Math.min(...outset.map((p) => p.z));
|
||||
const maxZ = Math.max(...outset.map((p) => p.z));
|
||||
|
||||
expect(Math.round(maxX - minX)).toBe(120);
|
||||
expect(Math.round(maxZ - minZ)).toBe(70);
|
||||
});
|
||||
|
||||
it("offsets a room perimeter inward by 15mm to generate interior wall", () => {
|
||||
const room: Point2D[] = [
|
||||
{ x: 0, z: 0 },
|
||||
{ x: 200, z: 0 },
|
||||
{ x: 200, z: 150 },
|
||||
{ x: 0, z: 150 },
|
||||
];
|
||||
// Inset by -15mm
|
||||
const inset = offsetPolygon(room, -15);
|
||||
expect(inset.length).toBe(4);
|
||||
const minX = Math.min(...inset.map((p) => p.x));
|
||||
const maxX = Math.max(...inset.map((p) => p.x));
|
||||
const minZ = Math.min(...inset.map((p) => p.z));
|
||||
const maxZ = Math.max(...inset.map((p) => p.z));
|
||||
|
||||
expect(Math.round(maxX - minX)).toBe(170); // 200 - 30 = 170
|
||||
expect(Math.round(maxZ - minZ)).toBe(120); // 150 - 30 = 120
|
||||
});
|
||||
|
||||
it("offsets a SketchProfile into a dual-walled footprint", () => {
|
||||
const initialProfile = {
|
||||
points: [
|
||||
{ id: "p1", x: 0, z: 0 },
|
||||
{ id: "p2", x: 100, z: 0 },
|
||||
{ id: "p3", x: 100, z: 80 },
|
||||
{ id: "p4", x: 0, z: 80 },
|
||||
],
|
||||
segments: [
|
||||
{ id: "s1", startId: "p1", endId: "p2" },
|
||||
{ id: "s2", startId: "p2", endId: "p3" },
|
||||
{ id: "s3", startId: "p3", endId: "p4" },
|
||||
{ id: "s4", startId: "p4", endId: "p1" },
|
||||
],
|
||||
};
|
||||
const walledProfile = offsetSketchProfile(initialProfile, -10);
|
||||
expect(walledProfile.points.length).toBe(8); // 4 outer + 4 inner wall points
|
||||
expect(walledProfile.segments.length).toBe(8); // 4 outer + 4 inner segments
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
||||
import { importedShapeFromDxf } from "@/lib/dxfImport";
|
||||
import { editorHistoryEntry } from "@/lib/editorHistory";
|
||||
import { placementWorkplaneFromSurface } from "@/lib/placementWorkplane";
|
||||
import { projectAssetFromBytes } from "@/lib/projectAssets";
|
||||
import { attachProjectAsset, projectAssetFromBytes } from "@/lib/projectAssets";
|
||||
import * as projectAssets from "@/lib/projectAssets";
|
||||
import { canonicalizeShape } from "@/lib/workplaneShapes";
|
||||
import {
|
||||
@@ -18,6 +19,21 @@ import {
|
||||
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE } from "@/lib/workplaneSettings";
|
||||
import type { ShapeKind, WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
// DWG tarayıcı çekirdeği testte gerçek WASM çalıştırmaz; kaynak varlık yolunun
|
||||
// doğru içe aktarıcıya yönlendirildiğini doğrulamak için sabit bir mesh döner.
|
||||
vi.mock("@/lib/dwgKernel", () => ({
|
||||
importedShapeFromDwg: vi.fn(async () => ({
|
||||
importedMesh: {
|
||||
positions: [0, 0, 0, 1, 0, 0, 0, 1, 0],
|
||||
baseWidth: 4321,
|
||||
baseDepth: 21,
|
||||
baseHeight: 3,
|
||||
triangleCount: 1,
|
||||
sourceFormat: "dwg",
|
||||
},
|
||||
})),
|
||||
}));
|
||||
|
||||
function shape(kind: ShapeKind, id = `${kind}-1`, overrides: Partial<WorkplaneShape> = {}): WorkplaneShape {
|
||||
return {
|
||||
id,
|
||||
@@ -635,3 +651,111 @@ describe("SketchForge .skf project packages", () => {
|
||||
await expect(importSkfProject(zipSync(files))).rejects.toThrow("integrity check");
|
||||
});
|
||||
});
|
||||
|
||||
function rectangleDxf(width: number, height: number) {
|
||||
return `0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
0
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
0.0
|
||||
20
|
||||
0.0
|
||||
10
|
||||
${width}
|
||||
20
|
||||
0.0
|
||||
10
|
||||
${width}
|
||||
20
|
||||
${height}
|
||||
10
|
||||
0.0
|
||||
20
|
||||
${height}
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF`;
|
||||
}
|
||||
|
||||
describe("Imported CAD source assets survive .skf round trips", () => {
|
||||
it("reconstructs a DXF source asset when a project is reopened", async () => {
|
||||
const dxf = rectangleDxf(40, 20);
|
||||
const original = importedShapeFromDxf("plan.dxf", dxf);
|
||||
const asset = await projectAssetFromBytes("plan.dxf", "dxf", strToU8(dxf));
|
||||
const packaged = await exportSkfProject(input([attachProjectAsset(original, asset.id)], { assets: [asset] }));
|
||||
|
||||
// DXF kaynak dosyası yeniden üretilebildiği için paket yalnızca kaynağı taşır.
|
||||
const { document } = packageDocument(packaged);
|
||||
expect(document.assets.filter((entry) => entry.kind === "source").map((entry) => entry.sourceFormat)).toEqual(["dxf"]);
|
||||
expect(document.assets.some((entry) => entry.kind === "derived-mesh")).toBe(false);
|
||||
|
||||
const restored = await importSkfProject(packaged);
|
||||
expect(restored.shapes).toHaveLength(1);
|
||||
expect(restored.shapes[0].kind).toBe("mesh");
|
||||
expect(restored.shapes[0].importedMesh?.sourceFormat).toBe("dxf");
|
||||
expect(restored.shapes[0].importedMesh?.triangleCount).toBe(original.importedMesh?.triangleCount);
|
||||
expect(restored.shapes[0].width).toBeCloseTo(40, 0);
|
||||
expect(restored.shapes[0].depth).toBeCloseTo(20, 0);
|
||||
});
|
||||
|
||||
it("accepts a DWG source asset and reuses the stored derived mesh", async () => {
|
||||
// Gerçek bir DWG içe aktarımı, kaynak varlığını "dwg" biçiminde saklar ama
|
||||
// şeklin mesh'i DXF'ten üretildiği için sourceFormat "dxf" olarak kalır.
|
||||
// Bu birleşim daha önce "unknown source format" hatasıyla projeyi boş açıyordu.
|
||||
const importedMesh = {
|
||||
positions: [0, 0, 0, 10, 0, 0, 0, 10, 0],
|
||||
baseWidth: 270,
|
||||
baseDepth: 280,
|
||||
baseHeight: 4,
|
||||
triangleCount: 1,
|
||||
sourceFormat: "dxf" as const,
|
||||
};
|
||||
const dwgShape = shape("mesh", "dwg-mesh", { importedMesh });
|
||||
const dwgBytes = strToU8("AC1032");
|
||||
const asset = await projectAssetFromBytes("plan.dwg", "dwg", dwgBytes);
|
||||
const packaged = await exportSkfProject(input([attachProjectAsset(dwgShape, asset.id)], { assets: [asset] }));
|
||||
|
||||
const { document } = packageDocument(packaged);
|
||||
expect(document.assets.map((entry) => [entry.kind, entry.sourceFormat])).toContainEqual(["source", "dwg"]);
|
||||
expect(document.assets.some((entry) => entry.kind === "derived-mesh")).toBe(true);
|
||||
|
||||
// Kaynak DWG dönüştürülmeden, paketteki hazır mesh ile açılmalı.
|
||||
const restored = await importSkfProject(packaged);
|
||||
expect(restored.shapes).toHaveLength(1);
|
||||
expect(restored.shapes[0].importedMesh?.triangleCount).toBe(1);
|
||||
expect(restored.shapes[0].importedMesh?.baseWidth).toBe(270);
|
||||
});
|
||||
|
||||
it("routes a DWG source asset to the DWG importer when no derived mesh is stored", async () => {
|
||||
const dwgShape = shape("mesh", "dwg-source-only", {
|
||||
importedMesh: {
|
||||
positions: [0, 0, 0, 1, 0, 0, 0, 1, 0],
|
||||
baseWidth: 1,
|
||||
baseDepth: 1,
|
||||
baseHeight: 1,
|
||||
triangleCount: 1,
|
||||
sourceFormat: "dwg",
|
||||
},
|
||||
});
|
||||
const asset = await projectAssetFromBytes("source-only.dwg", "dwg", strToU8("AC1032"));
|
||||
const packaged = await exportSkfProject(input([attachProjectAsset(dwgShape, asset.id)], { assets: [asset] }));
|
||||
|
||||
const { document } = packageDocument(packaged);
|
||||
expect(document.assets.some((entry) => entry.kind === "derived-mesh")).toBe(false);
|
||||
|
||||
const restored = await importSkfProject(packaged);
|
||||
expect(restored.shapes).toHaveLength(1);
|
||||
expect(restored.shapes[0].importedMesh?.baseWidth).toBe(4321);
|
||||
expect(restored.shapes[0].importedMesh?.sourceFormat).toBe("dwg");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
calculateSmartPlacementPoint,
|
||||
calculateTopSurfaceElevation,
|
||||
} from "@/lib/smartPlacement";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
describe("Smart Placement & Anti-Collision (Akıllı Yerleşim ve Çakışma Önleme)", () => {
|
||||
it("places at origin when scene is empty", () => {
|
||||
const point = calculateSmartPlacementPoint([], { width: 20, depth: 20 });
|
||||
expect(point.x).toBe(0);
|
||||
expect(point.z).toBe(0);
|
||||
});
|
||||
|
||||
it("places cleanly beside an existing house centered at (0, 0)", () => {
|
||||
// Miniature house centered at (0, 0), width 80, depth 60
|
||||
const house: WorkplaneShape = {
|
||||
id: "house-1",
|
||||
name: "Minyatür Ev",
|
||||
kind: "box",
|
||||
color: "#f59e0b",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 80,
|
||||
depth: 60,
|
||||
height: 50,
|
||||
elevation: 0,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
// New 20x20 cube added
|
||||
const point = calculateSmartPlacementPoint([house], { width: 20, depth: 20 });
|
||||
|
||||
// House extends from X = -40 to +40.
|
||||
// New cube should be placed to the right: 40 + 10 (half width) + 12 (margin) = 62
|
||||
expect(point.x).toBe(62);
|
||||
expect(point.z).toBe(0);
|
||||
});
|
||||
|
||||
it("calculates top surface elevation to pop an interior cube onto the roof", () => {
|
||||
const houseBody: WorkplaneShape = {
|
||||
id: "house-body",
|
||||
name: "Ev Gövdesi",
|
||||
kind: "box",
|
||||
color: "#f59e0b",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 60,
|
||||
depth: 60,
|
||||
height: 40,
|
||||
elevation: 0,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
const roof: WorkplaneShape = {
|
||||
id: "house-roof",
|
||||
name: "Çatı",
|
||||
kind: "roof",
|
||||
color: "#dc2626",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 64,
|
||||
depth: 64,
|
||||
height: 25,
|
||||
elevation: 40, // sits on top of body (40 + 25 = 65)
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
// Cube swallowed inside at (0, 0, 0)
|
||||
const swallowedCube: WorkplaneShape = {
|
||||
id: "cube-inside",
|
||||
name: "Kutu",
|
||||
kind: "box",
|
||||
color: "#3b82f6",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 20,
|
||||
depth: 20,
|
||||
height: 20,
|
||||
elevation: 0,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
const topElevation = calculateTopSurfaceElevation(swallowedCube, [houseBody, roof, swallowedCube]);
|
||||
|
||||
// Top of the roof is 40 + 25 = 65mm
|
||||
expect(topElevation).toBe(65);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { SNAPCAD_PREFABS } from "@/lib/snapcadPrefabs";
|
||||
|
||||
describe("SnapCAD Prefabs Catalog", () => {
|
||||
it("contains high-demand mechanical, maker, everyday, and architectural prefabs", () => {
|
||||
expect(SNAPCAD_PREFABS.length).toBeGreaterThanOrEqual(14);
|
||||
|
||||
const ids = SNAPCAD_PREFABS.map((p) => p.id);
|
||||
expect(ids).toContain("hex-nut-m8");
|
||||
expect(ids).toContain("bearing-608zz");
|
||||
expect(ids).toContain("hex-bolt-m8x35");
|
||||
expect(ids).toContain("electronics-box");
|
||||
expect(ids).toContain("arduino-uno-mount");
|
||||
expect(ids).toContain("nema17-stepper-mount");
|
||||
expect(ids).toContain("modular-arch-wall");
|
||||
expect(ids).toContain("spiral-stairs");
|
||||
expect(ids).toContain("truss-beam");
|
||||
expect(ids).toContain("domino-run-track");
|
||||
expect(ids).toContain("modern-terrace-villa");
|
||||
expect(ids).toContain("retro-arcade-console");
|
||||
expect(ids).toContain("cable-stayed-bridge");
|
||||
expect(ids).toContain("iot-smart-hub-case");
|
||||
});
|
||||
|
||||
it("builds valid non-empty shape lists for every prefab", () => {
|
||||
for (const prefab of SNAPCAD_PREFABS) {
|
||||
expect(prefab.id).toBeTruthy();
|
||||
expect(prefab.title).toBeTruthy();
|
||||
expect(prefab.category).toMatch(/^(mechanical|maker|everyday|architecture)$/);
|
||||
expect(prefab.categoryLabel).toBeTruthy();
|
||||
expect(prefab.description).toBeTruthy();
|
||||
|
||||
const shapes = prefab.buildShapes();
|
||||
expect(shapes.length).toBeGreaterThan(0);
|
||||
|
||||
for (const shape of shapes) {
|
||||
expect(shape.id).toBeTruthy();
|
||||
expect(shape.name).toBeTruthy();
|
||||
expect(shape.kind).toBeTruthy();
|
||||
expect(typeof shape.width).toBe("number");
|
||||
expect(typeof shape.height).toBe("number");
|
||||
expect(typeof shape.depth).toBe("number");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
calculateSunPosition,
|
||||
DEFAULT_SOLAR_SETTINGS,
|
||||
SOLAR_LOCATIONS,
|
||||
type SolarStudySettings,
|
||||
} from "@/lib/solarSystem";
|
||||
|
||||
describe("Solar Study & Sun Position System (Mimari Güneş & Gölge Etüdü)", () => {
|
||||
it("provides architectural location presets including Istanbul and Ankara", () => {
|
||||
expect(SOLAR_LOCATIONS.length).toBeGreaterThanOrEqual(5);
|
||||
const names = SOLAR_LOCATIONS.map((l) => l.name);
|
||||
expect(names.some((n) => n.includes("İstanbul"))).toBe(true);
|
||||
expect(names.some((n) => n.includes("Ankara"))).toBe(true);
|
||||
});
|
||||
|
||||
it("calculates peak sun altitude at noon in June", () => {
|
||||
const noonSummer: SolarStudySettings = {
|
||||
...DEFAULT_SOLAR_SETTINGS,
|
||||
hour: 12.0,
|
||||
month: 5, // June
|
||||
day: 21,
|
||||
};
|
||||
const pos = calculateSunPosition(noonSummer);
|
||||
expect(pos.isDaylight).toBe(true);
|
||||
expect(pos.altitudeDegrees).toBeGreaterThan(60); // In Istanbul, summer solstice noon is ~72 deg
|
||||
expect(pos.lightVector[1]).toBeGreaterThan(150); // High Y position
|
||||
});
|
||||
|
||||
it("calculates lower sun altitude and longer shadows in winter solstice (December)", () => {
|
||||
const noonWinter: SolarStudySettings = {
|
||||
...DEFAULT_SOLAR_SETTINGS,
|
||||
hour: 12.0,
|
||||
month: 11, // December
|
||||
day: 21,
|
||||
};
|
||||
const pos = calculateSunPosition(noonWinter);
|
||||
expect(pos.altitudeDegrees).toBeLessThan(35); // Winter noon in Istanbul is ~25-26 deg
|
||||
});
|
||||
|
||||
it("produces warm golden hour lighting colors near sunrise/sunset", () => {
|
||||
const sunsetSettings: SolarStudySettings = {
|
||||
...DEFAULT_SOLAR_SETTINGS,
|
||||
hour: 20.2, // Around sunset in summer in Istanbul
|
||||
month: 5,
|
||||
day: 21,
|
||||
};
|
||||
const pos = calculateSunPosition(sunsetSettings);
|
||||
expect(pos.lightColorHex).toMatch(/^#(ffaa44|ffe4b5|fffcf2)$/);
|
||||
});
|
||||
});
|
||||
@@ -69,7 +69,7 @@ describe("SVG source preflight", () => {
|
||||
expect(() => validateSvgSourcePreflight('<svg><use href="https://example.com/art.svg#part"/></svg>')).toThrow(/external references/i);
|
||||
});
|
||||
|
||||
it("reports malformed Tinkercad cross-section geometry", () => {
|
||||
it("reports malformed cross-section geometry with NaN coordinates", () => {
|
||||
expect(() => validateSvgSourcePreflight('<svg width="NaNmm" viewBox="NaN NaN NaN NaN"><path d="z"/></svg>')).toThrow(/workplane intersects the model/i);
|
||||
});
|
||||
|
||||
@@ -109,14 +109,14 @@ describe("SVG path extrusion", () => {
|
||||
expect(() => buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10, { fill: "#00000000" })])).toThrow(/no readable visible/i);
|
||||
});
|
||||
|
||||
it("imports a closed Tinkercad-style stroke as an extrusion profile", () => {
|
||||
const tinkercadOutline = shapePath([[0, 0], [10, 0], [10, 6], [0, 6], [0, 0]], {
|
||||
it("imports a closed stroke as an extrusion profile", () => {
|
||||
const strokeOutline = shapePath([[0, 0], [10, 0], [10, 6], [0, 6], [0, 0]], {
|
||||
closed: false,
|
||||
fill: "none",
|
||||
stroke: "rgb(255,0,0)",
|
||||
strokeWidth: 0.001,
|
||||
});
|
||||
const result = buildSvgExtrusionFromPaths([tinkercadOutline]);
|
||||
const result = buildSvgExtrusionFromPaths([strokeOutline]);
|
||||
expect(result.analysis.width).toBeCloseTo(10);
|
||||
expect(result.analysis.depth).toBeCloseTo(6);
|
||||
expect(result.analysis.volume).toBeCloseTo(240);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { strFromU8, unzipSync } from "fflate";
|
||||
import { exportMeshesTo3mf, type ThreemfExportMesh } from "@/lib/threemfExport";
|
||||
|
||||
function makePrismMesh(name: string, color?: string): ThreemfExportMesh {
|
||||
const v = [
|
||||
[0, 0, 0],
|
||||
[10, 0, 0],
|
||||
[10, 20, 0],
|
||||
[0, 20, 0],
|
||||
[0, 0, 30],
|
||||
[10, 0, 30],
|
||||
[10, 20, 30],
|
||||
[0, 20, 30],
|
||||
] as [number, number, number][];
|
||||
|
||||
const faces: [number, number, number][] = [
|
||||
[0, 2, 1],
|
||||
[0, 3, 2],
|
||||
[4, 5, 6],
|
||||
[4, 6, 7],
|
||||
[0, 1, 5],
|
||||
[0, 5, 4],
|
||||
[1, 2, 6],
|
||||
[1, 6, 5],
|
||||
[2, 3, 7],
|
||||
[2, 7, 6],
|
||||
[3, 0, 4],
|
||||
[3, 4, 7],
|
||||
];
|
||||
|
||||
return {
|
||||
name,
|
||||
vertices: v,
|
||||
faces,
|
||||
color,
|
||||
};
|
||||
}
|
||||
|
||||
describe("3MF Modern 3D Manufacturing Export", () => {
|
||||
it("creates a valid .3mf ZIP package with standard OPC structure", () => {
|
||||
const mesh = makePrismMesh("cube_test", "#38bdf8");
|
||||
const zipBytes = exportMeshesTo3mf([mesh], {
|
||||
title: "Test Cube",
|
||||
unit: "millimeter",
|
||||
});
|
||||
|
||||
expect(zipBytes.byteLength).toBeGreaterThan(100);
|
||||
|
||||
const unzipped = unzipSync(zipBytes);
|
||||
expect(unzipped["[Content_Types].xml"]).toBeDefined();
|
||||
expect(unzipped["_rels/.rels"]).toBeDefined();
|
||||
expect(unzipped["3D/3dmodel.model"]).toBeDefined();
|
||||
|
||||
const modelContent = strFromU8(unzipped["3D/3dmodel.model"]);
|
||||
expect(modelContent).toContain('unit="millimeter"');
|
||||
expect(modelContent).toContain("<model");
|
||||
expect(modelContent).toContain("SnapCAD Studio");
|
||||
expect(modelContent).toContain('name="cube_test"');
|
||||
expect(modelContent).toContain("<vertices>");
|
||||
expect(modelContent).toContain("<triangles>");
|
||||
expect(modelContent).toContain("<item objectid=");
|
||||
});
|
||||
|
||||
it("exports multi-material and colors using 3MF material extension", () => {
|
||||
const meshA = makePrismMesh("cyan_box", "#00ffff");
|
||||
const meshB = makePrismMesh("magenta_box", "#ff00ff");
|
||||
const zipBytes = exportMeshesTo3mf([meshA, meshB]);
|
||||
|
||||
const unzipped = unzipSync(zipBytes);
|
||||
const modelContent = strFromU8(unzipped["3D/3dmodel.model"]);
|
||||
|
||||
expect(modelContent).toContain("<m:colorgroup");
|
||||
expect(modelContent).toContain('color="#00FFFFFF"');
|
||||
expect(modelContent).toContain('color="#FF00FFFF"');
|
||||
expect(modelContent).toContain('pid="1"');
|
||||
});
|
||||
|
||||
it("converts SketchForge Y-up scene into standard Z-up slicer coordinates", () => {
|
||||
const mesh = makePrismMesh("z_up_test");
|
||||
const zipBytes = exportMeshesTo3mf([mesh]);
|
||||
|
||||
const unzipped = unzipSync(zipBytes);
|
||||
const modelContent = strFromU8(unzipped["3D/3dmodel.model"]);
|
||||
|
||||
// Original vertex [0, 20, 30] in Y-up should convert to [x, -z, y] = [0, -30, 20]
|
||||
expect(modelContent).toContain('<vertex x="0.00000" y="-30.00000" z="20.00000"/>');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
describe("Wall Opening & Window Cutout Unit Tests", () => {
|
||||
it("calculates correct through-cutting hole dimensions and position for a wall", () => {
|
||||
const wall: WorkplaneShape = {
|
||||
id: "wall-sample",
|
||||
name: "Taşıyıcı Duvar",
|
||||
kind: "box",
|
||||
color: "#94a3b8",
|
||||
x: 0,
|
||||
z: 0,
|
||||
width: 120,
|
||||
depth: 20,
|
||||
height: 60,
|
||||
size: 60,
|
||||
elevation: 0,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
const windowConfig = {
|
||||
width: 30,
|
||||
height: 30,
|
||||
elevation: 20, // sill height
|
||||
offsetX: 0,
|
||||
};
|
||||
|
||||
// Calculate hole box penetrating through the wall
|
||||
const holeDepth = (wall.depth ?? 20) + 6; // 26mm, ensures 3mm overhang on each side
|
||||
const holeShape: WorkplaneShape = {
|
||||
id: "hole-1",
|
||||
name: "Pencere Kesici",
|
||||
kind: "box",
|
||||
color: "#6b7280",
|
||||
x: (wall.x ?? 0) + windowConfig.offsetX,
|
||||
z: wall.z ?? 0,
|
||||
width: windowConfig.width,
|
||||
depth: holeDepth,
|
||||
height: windowConfig.height,
|
||||
size: windowConfig.height,
|
||||
elevation: (wall.elevation ?? 0) + windowConfig.elevation,
|
||||
rotation: wall.rotation ?? 0,
|
||||
hole: true,
|
||||
};
|
||||
|
||||
expect(holeShape.hole).toBe(true);
|
||||
expect(holeShape.depth).toBeGreaterThan(wall.depth ?? 0);
|
||||
expect(holeShape.elevation).toBe(20);
|
||||
expect(holeShape.width).toBe(30);
|
||||
expect(holeShape.height).toBe(30);
|
||||
});
|
||||
|
||||
it("handles door cutout at zero elevation (ground level)", () => {
|
||||
const wall: WorkplaneShape = {
|
||||
id: "wall-sample-door",
|
||||
name: "Giriş Duvarı",
|
||||
kind: "box",
|
||||
color: "#94a3b8",
|
||||
x: 50,
|
||||
z: -20,
|
||||
width: 100,
|
||||
depth: 20,
|
||||
height: 60,
|
||||
size: 60,
|
||||
elevation: 0,
|
||||
rotation: 0,
|
||||
};
|
||||
|
||||
const doorConfig = {
|
||||
width: 25,
|
||||
height: 50,
|
||||
elevation: 0, // door sill at ground
|
||||
offsetX: -20,
|
||||
};
|
||||
|
||||
const holeShape: WorkplaneShape = {
|
||||
id: "door-hole",
|
||||
name: "Kapı Kesici",
|
||||
kind: "box",
|
||||
color: "#6b7280",
|
||||
x: (wall.x ?? 0) + doorConfig.offsetX,
|
||||
z: wall.z ?? 0,
|
||||
width: doorConfig.width,
|
||||
depth: (wall.depth ?? 20) + 6,
|
||||
height: doorConfig.height,
|
||||
size: doorConfig.height,
|
||||
elevation: (wall.elevation ?? 0) + doorConfig.elevation,
|
||||
rotation: wall.rotation ?? 0,
|
||||
hole: true,
|
||||
};
|
||||
|
||||
expect(holeShape.elevation).toBe(0);
|
||||
expect(holeShape.x).toBe(30); // 50 - 20
|
||||
expect(holeShape.height).toBe(50);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
describe("YakNet SSO Cross-Subdomain Real-Time Session Synchronization", () => {
|
||||
it("validates incoming YAKNET_SSO_STATUS message payload structure", () => {
|
||||
const parseSsoMessage = (data: unknown) => {
|
||||
if (!data || typeof data !== "object") return null;
|
||||
const d = data as Record<string, unknown>;
|
||||
if (d.type !== "YAKNET_SSO_STATUS") return null;
|
||||
return {
|
||||
authenticated: Boolean(d.authenticated),
|
||||
user: d.user && typeof d.user === "object" ? (d.user as Record<string, unknown>) : null,
|
||||
};
|
||||
};
|
||||
|
||||
const validPayload = {
|
||||
type: "YAKNET_SSO_STATUS",
|
||||
authenticated: true,
|
||||
user: {
|
||||
id: 42,
|
||||
name: "Yakup İpek",
|
||||
email: "[email protected]",
|
||||
avatar: "https://auth.yakhub.com.tr/avatars/42.png",
|
||||
},
|
||||
};
|
||||
|
||||
const parsed = parseSsoMessage(validPayload);
|
||||
expect(parsed).not.toBeNull();
|
||||
expect(parsed?.authenticated).toBe(true);
|
||||
expect(parsed?.user?.name).toBe("Yakup İpek");
|
||||
expect(parsed?.user?.email).toBe("[email protected]");
|
||||
|
||||
// Invalid or unrelated message
|
||||
expect(parseSsoMessage({ type: "OTHER_EVENT" })).toBeNull();
|
||||
expect(parseSsoMessage(null)).toBeNull();
|
||||
});
|
||||
|
||||
it("formats cloud session sync request correctly for /cloud-api.php and /api/sync_session.php", () => {
|
||||
const buildSyncPayload = (ssoUser: { id?: number | string; name?: string; email?: string; avatar?: string | null }) => {
|
||||
const name = ssoUser.name?.trim() || "YakNet Kullanıcısı";
|
||||
const email = ssoUser.email?.trim() || "";
|
||||
const id = Number(ssoUser.id || 1);
|
||||
const avatar = ssoUser.avatar || `https://ui-avatars.com/api/?name=${encodeURIComponent(name)}&background=0284c7&color=fff`;
|
||||
|
||||
return {
|
||||
action: "sync_session",
|
||||
user: {
|
||||
id,
|
||||
name,
|
||||
email,
|
||||
avatar,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const payload = buildSyncPayload({
|
||||
id: 88,
|
||||
name: "Tasarımcı Öğrenci",
|
||||
email: "[email protected]",
|
||||
});
|
||||
|
||||
expect(payload.action).toBe("sync_session");
|
||||
expect(payload.user.id).toBe(88);
|
||||
expect(payload.user.name).toBe("Tasarımcı Öğrenci");
|
||||
expect(payload.user.email).toBe("[email protected]");
|
||||
expect(payload.user.avatar).toContain("ui-avatars.com");
|
||||
});
|
||||
|
||||
it("handles SSO logout and session clearing correctly", () => {
|
||||
let currentUser: { id: number; name: string } | null = { id: 10, name: "Aktif Kullanıcı" };
|
||||
let cloudProjectsCount = 5;
|
||||
|
||||
const handleSsoLogout = () => {
|
||||
currentUser = null;
|
||||
cloudProjectsCount = 0;
|
||||
};
|
||||
|
||||
handleSsoLogout();
|
||||
expect(currentUser).toBeNull();
|
||||
expect(cloudProjectsCount).toBe(0);
|
||||
});
|
||||
|
||||
it("ensures correct auth base URL for YakNet developer console SSO frame", () => {
|
||||
const YAKNET_AUTH_BASE = "https://developer-console.yakhub.com.tr";
|
||||
const ssoFrameUrl = `${YAKNET_AUTH_BASE}/sdk/sso-frame`;
|
||||
|
||||
expect(ssoFrameUrl).toBe("https://developer-console.yakhub.com.tr/sdk/sso-frame");
|
||||
expect(ssoFrameUrl.startsWith("https://developer-console.yakhub.com.tr")).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user