Skip to content

Commit f5b1880

Browse files
committed
feat: add OrderConfirmation component tests for success messages, tracking information, and layout structure
1 parent 065f269 commit f5b1880

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { describe, expect, it, vi } from "vitest";
3+
4+
import OrderConfirmation from ".";
5+
import type { Route } from "./+types";
6+
7+
// Mock Container component
8+
vi.mock("@/components/ui", () => ({
9+
Container: vi.fn(({ children }) => (
10+
<div data-testid="mock-container">{children}</div>
11+
)),
12+
}));
13+
14+
// Creates minimal test props for OrderConfirmation component
15+
const createTestProps = (orderId = "test-123"): Route.ComponentProps => ({
16+
loaderData: { orderId },
17+
params: vi.fn() as any,
18+
matches: vi.fn() as any,
19+
});
20+
21+
describe("OrderConfirmation", () => {
22+
describe("Success Messages Display", () => {
23+
it("should display all success messages correctly", () => {
24+
// Step 1: Setup - Create test props
25+
const props = createTestProps();
26+
// Step 2: Mock
27+
// Step 3: Call - Render component
28+
render(<OrderConfirmation {...props} />);
29+
// Step 4: Verify - Check all success messages
30+
const expectedMessages = [
31+
"¡Muchas gracias por tu compra!",
32+
"Tu orden está en camino",
33+
"Llegaremos a la puerta de tu domicilio lo antes posible",
34+
];
35+
expectedMessages.forEach((message) => {
36+
expect(screen.getByText(message)).toBeInTheDocument();
37+
});
38+
});
39+
});
40+
41+
describe("Order Tracking Information", () => {
42+
it("should display correct tracking code section", () => {
43+
// Step 1: Setup - Create test props with a specific order ID
44+
const testOrderId = "order-456";
45+
const props = createTestProps(testOrderId);
46+
// Step 2: Mock
47+
// Step 3: Call - Render component
48+
render(<OrderConfirmation {...props} />);
49+
// Step 4: Verify - Check tracking code section
50+
const trackingCodeLabel = screen.getByText("Código de seguimiento");
51+
expect(trackingCodeLabel).toBeInTheDocument();
52+
53+
const trackingCode = screen.getByText(testOrderId);
54+
expect(trackingCode).toBeInTheDocument();
55+
});
56+
});
57+
58+
describe("Layout Structure", () => {
59+
it("should render with correct layout structure and classes", () => {
60+
// Step 1: Setup - Create test props
61+
const props = createTestProps();
62+
// Step 2: Mock
63+
// Step 3: Call - Render component
64+
render(<OrderConfirmation {...props} />);
65+
// Step 4: Verify - Check layout structure
66+
const container = screen.getByTestId("mock-container");
67+
expect(container).toBeInTheDocument();
68+
69+
const section = container.parentElement;
70+
expect(section).toHaveClass(
71+
"pt-12",
72+
"pb-12",
73+
"sm:pt-14",
74+
"sm:pb-14",
75+
"lg:pt-16",
76+
"lg:pb-16"
77+
);
78+
});
79+
});
80+
});

0 commit comments

Comments
 (0)