From df1db7fa8798cef23310d0871bd30a90cf749c55 Mon Sep 17 00:00:00 2001 From: kishore08-07 Date: Fri, 31 Jul 2026 18:31:12 +0530 Subject: [PATCH] test(dev): mock JamSessionInfoContext in DevPage unit test Signed-off-by: kishore08-07 --- .storybook/preview.tsx | 18 ++++++++++++++++-- src/components/dev/DevPage.test.tsx | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index b6009ab1..fb099afa 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -10,6 +10,7 @@ import { MemoryRouter } from 'react-router-dom' import type { CoreTypes, GlobalTypes } from 'storybook/internal/csf' import { DEFAULT_VIEWPORT, MINIMAL_VIEWPORTS, INITIAL_VIEWPORTS } from 'storybook/viewport' import { JamDisplayContextProvider } from '../src/context/JamDisplayContextProvider' +import { JamSessionInfoContextProvider } from '../src/context/JamSessionInfoContextProvider' import { JamWalletInfoContextProvider } from '../src/context/JamWalletInfoContextProvider' import i18n from '../src/i18n/config' import '../src/index.css' @@ -31,7 +32,7 @@ const locales = [ // Create a global variable called locale in storybook // and add a menu in the toolbar to change your locale -export const globalTypes: GlobalTypes = { +const globalTypes: GlobalTypes = { locale: { name: 'Locale', description: 'Internationalization locale', @@ -99,6 +100,7 @@ const preview: Preview = { return worker }), ], + globalTypes, } const withTheme = (Story: React.ComponentType, context: GlobalContext) => { @@ -151,6 +153,14 @@ export const withJamDisplayContext = (Story: React.ComponentType) => { ) } +export const withJamSessionInfoContext = (Story: React.ComponentType) => { + return ( + + + + ) +} + export const withJamWalletInfoContext = (Story: React.ComponentType) => { return ( @@ -159,14 +169,18 @@ export const withJamWalletInfoContext = (Story: React.ComponentType) => { ) } -// export decorators for storybook to wrap your stories in + + export const decorators = [ withTheme, withMemoryRouter, withI18next, withJamWalletInfoContext, + withJamSessionInfoContext, withQueryClient, withJamDisplayContext, ] +preview.decorators = decorators + export default preview diff --git a/src/components/dev/DevPage.test.tsx b/src/components/dev/DevPage.test.tsx index 6f35c16c..1d7cc699 100644 --- a/src/components/dev/DevPage.test.tsx +++ b/src/components/dev/DevPage.test.tsx @@ -1,6 +1,7 @@ import type { ReactNode } from 'react' import { render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' +import { jmSessionStore } from '@/store/jmSessionStore' import DevPage from './DevPage' vi.mock('react-router-dom', () => ({ @@ -29,6 +30,13 @@ vi.mock('@/context/JamWalletInfoContext', () => ({ useWalletBalanceSummary: () => ({}), })) +vi.mock('@/context/JamSessionInfoContext', () => ({ + useJamSession: () => ({ + jmSession: jmSessionStore.getState().state, + updateSessionInfo: vi.fn(), + }), +})) + vi.mock('@/components/settings/fees/FeeConfigDialog', () => ({ FeeConfigDialog: () =>
, }))