Skip to content

Commit

Permalink
test override
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggishop committed Jan 31, 2025
1 parent 01e72d5 commit 6996386
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/hydrogen-react/src/ShopifyProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type ShopifyProviderProps,
} from './ShopifyProvider.js';
import type {PartialDeep} from 'type-fest';
import {HydrogenContext, HydrogenContextValue} from './HydrogenProvider.js';

const SHOPIFY_CONFIG: ShopifyProviderProps = {
storeDomain: 'https://notashop.myshopify.com',
Expand Down Expand Up @@ -223,6 +224,61 @@ describe('<ShopifyProvider/>', () => {
);
});
});

describe('hydrogen context overrides', () => {
it('returns the hydrogen overrides if provided (partial override)', () => {
function runTest(hydrogenContextValue: HydrogenContextValue) {
const {result} = renderHook(() => useShop(), {
wrapper: ({children}) => (
<HydrogenContext.Provider value={hydrogenContextValue}>
<ShopifyProvider {...SHOPIFY_CONFIG}>{children}</ShopifyProvider>
</HydrogenContext.Provider>
),
});
return result;
}

const result = runTest({languageIsoCode: 'FR', countryIsoCode: null});
expect(result.current.countryIsoCode).toBe(SHOPIFY_CONFIG.countryIsoCode);
expect(result.current.languageIsoCode).toBe('FR');
});

it('returns the hydrogen overrides if provided (full override)', () => {
function runTest(hydrogenContextValue: HydrogenContextValue) {
const {result} = renderHook(() => useShop(), {
wrapper: ({children}) => (
<HydrogenContext.Provider value={hydrogenContextValue}>
<ShopifyProvider {...SHOPIFY_CONFIG}>{children}</ShopifyProvider>
</HydrogenContext.Provider>
),
});
return result;
}

const result = runTest({languageIsoCode: 'FR', countryIsoCode: 'FR'});
expect(result.current.countryIsoCode).toBe('FR');
expect(result.current.languageIsoCode).toBe('FR');
});

it('returns the hydrogen overrides if provided (full override, without ShopifyProvider)', () => {
// Note(FR): this ensures the current behavior – however it's arguable that not having the ShopifyProvider at all
// should not be possible, as docs currently say it _must_ be there.
function runTest(hydrogenContextValue: HydrogenContextValue) {
const {result} = renderHook(() => useShop(), {
wrapper: ({children}) => (
<HydrogenContext.Provider value={hydrogenContextValue}>
{children}
</HydrogenContext.Provider>
),
});
return result;
}

const result = runTest({languageIsoCode: 'FR', countryIsoCode: 'FR'});
expect(result.current.countryIsoCode).toBe('FR');
expect(result.current.languageIsoCode).toBe('FR');
});
});
});

export function getShopifyConfig(
Expand Down
1 change: 1 addition & 0 deletions templates/debug-cpu-test
Submodule debug-cpu-test added at ba7caa

0 comments on commit 6996386

Please sign in to comment.