|
| 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