feat: Wabenhain Honig-Shop Anwendung
Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
This commit is contained in:
1 parent
5c76fcc266
commit
c7927f2883
240 files changed
+26096
-137
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { describe, test, expect, beforeEach, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { CheckoutForm } from "./checkout-form";
|
||||
import { useCartStore, type CartItem } from "@/store/cart-store";
|
||||
import { I18nProvider } from "@/i18n/i18n-provider";
|
||||
import type { ShippingTierLike } from "@/lib/shipping-calc";
|
||||
import type { BulkDiscountTierLike } from "@/lib/bulk-discount-calc";
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
}));
|
||||
|
||||
const tiers: ShippingTierLike[] = [{ minQuantity: 0, maxQuantity: null, priceCents: 700 }];
|
||||
const bulkDiscountTiers: BulkDiscountTierLike[] = [];
|
||||
|
||||
const item = (overrides: Partial<CartItem> = {}): CartItem => ({
|
||||
productId: "p1",
|
||||
slug: "fruehtracht-2026",
|
||||
name: "Frühtracht 2026",
|
||||
weightGrams: 500,
|
||||
priceCents: 990,
|
||||
image: null,
|
||||
quantity: 1,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
function renderCheckout(items: CartItem[]) {
|
||||
useCartStore.setState({ items, isOpen: false });
|
||||
return render(
|
||||
<I18nProvider locale="de">
|
||||
<CheckoutForm tiers={tiers} bulkDiscountTiers={bulkDiscountTiers} />
|
||||
</I18nProvider>
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useCartStore.setState({ items: [], isOpen: false });
|
||||
});
|
||||
|
||||
describe("CheckoutForm", () => {
|
||||
test("shows the empty-cart message instead of the form when the cart is empty", () => {
|
||||
renderCheckout([]);
|
||||
expect(screen.queryByRole("button", { name: /kostenpflichtig bestellen/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("charges shipping by default and drops it when switching to pickup", async () => {
|
||||
const userEventInstance = userEvent.setup();
|
||||
renderCheckout([item()]);
|
||||
|
||||
expect(screen.getByText("7,00 €")).toBeInTheDocument();
|
||||
|
||||
await userEventInstance.click(screen.getByRole("button", { name: /abholung/i }));
|
||||
|
||||
expect(screen.queryByText("7,00 €")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("kostenlos")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user