22import React from 'react' ;
33import { render , screen , fireEvent } from '@testing-library/react' ;
44import ProductCard from '../src/components/ProductCard' ;
5- import { CioPlpContext } from '../src/PlpContext ' ;
5+ import CioPlp from '../src/components/CioPlp ' ;
66import { DEMO_API_KEY } from '../src/constants' ;
77import testItem from './local_examples/item.json' ;
88import { transformResultItem } from '../src/utils/transformers' ;
99
1010describe ( 'Testing Component: ProductCard' , ( ) => {
11- test ( 'Should throw error if used outside the CioPlpContext ' , ( ) => {
11+ test ( 'Should throw error if used outside the CioPlp ' , ( ) => {
1212 const spy = jest . spyOn ( console , 'error' ) ;
1313 spy . mockImplementation ( ( ) => { } ) ;
1414 expect ( ( ) => render ( < ProductCard /> ) ) . toThrow ( ) ;
@@ -20,51 +20,49 @@ describe('Testing Component: ProductCard', () => {
2020 spy . mockImplementation ( ( ) => { } ) ;
2121 expect ( ( ) =>
2222 render (
23- < CioPlpContext apiKey = { DEMO_API_KEY } >
23+ < CioPlp apiKey = { DEMO_API_KEY } >
2424 < ProductCard />
25- </ CioPlpContext > ,
25+ </ CioPlp > ,
2626 ) ,
2727 ) . toThrow ( ) ;
2828 spy . mockRestore ( ) ;
2929 } ) ;
3030
3131 test ( 'Should render default price formatting if not overridden' , ( ) => {
3232 render (
33- < CioPlpContext apiKey = { DEMO_API_KEY } >
33+ < CioPlp apiKey = { DEMO_API_KEY } >
3434 < ProductCard item = { transformResultItem ( testItem ) } />
35- </ CioPlpContext > ,
35+ </ CioPlp > ,
3636 ) ;
3737 screen . getByText ( '$79.00' ) ;
3838 } ) ;
3939
40- test ( 'Should render custom price formatting if overridden at the PlpContext level' , ( ) => {
40+ test ( 'Should render custom price formatting if overridden at the CioPlp provider level' , ( ) => {
4141 const contextPriceFormatter = ( price ) => `USD$${ price . toFixed ( 2 ) } ` ;
4242 render (
43- < CioPlpContext apiKey = { DEMO_API_KEY } formatters = { { formatPrice : contextPriceFormatter } } >
43+ < CioPlp apiKey = { DEMO_API_KEY } formatters = { { formatPrice : contextPriceFormatter } } >
4444 < ProductCard item = { transformResultItem ( testItem ) } />
45- </ CioPlpContext > ,
45+ </ CioPlp > ,
4646 ) ;
4747 screen . getByText ( 'USD$79.00' ) ;
4848 } ) ;
4949
50- test ( 'Should retrieve custom price if overridden at the PlpContext level' , ( ) => {
50+ test ( 'Should retrieve custom price if overridden at the CioPlp provider level' , ( ) => {
5151 const contextPriceGetter = ( item ) => item . data . altPrice ;
5252 render (
53- < CioPlpContext apiKey = { DEMO_API_KEY } getters = { { getPrice : contextPriceGetter } } >
53+ < CioPlp apiKey = { DEMO_API_KEY } getters = { { getPrice : contextPriceGetter } } >
5454 < ProductCard item = { transformResultItem ( testItem ) } />
55- </ CioPlpContext > ,
55+ </ CioPlp > ,
5656 ) ;
5757 screen . getByText ( '$69.00' ) ;
5858 } ) ;
5959
60- test ( 'Should run custom onclick handler if overridden at the PlpContext level' , ( ) => {
60+ test ( 'Should run custom onclick handler if overridden at the CioPlp provider level' , ( ) => {
6161 const contextOnClickHandler = jest . fn ( ) ;
6262 render (
63- < CioPlpContext
64- apiKey = { DEMO_API_KEY }
65- callbacks = { { onProductCardClick : contextOnClickHandler } } >
63+ < CioPlp apiKey = { DEMO_API_KEY } callbacks = { { onProductCardClick : contextOnClickHandler } } >
6664 < ProductCard item = { transformResultItem ( testItem ) } />
67- </ CioPlpContext > ,
65+ </ CioPlp > ,
6866 ) ;
6967 // Click the title
7068 fireEvent . click ( screen . getByText ( 'Jersey Riviera Shirt (Park Bench Dot)' ) ) ;
@@ -83,12 +81,12 @@ describe('Testing Component: ProductCard', () => {
8381 expect ( contextOnClickHandler ) . toHaveBeenCalledTimes ( 3 ) ;
8482 } ) ;
8583
86- test ( 'Should run custom onAddToCart handler if overridden at the PlpContext level' , ( ) => {
84+ test ( 'Should run custom onAddToCart handler if overridden at the CioPlp provider level' , ( ) => {
8785 const contextOnAddToCart = jest . fn ( ) ;
8886 render (
89- < CioPlpContext apiKey = { DEMO_API_KEY } callbacks = { { onAddToCart : contextOnAddToCart } } >
87+ < CioPlp apiKey = { DEMO_API_KEY } callbacks = { { onAddToCart : contextOnAddToCart } } >
9088 < ProductCard item = { transformResultItem ( testItem ) } />
91- </ CioPlpContext > ,
89+ </ CioPlp > ,
9290 ) ;
9391
9492 fireEvent . click ( screen . getByRole ( 'button' , { name : / a d d t o c a r t / i } ) ) ;
@@ -97,14 +95,14 @@ describe('Testing Component: ProductCard', () => {
9795
9896 test ( 'Should render renderProps argument' , ( ) => {
9997 render (
100- < CioPlpContext apiKey = { DEMO_API_KEY } >
98+ < CioPlp apiKey = { DEMO_API_KEY } >
10199 < ProductCard item = { transformResultItem ( testItem ) } >
102100 { ( props ) => (
103101 // Custom Rendered Price
104102 < div > My Rendered Price: { props . formatPrice ( props . getPrice ( props . item ) ) } </ div >
105103 ) }
106104 </ ProductCard >
107- </ CioPlpContext > ,
105+ </ CioPlp > ,
108106 ) ;
109107
110108 screen . getByText ( 'My Rendered Price: $79.00' ) ;
0 commit comments