mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 21:41:17 +00:00
89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
vi.mock("next/image", () => ({ default: () => null }));
|
|
vi.mock("@/src/modules/courses/actions/booking-actions", () => ({
|
|
checkUserBookingStatus: vi.fn(),
|
|
previewDiscountCode: vi.fn(),
|
|
}));
|
|
vi.mock("@/src/modules/courses/actions/waitlist-actions", () => ({
|
|
joinWaitlistAsUser: vi.fn(),
|
|
}));
|
|
vi.mock("@/src/modules/products/actions/pass-booking-actions", () => ({
|
|
bookCourseWithPass: vi.fn(),
|
|
}));
|
|
vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn() }) }));
|
|
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
|
|
|
import { BookingDialog } from "@/src/modules/courses/ui/components/BookingDialog";
|
|
import { checkUserBookingStatus } from "@/src/modules/courses/actions/booking-actions";
|
|
|
|
const course = {
|
|
id: "course-1",
|
|
name: "Spinning",
|
|
sport: ["spinning"],
|
|
level: "any",
|
|
date: new Date("2099-01-01"),
|
|
timeFrom: "07:30",
|
|
timeTo: "08:30",
|
|
maxParticipants: 10,
|
|
price: 12,
|
|
currentParticipants: 0,
|
|
};
|
|
|
|
function renderDialog() {
|
|
return render(
|
|
<BookingDialog course={course} open onOpenChange={() => {}} serviceFeeCents={50} />
|
|
);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("BookingDialog", () => {
|
|
it("zeigt Gästen das Gast-Formular sofort, ohne zweiten Buchen-Button", async () => {
|
|
vi.mocked(checkUserBookingStatus).mockResolvedValue({
|
|
success: true,
|
|
isLoggedIn: false,
|
|
isBooked: false,
|
|
isOnWaitlist: false,
|
|
});
|
|
|
|
renderDialog();
|
|
|
|
expect(await screen.findByText("Als Gast buchen")).toBeTruthy();
|
|
expect(screen.queryByRole("button", { name: "Buchen" })).toBeNull();
|
|
// Rabattcodes gibt es nur für Angemeldete.
|
|
expect(screen.queryByPlaceholderText("Rabattcode")).toBeNull();
|
|
});
|
|
|
|
it("zeigt Angemeldeten Buchen-Button und Rabattcode statt Gast-Formular", async () => {
|
|
vi.mocked(checkUserBookingStatus).mockResolvedValue({
|
|
success: true,
|
|
isLoggedIn: true,
|
|
isBooked: false,
|
|
isOnWaitlist: false,
|
|
});
|
|
|
|
renderDialog();
|
|
|
|
expect(await screen.findByRole("button", { name: "Buchen" })).toBeTruthy();
|
|
expect(screen.getByPlaceholderText("Rabattcode")).toBeTruthy();
|
|
expect(screen.queryByText("Als Gast buchen")).toBeNull();
|
|
});
|
|
|
|
it("zeigt den Endpreis inklusive Servicegebühr", async () => {
|
|
vi.mocked(checkUserBookingStatus).mockResolvedValue({
|
|
success: true,
|
|
isLoggedIn: true,
|
|
isBooked: false,
|
|
isOnWaitlist: false,
|
|
});
|
|
|
|
renderDialog();
|
|
|
|
expect(await screen.findByText("Preis: 12,50 €")).toBeTruthy();
|
|
expect(screen.getByText(/12,00 €\s*Kurs \+ 0,50 € Servicegebühr/)).toBeTruthy();
|
|
});
|
|
});
|