overleaf/services/web/test/frontend/helpers/render-with-context.js
Alf Eaton 53324b0cd2 Add Cypress React component testing (#6974)
GitOrigin-RevId: 1260312a0644f3bc60e007a840045974336e264d
2022-04-05 12:17:30 +00:00

52 lines
1.4 KiB
JavaScript

// Disable prop type checks for test harnesses
/* eslint-disable react/prop-types */
import { render } from '@testing-library/react'
import { renderHook } from '@testing-library/react-hooks'
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 renderHookWithEditorContext(hook, contextProps) {
const EditorProvidersWrapper = ({ children }) => (
<EditorProviders {...contextProps}>{children}</EditorProviders>
)
return renderHook(hook, { wrapper: EditorProvidersWrapper })
}
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
}