generated from nhcarrigan/template
514e137590
Adds mirror-function tests for five Svelte components (HighlightedText, CliVersion, AchievementNotification, StatusBar, ConversationTabs) and removes stale eslint-disable comments from existing store test files.
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
formatCost,
|
|
formatAlertType,
|
|
getAlertMessage,
|
|
type AlertType,
|
|
type CostAlert,
|
|
} from "./costTracking";
|
|
|
|
describe("formatCost", () => {
|
|
it("formats amounts below $0.01 to 4 decimal places", () => {
|
|
expect(formatCost(0)).toBe("$0.0000");
|
|
expect(formatCost(0.001)).toBe("$0.0010");
|
|
expect(formatCost(0.0099)).toBe("$0.0099");
|
|
});
|
|
|
|
it("formats amounts between $0.01 and $1 to 3 decimal places", () => {
|
|
expect(formatCost(0.01)).toBe("$0.010");
|
|
expect(formatCost(0.123)).toBe("$0.123");
|
|
expect(formatCost(0.999)).toBe("$0.999");
|
|
});
|
|
|
|
it("formats amounts $1 and above to 2 decimal places", () => {
|
|
expect(formatCost(1)).toBe("$1.00");
|
|
expect(formatCost(1.5)).toBe("$1.50");
|
|
expect(formatCost(100.99)).toBe("$100.99");
|
|
});
|
|
});
|
|
|
|
describe("formatAlertType", () => {
|
|
it("formats Daily as Today", () => {
|
|
expect(formatAlertType("Daily")).toBe("Today");
|
|
});
|
|
|
|
it("formats Weekly as This Week", () => {
|
|
expect(formatAlertType("Weekly")).toBe("This Week");
|
|
});
|
|
|
|
it("formats Monthly as This Month", () => {
|
|
expect(formatAlertType("Monthly")).toBe("This Month");
|
|
});
|
|
|
|
it("handles all AlertType values", () => {
|
|
const types: AlertType[] = ["Daily", "Weekly", "Monthly"];
|
|
const results = types.map(formatAlertType);
|
|
expect(results).toEqual(["Today", "This Week", "This Month"]);
|
|
});
|
|
});
|
|
|
|
describe("getAlertMessage", () => {
|
|
it("generates a message for a Daily alert", () => {
|
|
const alert: CostAlert = {
|
|
alert_type: "Daily",
|
|
threshold: 1.0,
|
|
current_cost: 1.5,
|
|
};
|
|
const message = getAlertMessage(alert);
|
|
expect(message).toContain("Today");
|
|
expect(message).toContain("$1.50");
|
|
expect(message).toContain("$1.00");
|
|
});
|
|
|
|
it("generates a message for a Weekly alert", () => {
|
|
const alert: CostAlert = {
|
|
alert_type: "Weekly",
|
|
threshold: 5.0,
|
|
current_cost: 6.0,
|
|
};
|
|
const message = getAlertMessage(alert);
|
|
expect(message).toContain("This Week");
|
|
expect(message).toContain("$6.00");
|
|
expect(message).toContain("$5.00");
|
|
});
|
|
|
|
it("generates a message for a Monthly alert", () => {
|
|
const alert: CostAlert = {
|
|
alert_type: "Monthly",
|
|
threshold: 20.0,
|
|
current_cost: 25.0,
|
|
};
|
|
const message = getAlertMessage(alert);
|
|
expect(message).toContain("This Month");
|
|
expect(message).toContain("$25.00");
|
|
expect(message).toContain("$20.00");
|
|
});
|
|
|
|
it("includes threshold and current cost in the message", () => {
|
|
const alert: CostAlert = {
|
|
alert_type: "Daily",
|
|
threshold: 0.005,
|
|
current_cost: 0.007,
|
|
};
|
|
const message = getAlertMessage(alert);
|
|
expect(message).toContain("$0.0070");
|
|
expect(message).toContain("$0.0050");
|
|
});
|
|
});
|