Skip to content

Commit f8ac0ca

Browse files
authored
Merge pull request #188 from codeableorg/OrderConfirmation-route-module-test
OrderConfirmation-route-module-test
2 parents 881f199 + 6c89778 commit f8ac0ca

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { loader } from ".";
4+
5+
describe("OrderConfirmation loader", () => {
6+
// Helper function to create loader arguments
7+
const createLoaderArgs = (orderId: string) => ({
8+
params: { orderId },
9+
request: new Request(`http://localhost/order-confirmation/${orderId}`),
10+
context: {},
11+
});
12+
13+
it("should return orderId from params", async () => {
14+
// Step 1: Setup - Create test data
15+
const testOrderId = "testOrderId-123"; // Example order ID
16+
17+
// Step 2: Mock - Not needed as loader has no dependencies
18+
19+
// Step 3: Call service function
20+
const result = await loader(createLoaderArgs(testOrderId));
21+
22+
// Step 4: Verify expected behavior
23+
expect(result).toEqual({
24+
orderId: testOrderId,
25+
});
26+
});
27+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
// Creates minimal test props for OrderConfirmation component
8+
const createTestProps = (orderId = "test-123"): Route.ComponentProps => ({
9+
loaderData: { orderId },
10+
params: vi.fn() as any,
11+
matches: vi.fn() as any,
12+
});
13+
14+
describe("OrderConfirmation", () => {
15+
describe("Success Messages Display", () => {
16+
it("should display all success messages correctly", () => {
17+
// Step 1: Setup - Create test props
18+
const props = createTestProps();
19+
// Step 2: Mock
20+
// Step 3: Call - Render component
21+
render(<OrderConfirmation {...props} />);
22+
// Step 4: Verify - Check all success messages
23+
const expectedMessages = [
24+
"¡Muchas gracias por tu compra!",
25+
"Tu orden está en camino",
26+
"Llegaremos a la puerta de tu domicilio lo antes posible",
27+
];
28+
expectedMessages.forEach((message) => {
29+
expect(screen.queryByText(message)).toBeInTheDocument();
30+
});
31+
});
32+
});
33+
34+
describe("Order Tracking Information", () => {
35+
it("should display correct tracking code section", () => {
36+
// Step 1: Setup - Create test props with a specific order ID
37+
const testOrderId = "order-456";
38+
const props = createTestProps(testOrderId);
39+
// Step 2: Mock
40+
// Step 3: Call - Render component
41+
render(<OrderConfirmation {...props} />);
42+
// Step 4: Verify - Check tracking code section
43+
const trackingCodeLabel = screen.queryByText("Código de seguimiento");
44+
expect(trackingCodeLabel).toBeInTheDocument();
45+
46+
const trackingCode = screen.queryByText(testOrderId);
47+
expect(trackingCode).toBeInTheDocument();
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)