render-with-context.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Disable prop type checks for test harnesses
  2. /* eslint-disable react/prop-types */
  3. import { render } from '@testing-library/react'
  4. import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-context'
  5. import { EditorProviders } from './editor-providers'
  6. export function renderWithEditorContext(
  7. component,
  8. contextProps,
  9. renderOptions = {}
  10. ) {
  11. const EditorProvidersWrapper = ({ children }) => (
  12. <EditorProviders {...contextProps}>{children}</EditorProviders>
  13. )
  14. return render(component, {
  15. wrapper: EditorProvidersWrapper,
  16. ...renderOptions,
  17. })
  18. }
  19. export function ChatProviders({ children, ...props }) {
  20. return (
  21. <EditorProviders {...props}>
  22. <ChatProvider>{children}</ChatProvider>
  23. </EditorProviders>
  24. )
  25. }
  26. export function renderWithChatContext(component, props) {
  27. const ChatProvidersWrapper = ({ children }) => (
  28. <ChatProviders {...props}>{children}</ChatProviders>
  29. )
  30. return render(component, { wrapper: ChatProvidersWrapper })
  31. }
  32. export function cleanUpContext() {
  33. delete window.user
  34. delete window.project_id
  35. delete window._ide
  36. }