Skip to content

Commit

Permalink
add a mock application session context (provider) to our standard tes…
Browse files Browse the repository at this point in the history
…ting library wrapper
  • Loading branch information
jay-hodgson committed Oct 18, 2024
1 parent c2184ef commit 5f065d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import {
ApplicationSessionContextProvider,
ApplicationSessionContextType,
} from '../utils/AppUtils/session/ApplicationSessionContext'
export const MOCK_CLEAR_SESSION = jest.fn()

export const MOCK_REFRESH_SESSION = jest.fn()

export const MOCK_CONTEXT_VALUE: ApplicationSessionContextType = {
clearSession: MOCK_CLEAR_SESSION,
refreshSession: MOCK_REFRESH_SESSION,
hasInitializedSession: false,
isLoadingSSO: false,
}

export const MOCK_CONTEXT = React.createContext(MOCK_CONTEXT_VALUE)

/**
* Full context object with default values for testing.
*
* If using @testing-library/react, see {@link TestingLibraryUtils#createWrapper}
*/
export const ApplicationSessionTestContext = jest
.fn()
.mockImplementation(({ children }) => {
return (
<ApplicationSessionContextProvider context={MOCK_CONTEXT_VALUE}>
{children}
</ApplicationSessionContextProvider>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SynapseContextType } from '../utils/context/SynapseContext'
import FullContextProvider, {
defaultQueryClientConfig,
} from '../utils/context/FullContextProvider'
import { ApplicationSessionTestContext } from '../mocks/MockApplicationSessionContext'

type RtlWrapperProps = {
children?: ReactNode
Expand All @@ -26,12 +27,14 @@ export const createWrapperAndQueryClient = (
return {
wrapperFn: function RtlWrapper({ children }: RtlWrapperProps) {
return (
<FullContextProvider
synapseContext={wrapperProps}
queryClient={queryClient}
>
{children}
</FullContextProvider>
<ApplicationSessionTestContext>
<FullContextProvider
synapseContext={wrapperProps}
queryClient={queryClient}
>
{children}
</FullContextProvider>
</ApplicationSessionTestContext>
)
},
queryClient: queryClient,
Expand Down

0 comments on commit 5f065d6

Please sign in to comment.