Files
snapcad-studio/tests/unit/voiceAndNesting.test.ts
T
Enes Yakıştır e7b6db9db6
CI / Typecheck and unit tests (push) Canceled after 0s
Build and Push Docker Images / build (push) Canceled after 0s
feat: sesli CAD asistani, bellek optimizasyonlari ve akilli cozunurluk
- SnapVoice Turkce sesli CAD ve komut konsolu (/denetle, /ram, /eko, /otomatik, /sessiz)
- 3B uzamsal sesli radar ve gorme engelli gelistirici geometri denetim motoru
- LibreDWG/DXF ikili sikistirma, font tembel yukleme ve RAM optimizasyonu
- Monitor cozunurlugune gore otomatik uyarlamali dinamik grafik modu
2026-11-02 13:37:37 +03:00

90 lines
4.5 KiB
TypeScript

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { parseCadVoiceCommand } from "@/lib/voiceCadCommander";
import { compute2DSheetNesting, nestingResultToCadEntities } from "@/lib/sheetNesting";
describe("SnapVoice CAD - Voice Command Parser", () => {
it("parses box dimensions and hole status from natural Turkish voice", () => {
const cmd1 = parseCadVoiceCommand("50'ye 30 kutu ekle");
expect(cmd1.action).toBe("add_shape");
expect(cmd1.payload?.kind).toBe("box");
expect(cmd1.payload?.width).toBe(50);
expect(cmd1.payload?.depth).toBe(30);
expect(cmd1.payload?.isHole).toBe(false);
const cmd2 = parseCadVoiceCommand("25 çapında delik silindir ekle");
expect(cmd2.action).toBe("add_shape");
expect(cmd2.payload?.kind).toBe("cylinder");
expect(cmd2.payload?.width).toBe(25);
expect(cmd2.payload?.isHole).toBe(true);
expect(cmd2.speechFeedback).toContain("delik kesici");
});
it("parses operation commands: group, ungroup, delete, audit, undo", () => {
expect(parseCadVoiceCommand("seçili nesneleri grupla").action).toBe("group");
expect(parseCadVoiceCommand("grubu çöz").action).toBe("ungroup");
expect(parseCadVoiceCommand("seçileni sil").action).toBe("delete");
expect(parseCadVoiceCommand("sahneyi denetle ve rapor ver").action).toBe("open_audit");
expect(parseCadVoiceCommand("geri al").action).toBe("undo");
expect(parseCadVoiceCommand("ölçüleri oku").action).toBe("speak_selection");
});
it("parses slash commands and quick shortcuts seamlessly", () => {
expect(parseCadVoiceCommand("/denetle").action).toBe("open_audit");
expect(parseCadVoiceCommand("/dxf").action).toBe("export_dxf");
expect(parseCadVoiceCommand("/pdf").action).toBe("export_pdf");
expect(parseCadVoiceCommand("/gcode").action).toBe("gcode");
expect(parseCadVoiceCommand("/sac").action).toBe("nesting");
expect(parseCadVoiceCommand("/radar").action).toBe("sonar_radar");
expect(parseCadVoiceCommand("/yardım").action).toBe("help");
expect(parseCadVoiceCommand("/sessiz").action).toBe("mute_voice");
expect(parseCadVoiceCommand("/ses kapat").action).toBe("mute_voice");
expect(parseCadVoiceCommand("/ses aç").action).toBe("unmute_voice");
expect(parseCadVoiceCommand("/ram").action).toBe("ram_cleanup");
expect(parseCadVoiceCommand("/bellek temizle").action).toBe("ram_cleanup");
expect(parseCadVoiceCommand("/eko").action).toBe("toggle_eco_mode");
expect(parseCadVoiceCommand("/düşük ram").action).toBe("toggle_eco_mode");
expect(parseCadVoiceCommand("/otomatik").action).toBe("set_resolution_auto");
expect(parseCadVoiceCommand("/kutu 50 30").action).toBe("add_shape");
expect(parseCadVoiceCommand("/kutu 50 30").payload?.width).toBe(50);
});
it("handles unknown or empty inputs gracefully with guidance", () => {
const res = parseCadVoiceCommand("merhaba nasılsın");
expect(res.action).toBe("unknown");
expect(res.speechFeedback).toContain("anlaşılamadı");
});
});
describe("2D Sheet Nesting Optimizer (CNC Laser Cutting)", () => {
it("packs rectangular parts onto a standard plate with margins and computes efficiency", () => {
const items = [
{ id: "1", name: "Parça A", width: 200, height: 100 },
{ id: "2", name: "Parça B", width: 150, height: 80 },
{ id: "3", name: "Parça C", width: 100, height: 60 },
{ id: "4", name: "Parça D", width: 80, height: 40 },
];
const result = compute2DSheetNesting(items, 600, 400, 5);
expect(result.placedItems.length).toBe(4);
expect(result.unplacedItems.length).toBe(0);
expect(result.sheetAreaMm2).toBe(240000);
expect(result.usedAreaMm2).toBe(200 * 100 + 150 * 80 + 100 * 60 + 80 * 40);
expect(result.efficiencyPercent).toBeGreaterThan(15);
expect(result.wastePercent).toBeLessThan(85);
expect(result.speechSummary).toContain("Nesting yerleşimi tamamlandı");
expect(result.textReport).toContain("SNAPCAD 2B SAC & LAZER YERLEŞİM");
});
it("converts nesting layout into CAD entities with border and part outlines", () => {
const items = [{ id: "1", name: "Kare Plaka", width: 100, height: 100 }];
const nesting = compute2DSheetNesting(items, 400, 300, 5);
const cadEntities = nestingResultToCadEntities(nesting);
expect(cadEntities.length).toBe(2); // Sheet border + 1 part
expect(cadEntities[0].type).toBe("rect");
expect(cadEntities[0].layer).toBe("DIMENSION");
expect(cadEntities[1].type).toBe("rect");
expect(cadEntities[1].layer).toBe("VISIBLE");
});
});