diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 3e32c06fb03..645d35a54c2 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -9,6 +9,7 @@ "localdev": "dotenv -e ../../.env -- vinxi dev --port 3002", "build": "vinxi build", "tauri": "tauri", + "test": "vitest run", "test:memory": "node scripts/desktop-memory-soak.js", "test:memory:unit": "vitest run scripts/desktop-memory-soak.test.js" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 82f842d4c57..8283971c1b4 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -6,7 +6,8 @@ }, "scripts": { "typecheck": "tsc -b", - "build": "tsdown" + "build": "tsdown", + "test": "vitest run" }, "publishConfig": { "main": "./dist/index.js" @@ -16,7 +17,8 @@ "react-dom": "^19.1.1", "react-router-dom": "^6.18.0", "tsconfig": "workspace:*", - "typescript": "^5.8.3" + "typescript": "^5.8.3", + "vitest": "~2.1.9" }, "dependencies": { "@aws-sdk/client-s3": "^3.485.0", diff --git a/packages/utils/src/helpers.test.ts b/packages/utils/src/helpers.test.ts new file mode 100644 index 00000000000..1a9e201972b --- /dev/null +++ b/packages/utils/src/helpers.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, it } from "vitest"; + +import { + calculateStrokeDashoffset, + classNames, + getDisplayProgress, + getProgressCircleConfig, + isEmailAllowedByRestriction, + uuidFormat, + uuidParse, +} from "./helpers"; + +describe("helpers", () => { + it("merges class names and resolves conflicting Tailwind utilities", () => { + expect(classNames("px-2 text-sm", false, "px-4")).toBe("text-sm px-4"); + }); + + it("round-trips uuid formatting helpers", () => { + const formatted = "123e4567-e89b-12d3-a456-426614174000"; + const compact = "123e4567e89b12d3a456426614174000"; + + expect(uuidParse(formatted)).toBe(compact); + expect(uuidFormat(compact)).toBe(formatted); + }); + + it("calculates progress circle geometry", () => { + const { circumference } = getProgressCircleConfig(); + + expect(calculateStrokeDashoffset(25, circumference)).toBeCloseTo( + circumference * 0.75, + ); + expect(calculateStrokeDashoffset(100, circumference)).toBe(0); + }); + + it("prefers upload progress over processing progress", () => { + expect(getDisplayProgress(42, 10)).toBe(42); + expect(getDisplayProgress(undefined, 64)).toBe(64); + }); + + it("allows emails by exact address or domain restrictions", () => { + expect(isEmailAllowedByRestriction("owner@cap.so", "")).toBe(true); + expect(isEmailAllowedByRestriction("owner@cap.so", "cap.so")).toBe(true); + expect( + isEmailAllowedByRestriction("owner@cap.so", "admin@example.com"), + ).toBe(false); + expect( + isEmailAllowedByRestriction("admin@example.com", " admin@example.com "), + ).toBe(true); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce77b06b4f8..b6f84808fab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1323,6 +1323,9 @@ importers: typescript: specifier: ^5.8.3 version: 5.8.3 + vitest: + specifier: ~2.1.9 + version: 2.1.9(@types/node@22.15.17)(jsdom@26.1.0)(terser@5.44.0) packages/web-api-contract: dependencies: