Files

51 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

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");
});
});