@@ -27,6 +27,7 @@ vi.mock("react-router", () => ({
2727 Form : vi . fn ( ( { children } ) => < form > { children } </ form > ) ,
2828 useNavigation : vi . fn ( ( ) => createTestNavigation ( ) ) ,
2929 Link : vi . fn ( ( { children, ...props } ) => < a { ...props } > { children } </ a > ) ,
30+ useSearchParams : vi . fn ( ( ) => [ new URLSearchParams ( ) , vi . fn ( ) ] ) ,
3031} ) ) ;
3132
3233const createTestProps = (
@@ -61,6 +62,23 @@ describe("Product Component", () => {
6162 expect ( screen . queryByText ( "S/150.99" ) ) . toBeInTheDocument ( ) ;
6263 } ) ;
6364
65+ it ( "should render product price with correct currency for stickers variants" , ( ) => {
66+ // Step 1: Setup - Create test props with stickers variants
67+ const props = createTestProps ( {
68+ price : 100 ,
69+ stickersVariants : [
70+ { id : 1 , measure : "3*3" , price : 80 } ,
71+ { id : 2 , measure : "5*5" , price : 120 } ,
72+ { id : 3 , measure : "10*10" , price : 150 } ,
73+ ] ,
74+ } ) ;
75+ // Step 2: Mock - Component mocks already set up above
76+ // Step 3: Call - Render component
77+ render ( < Product { ...props } /> ) ;
78+ // Step 4: Verify - Check price is rendered correctly (should use first variant price)
79+ expect ( screen . queryByText ( "S/80" ) ) . toBeInTheDocument ( ) ;
80+ } ) ;
81+
6482 it ( "should render product description" , ( ) => {
6583 // Step 1: Setup - Create test props
6684 const props = createTestProps ( {
@@ -101,6 +119,44 @@ describe("Product Component", () => {
101119 } ) ;
102120 } ) ;
103121
122+ it ( "should render size selector when product has variants" , ( ) => {
123+ // Step 1: Setup - Create test props with variants
124+ const props = createTestProps ( {
125+ variants : [
126+ { id : 1 , size : "small" } ,
127+ { id : 2 , size : "medium" } ,
128+ { id : 3 , size : "large" } ,
129+ ] ,
130+ } ) ;
131+ // Step 2: Mock - Component mocks already set up above
132+ // Step 3: Call - Render component
133+ render ( < Product { ...props } /> ) ;
134+ // Step 4: Verify - Check size selector is rendered
135+ expect ( screen . queryByText ( "Talla" ) ) . toBeInTheDocument ( ) ;
136+ expect ( screen . queryByText ( "Small" ) ) . toBeInTheDocument ( ) ;
137+ expect ( screen . queryByText ( "Medium" ) ) . toBeInTheDocument ( ) ;
138+ expect ( screen . queryByText ( "Large" ) ) . toBeInTheDocument ( ) ;
139+ } ) ;
140+
141+ it ( "should render measure selector when product has stickers variants" , ( ) => {
142+ // Step 1: Setup - Create test props with stickers variants
143+ const props = createTestProps ( {
144+ stickersVariants : [
145+ { id : 1 , measure : "3*3" , price : 80 } ,
146+ { id : 2 , measure : "5*5" , price : 120 } ,
147+ { id : 3 , measure : "10*10" , price : 150 } ,
148+ ] ,
149+ } ) ;
150+ // Step 2: Mock - Component mocks already set up above
151+ // Step 3: Call - Render component
152+ render ( < Product { ...props } /> ) ;
153+ // Step 4: Verify - Check measure selector is rendered
154+ expect ( screen . queryByText ( "Medida" ) ) . toBeInTheDocument ( ) ;
155+ expect ( screen . queryByText ( "3*3" ) ) . toBeInTheDocument ( ) ;
156+ expect ( screen . queryByText ( "5*5" ) ) . toBeInTheDocument ( ) ;
157+ expect ( screen . queryByText ( "10*10" ) ) . toBeInTheDocument ( ) ;
158+ } ) ;
159+
104160 it ( 'should render "Agregar al Carrito" button' , ( ) => {
105161 // Step 1: Setup - Create test props
106162 const props = createTestProps ( ) ;
@@ -148,7 +204,7 @@ describe("Product Component", () => {
148204 it ( "should render NotFound component when product is not provided" , ( ) => {
149205 // Step 1: Setup - Create props without product
150206 const props = createTestProps ( ) ;
151- props . loaderData . product = undefined ;
207+ props . loaderData = { product : undefined } ;
152208
153209 // Step 2: Mock - Mock NotFound component
154210 // vi.mock("../not-found", () => ({
0 commit comments