overleaf/services/web/test/frontend/helpers/render-with-context.js
Alf Eaton cda947d1ac Remove sysend dependency (#10852)
GitOrigin-RevId: c3d9601256af8720ab41264609cb5c5c810afbba
2023-01-10 09:04:37 +00:00

43 lines
1.1 KiB
JavaScript

// Disable prop type checks for test harnesses
/* eslint-disable react/prop-types */
import { render } from '@testing-library/react'
import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-context'
import { EditorProviders } from './editor-providers'
export function renderWithEditorContext(
component,
contextProps,
renderOptions = {}
) {
const EditorProvidersWrapper = ({ children }) => (
<EditorProviders {...contextProps}>{children}</EditorProviders>
)
return render(component, {
wrapper: EditorProvidersWrapper,
...renderOptions,
})
}
export function ChatProviders({ children, ...props }) {
return (
<EditorProviders {...props}>
<ChatProvider>{children}</ChatProvider>
</EditorProviders>
)
}
export function renderWithChatContext(component, props) {
const ChatProvidersWrapper = ({ children }) => (
<ChatProviders {...props}>{children}</ChatProviders>
)
return render(component, { wrapper: ChatProvidersWrapper })
}
export function cleanUpContext() {
delete window.user
delete window.project_id
delete window._ide
}