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
107 lines
3.2 KiB
TypeScript
107 lines
3.2 KiB
TypeScript
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");
|
||
|
|
});
|
||
|
|
});
|