1+ import { render , screen } from "@testing-library/react" ;
2+ import { useNavigation } from "react-router" ;
13import { describe , expect , it , vi } from "vitest" ;
24
35import { createTestProduct } from "@/lib/utils.tests" ;
46import type { Product as ProductType } from "@/models/product.model" ;
5- import { render , screen } from "@testing-library/react" ;
67
7- import { useNavigation } from "react-router" ;
88import Product from "." ;
9- import type { Route } from "./+types" ;
109
11- // Mock Container component since we just want to verify it's used correctly
12- vi . mock ( "@/components/ui" , ( ) => ( {
13- Container : vi . fn ( ( { children } ) => (
14- < div data-testid = "mock-container" > { children } </ div >
15- ) ) ,
16- Button : vi . fn ( ( { children, ...props } ) => (
17- < button data-testid = "mock-button" { ...props } >
18- { children }
19- </ button >
20- ) ) ,
21- Separator : vi . fn ( ( ) => < hr data-testid = "mock-separator" /> ) ,
22- } ) ) ;
10+ import type { Route } from "./+types" ;
2311
2412// Helper function to create a test navigation object
2513const createTestNavigation = ( overrides = { } ) => ( {
@@ -38,6 +26,7 @@ const createTestNavigation = (overrides = {}) => ({
3826vi . mock ( "react-router" , ( ) => ( {
3927 Form : vi . fn ( ( { children } ) => < form > { children } </ form > ) ,
4028 useNavigation : vi . fn ( ( ) => createTestNavigation ( ) ) ,
29+ Link : vi . fn ( ( { children, ...props } ) => < a { ...props } > { children } </ a > ) ,
4130} ) ) ;
4231
4332const createTestProps = (
@@ -68,7 +57,7 @@ describe("Product Component", () => {
6857 // Step 3: Call - Render component
6958 render ( < Product { ...props } /> ) ;
7059 // Step 4: Verify - Check price is rendered correctly
71- expect ( screen . getByText ( "$150.99" ) ) . toBeInTheDocument ( ) ;
60+ expect ( screen . queryByText ( "$150.99" ) ) . toBeInTheDocument ( ) ;
7261 } ) ;
7362
7463 it ( "should render product description" , ( ) => {
@@ -80,7 +69,7 @@ describe("Product Component", () => {
8069 // Step 3: Call - Render component
8170 render ( < Product { ...props } /> ) ;
8271 // Step 4: Verify - Check description is rendered
83- expect ( screen . getByText ( "Amazing product" ) ) . toBeInTheDocument ( ) ;
72+ expect ( screen . queryByText ( "Amazing product" ) ) . toBeInTheDocument ( ) ;
8473 } ) ;
8574
8675 it ( "should render product image with correct src and alt attributes" , ( ) => {
@@ -107,7 +96,7 @@ describe("Product Component", () => {
10796 render ( < Product { ...props } /> ) ;
10897 // Step 4: Verify - Check features are rendered
10998 features . forEach ( ( feature ) => {
110- expect ( screen . getByText ( feature ) ) . toBeInTheDocument ( ) ;
99+ expect ( screen . queryByText ( feature ) ) . toBeInTheDocument ( ) ;
111100 } ) ;
112101 } ) ;
113102
@@ -119,7 +108,7 @@ describe("Product Component", () => {
119108 render ( < Product { ...props } /> ) ;
120109 // Step 4: Verify - Check button is present
121110 expect (
122- screen . getByRole ( "button" , { name : "Agregar al Carrito" } )
111+ screen . queryByRole ( "button" , { name : "Agregar al Carrito" } )
123112 ) . toBeInTheDocument ( ) ;
124113 } ) ;
125114 } ) ;
@@ -133,7 +122,9 @@ describe("Product Component", () => {
133122 // Step 3: Call
134123 render ( < Product { ...props } /> ) ;
135124 // Step 4: Verify
136- const redirectInput = screen . getByDisplayValue ( `/products/${ productId } ` ) ;
125+ const redirectInput = screen . queryByDisplayValue (
126+ `/products/${ productId } `
127+ ) ;
137128 expect ( redirectInput ) . toBeInTheDocument ( ) ;
138129 } ) ;
139130
@@ -159,9 +150,9 @@ describe("Product Component", () => {
159150 props . loaderData . product = undefined ;
160151
161152 // Step 2: Mock - Mock NotFound component
162- vi . mock ( "../not-found" , ( ) => ( {
163- default : ( ) => < div data-testid = "not-found" > Not Found Page</ div > ,
164- } ) ) ;
153+ // vi.mock("../not-found", () => ({
154+ // default: () => <div data-testid="not-found">Not Found Page</div>,
155+ // }));
165156 // Step 3: Call
166157 render ( < Product { ...props } /> ) ;
167158 // Step 4: Verify
0 commit comments