@@ -3,6 +3,7 @@ import ReactDOMServer from 'react-dom/server';
33import CioPlp from '../../../src/components/CioPlp' ;
44import { useCioPlpContext } from '../../../src/hooks/useCioPlpContext' ;
55import { DEMO_API_KEY } from '../../../src/constants' ;
6+ import mockSearchResponse from '../../local_examples/apiSearchResponse.json' ;
67
78describe ( 'CioPlp React Server-Side Rendering' , ( ) => {
89 it ( "throws an error if apiKey isn't provided" , ( ) => {
@@ -60,4 +61,32 @@ describe('CioPlp React Server-Side Rendering', () => {
6061 '<div class="cio-plp"><div>{"cioClient":null,"cioClientOptions":{},"staticRequestConfigs":{},"itemFieldGetters":{},"formatters":{},"callbacks":{},"urlHelpers":{"defaultQueryStringMap":{"query":"q","page":"page","offset":"offset","resultsPerPage":"numResults","filters":"filters","sortBy":"sortBy","sortOrder":"sortOrder","section":"section"}},"renderOverrides":{}}</div></div>' ,
6162 ) ;
6263 } ) ;
64+
65+ it ( 'renders CioPlp with hideGroups set to true on the server' , ( ) => {
66+ // Render the component with hideGroups config and initial data containing groups
67+ const html = ReactDOMServer . renderToString (
68+ < CioPlp
69+ apiKey = { DEMO_API_KEY }
70+ groupsConfigs = { { hideGroups : true } }
71+ initialSearchResponse = { mockSearchResponse }
72+ /> ,
73+ ) ;
74+ // Groups container should not be present when hideGroups is true
75+ expect ( html ) . not . toContain ( 'cio-groups-container' ) ;
76+ expect ( html ) . not . toContain ( 'cio-groups-breadcrumbs' ) ;
77+ } ) ;
78+
79+ it ( 'renders CioPlp with hideGroups set to false on the server' , ( ) => {
80+ // Render the component with hideGroups config and initial data containing groups
81+ const html = ReactDOMServer . renderToString (
82+ < CioPlp
83+ apiKey = { DEMO_API_KEY }
84+ groupsConfigs = { { hideGroups : false } }
85+ initialSearchResponse = { mockSearchResponse }
86+ /> ,
87+ ) ;
88+ // Groups container should be present when hideGroups is false
89+ expect ( html ) . toContain ( 'cio-groups-container' ) ;
90+ expect ( html ) . toContain ( 'cio-groups-breadcrumbs' ) ;
91+ } ) ;
6392} ) ;
0 commit comments