first commit
This commit is contained in:
7
tests/e2e/smoke.spec.ts
Normal file
7
tests/e2e/smoke.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("login screen is visible", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await expect(page.getByText("La Burbuja POS")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Entrar" })).toBeVisible();
|
||||
});
|
||||
51
tests/unit/calculations.test.ts
Normal file
51
tests/unit/calculations.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { calculateAddonTotalCents, calculateExpectedCash, calculateLoyaltyDiscountCents, calculateUtilizationPct } from "@/server/services/calculations";
|
||||
|
||||
describe("calculateExpectedCash", () => {
|
||||
it("computes shift expected cash with deposits and withdrawals", () => {
|
||||
const value = calculateExpectedCash({
|
||||
startingCashCents: 10_000,
|
||||
cashSalesCents: 24_500,
|
||||
depositsCents: 2_000,
|
||||
withdrawalsCents: 1_500
|
||||
});
|
||||
expect(value).toBe(35_000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("calculateUtilizationPct", () => {
|
||||
it("returns rounded percentage", () => {
|
||||
expect(calculateUtilizationPct(43, 120)).toBe(35.83);
|
||||
});
|
||||
|
||||
it("guards zero window", () => {
|
||||
expect(calculateUtilizationPct(10, 0)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("calculateLoyaltyDiscountCents", () => {
|
||||
it("computes rounded discount by percentage", () => {
|
||||
expect(calculateLoyaltyDiscountCents(4_500, 50)).toBe(2_250);
|
||||
});
|
||||
|
||||
it("caps percentage and guards invalid values", () => {
|
||||
expect(calculateLoyaltyDiscountCents(3_000, 150)).toBe(3_000);
|
||||
expect(calculateLoyaltyDiscountCents(3_000, -20)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("calculateAddonTotalCents", () => {
|
||||
it("sums addon quantities by configured prices", () => {
|
||||
expect(
|
||||
calculateAddonTotalCents({
|
||||
detergentQty: 2,
|
||||
softenerQty: 1,
|
||||
bleachQty: 3,
|
||||
detergentAddonCents: 500,
|
||||
softenerAddonCents: 500,
|
||||
bleachAddonCents: 500
|
||||
})
|
||||
).toBe(3_000);
|
||||
});
|
||||
});
|
||||
23
tests/unit/dateRange.test.ts
Normal file
23
tests/unit/dateRange.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseDateRange } from "@/server/api/dateRange";
|
||||
|
||||
describe("parseDateRange", () => {
|
||||
it("parses explicit from/to", () => {
|
||||
const params = new URLSearchParams({
|
||||
from: "2026-04-05T10:00:00.000Z",
|
||||
to: "2026-04-05T18:00:00.000Z"
|
||||
});
|
||||
const range = parseDateRange(params);
|
||||
expect(range.from.toISOString()).toBe("2026-04-05T10:00:00.000Z");
|
||||
expect(range.to.toISOString()).toBe("2026-04-05T18:00:00.000Z");
|
||||
});
|
||||
|
||||
it("throws on inverted range", () => {
|
||||
const params = new URLSearchParams({
|
||||
from: "2026-04-05T18:00:00.000Z",
|
||||
to: "2026-04-05T10:00:00.000Z"
|
||||
});
|
||||
expect(() => parseDateRange(params)).toThrow("Rango de fechas invalido");
|
||||
});
|
||||
});
|
||||
23
tests/unit/time.test.ts
Normal file
23
tests/unit/time.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { addMinutes, clampRange, minutesBetween } from "@/lib/time";
|
||||
|
||||
describe("time helpers", () => {
|
||||
it("adds minutes correctly", () => {
|
||||
const base = new Date("2026-04-06T10:00:00.000Z");
|
||||
const result = addMinutes(base, 35);
|
||||
expect(result.toISOString()).toBe("2026-04-06T10:35:00.000Z");
|
||||
});
|
||||
|
||||
it("returns overlap range", () => {
|
||||
const overlap = clampRange(
|
||||
new Date("2026-04-06T10:00:00.000Z"),
|
||||
new Date("2026-04-06T11:00:00.000Z"),
|
||||
new Date("2026-04-06T10:30:00.000Z"),
|
||||
new Date("2026-04-06T12:00:00.000Z")
|
||||
);
|
||||
expect(overlap?.start.toISOString()).toBe("2026-04-06T10:30:00.000Z");
|
||||
expect(overlap?.end.toISOString()).toBe("2026-04-06T11:00:00.000Z");
|
||||
expect(minutesBetween(overlap!.start, overlap!.end)).toBe(30);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user