@@ -10,6 +10,7 @@ import {StorefrontPreview} from './index'
1010import { detectStorefrontPreview } from './utils'
1111import { Helmet } from 'react-helmet'
1212import { useHistory } from 'react-router-dom'
13+ import { getConfig } from 'pwa-kit-runtime/utils/ssr-config'
1314
1415jest . mock ( './utils' , ( ) => {
1516 const origin = jest . requireActual ( './utils' )
@@ -30,17 +31,28 @@ jest.mock('react-router-dom', () => {
3031 }
3132} )
3233
34+ jest . mock ( 'pwa-kit-runtime/utils/ssr-config' , ( ) => ( {
35+ getConfig : jest . fn ( )
36+ } ) )
37+
3338describe ( 'Storefront Preview Component' , function ( ) {
3439 const oldWindow = window
3540
3641 beforeEach ( ( ) => {
3742 // eslint-disable-next-line
3843 window = { ...oldWindow }
44+
45+ getConfig . mockReturnValue ( {
46+ app : {
47+ commerceAPI : { proxyPath : '/mobify/proxy/api' , parameters : { siteId : 'site-id' } }
48+ }
49+ } )
3950 } )
4051
4152 afterEach ( ( ) => {
4253 // eslint-disable-next-line
4354 window = oldWindow
55+ jest . resetAllMocks ( )
4456 } )
4557
4658 test ( 'Renders children when enabled' , async ( ) => {
@@ -104,20 +116,26 @@ describe('Storefront Preview Component', function () {
104116
105117 mount ( < StorefrontPreview getToken = { ( ) => 'my-token' } /> )
106118 expect ( window . STOREFRONT_PREVIEW . getToken ) . toBeDefined ( )
119+ expect ( window . STOREFRONT_PREVIEW . siteId ) . toBeDefined ( )
107120 expect ( window . STOREFRONT_PREVIEW . experimentalUnsafeNavigate ) . toBeDefined ( )
108121 expect ( window . STOREFRONT_PREVIEW . experimentalUnsafeAdditionalSearchParams ) . toBeDefined ( )
109122 expect ( window . STOREFRONT_PREVIEW . experimentalUnsafeReloadServerSide ) . toBeDefined ( )
110123 } )
111124
112125 test ( 'window.STOREFRONT_PREVIEW.experimentalUnsafeNavigate' , ( ) => {
113126 detectStorefrontPreview . mockReturnValue ( true )
127+ const replace = jest . fn ( )
128+ const push = jest . fn ( )
129+
130+ useHistory . mockReturnValue ( { replace, push} )
131+
114132 mount ( < StorefrontPreview getToken = { ( ) => 'my-token' } /> )
115133
116134 window . STOREFRONT_PREVIEW . experimentalUnsafeNavigate ( '/' , 'replace' )
117- expect ( useHistory ( ) . replace ) . toHaveBeenCalledWith ( '/' )
135+ expect ( replace ) . toHaveBeenCalledWith ( '/' )
118136
119137 window . STOREFRONT_PREVIEW . experimentalUnsafeNavigate ( '/' )
120- expect ( useHistory ( ) . push ) . toHaveBeenCalledWith ( '/' )
138+ expect ( push ) . toHaveBeenCalledWith ( '/' )
121139 } )
122140
123141 test ( 'window.STOREFRONT_PREVIEW.experimentalUnsafeAdditionalSearchParams' , async ( ) => {
0 commit comments