|
| 1 | +import type { ReactNode } from "react"; |
| 2 | +import { describe, it, expect, vi } from "vitest"; |
| 3 | +import { render, screen } from "@testing-library/react"; |
| 4 | +import { MemoryRouter } from "react-router-dom"; |
| 5 | + |
| 6 | +import NatureCategoryLayout from "./NatureCategoryLayout"; |
| 7 | + |
| 8 | +vi.mock("@/components/animated/MotionReveal", () => ({ |
| 9 | + MotionReveal: ({ children }: { children: ReactNode }) => <>{children}</>, |
| 10 | +})); |
| 11 | + |
| 12 | +vi.mock("@/features/places/components/PlaceCard", () => ({ |
| 13 | + PlaceCard: ({ place }: { place: { title: string } }) => <div>{place.title}</div>, |
| 14 | +})); |
| 15 | + |
| 16 | +const baseCategory = { |
| 17 | + id: 1, |
| 18 | + slug: "beaches", |
| 19 | + nombre: "Playas", |
| 20 | + descripcion: "Descubre nuestras playas", |
| 21 | + taxonomy: "places", |
| 22 | + parent: null, |
| 23 | + icon: "umbrella", |
| 24 | + is_published: true, |
| 25 | + featured_media: null, |
| 26 | + attachments: [], |
| 27 | + created_at: "2025-01-01", |
| 28 | + updated_at: "2025-01-01", |
| 29 | +}; |
| 30 | + |
| 31 | +const makePlace = (id: number) => ({ |
| 32 | + id, |
| 33 | + slug: `playa-${id}`, |
| 34 | + title: `Playa ${id}`, |
| 35 | + description: "", |
| 36 | + location_text: `Zona ${id}`, |
| 37 | + latitude: 41, |
| 38 | + longitude: 2, |
| 39 | + phone: id === 1 ? "123" : "", |
| 40 | + email: "", |
| 41 | + website: "", |
| 42 | + booking_url: "", |
| 43 | + is_published: true, |
| 44 | + category: 1, |
| 45 | + template_key: "beaches", |
| 46 | + featured_media: null, |
| 47 | + attachments: [], |
| 48 | + created_at: "2025-01-01", |
| 49 | + updated_at: "2025-01-01", |
| 50 | +}); |
| 51 | + |
| 52 | +describe("NatureCategoryLayout beaches comparison", () => { |
| 53 | + it("shows comparison only when exactly two beaches are available", () => { |
| 54 | + render( |
| 55 | + <MemoryRouter> |
| 56 | + <NatureCategoryLayout |
| 57 | + category={baseCategory as any} |
| 58 | + places={[makePlace(1), makePlace(2)] as any} |
| 59 | + events={[] as any} |
| 60 | + isLoadingPlaces={false} |
| 61 | + isLoadingEvents={false} |
| 62 | + /> |
| 63 | + </MemoryRouter>, |
| 64 | + ); |
| 65 | + |
| 66 | + expect(screen.getByText("Compara las dos playas publicadas")).toBeInTheDocument(); |
| 67 | + expect(screen.queryByText("Seleccion editorial")).not.toBeInTheDocument(); |
| 68 | + }); |
| 69 | + |
| 70 | + it("shows editorial fallback when published beaches are not exactly two", () => { |
| 71 | + render( |
| 72 | + <MemoryRouter> |
| 73 | + <NatureCategoryLayout |
| 74 | + category={baseCategory as any} |
| 75 | + places={[makePlace(1), makePlace(2), makePlace(3), makePlace(4)] as any} |
| 76 | + events={[] as any} |
| 77 | + isLoadingPlaces={false} |
| 78 | + isLoadingEvents={false} |
| 79 | + /> |
| 80 | + </MemoryRouter>, |
| 81 | + ); |
| 82 | + |
| 83 | + expect(screen.getByText("Seleccion editorial")).toBeInTheDocument(); |
| 84 | + expect(screen.queryByText("Compara las dos playas publicadas")).not.toBeInTheDocument(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments