2021-04-23 09:01:16 +00:00
|
|
|
// Disable prop type checks for test harnesses
|
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
2020-12-14 11:44:10 +00:00
|
|
|
import { render } from '@testing-library/react'
|
2021-12-14 13:24:53 +00:00
|
|
|
import { renderHook } from '@testing-library/react-hooks'
|
2021-04-23 09:01:16 +00:00
|
|
|
import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-context'
|
2022-03-30 09:49:41 +00:00
|
|
|
import { EditorProviders } from './editor-providers'
|
2021-02-09 15:37:48 +00:00
|
|
|
|
2022-01-10 15:46:46 +00:00
|
|
|
export function renderWithEditorContext(
|
|
|
|
component,
|
|
|
|
contextProps,
|
|
|
|
renderOptions = {}
|
|
|
|
) {
|
2021-06-16 09:32:38 +00:00
|
|
|
const EditorProvidersWrapper = ({ children }) => (
|
|
|
|
<EditorProviders {...contextProps}>{children}</EditorProviders>
|
|
|
|
)
|
|
|
|
|
2022-01-10 15:46:46 +00:00
|
|
|
return render(component, {
|
|
|
|
wrapper: EditorProvidersWrapper,
|
|
|
|
...renderOptions,
|
|
|
|
})
|
2021-04-23 09:01:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:24:53 +00:00
|
|
|
export function renderHookWithEditorContext(hook, contextProps) {
|
|
|
|
const EditorProvidersWrapper = ({ children }) => (
|
|
|
|
<EditorProviders {...contextProps}>{children}</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
return renderHook(hook, { wrapper: EditorProvidersWrapper })
|
|
|
|
}
|
|
|
|
|
2021-04-23 09:01:16 +00:00
|
|
|
export function ChatProviders({ children, ...props }) {
|
|
|
|
return (
|
|
|
|
<EditorProviders {...props}>
|
|
|
|
<ChatProvider>{children}</ChatProvider>
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-03 13:44:23 +00:00
|
|
|
export function renderWithChatContext(component, props) {
|
2021-06-16 09:32:38 +00:00
|
|
|
const ChatProvidersWrapper = ({ children }) => (
|
|
|
|
<ChatProviders {...props}>{children}</ChatProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
return render(component, { wrapper: ChatProvidersWrapper })
|
2021-02-09 15:37:48 +00:00
|
|
|
}
|
2021-02-17 10:05:33 +00:00
|
|
|
|
|
|
|
export function cleanUpContext() {
|
|
|
|
delete window.user
|
|
|
|
delete window.project_id
|
|
|
|
delete window._ide
|
|
|
|
}
|