2021-04-22 04:37:26 -04:00
|
|
|
// Disable prop type checks for test harnesses
|
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
2020-12-14 06:44:10 -05:00
|
|
|
import React from 'react'
|
|
|
|
import { render } from '@testing-library/react'
|
2021-04-22 04:37:26 -04:00
|
|
|
import sinon from 'sinon'
|
2020-12-14 06:44:10 -05:00
|
|
|
import { ApplicationProvider } from '../../../frontend/js/shared/context/application-context'
|
|
|
|
import { EditorProvider } from '../../../frontend/js/shared/context/editor-context'
|
2021-02-23 05:17:41 -05:00
|
|
|
import { LayoutProvider } from '../../../frontend/js/shared/context/layout-context'
|
2021-04-22 04:37:26 -04:00
|
|
|
import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-context'
|
2020-12-14 06:44:10 -05:00
|
|
|
|
2021-04-22 04:37:26 -04:00
|
|
|
export function EditorProviders({
|
|
|
|
user = { id: '123abd' },
|
|
|
|
projectId = 'project123',
|
|
|
|
socket = {
|
|
|
|
on: sinon.stub(),
|
|
|
|
removeListener: sinon.stub()
|
|
|
|
},
|
|
|
|
children
|
|
|
|
}) {
|
2020-12-14 06:44:10 -05:00
|
|
|
window.user = user || window.user
|
2021-03-10 07:19:54 -05:00
|
|
|
window.ExposedSettings.appName = 'test'
|
2021-03-31 11:46:43 -04:00
|
|
|
window.gitBridgePublicBaseUrl = 'git.overleaf.test'
|
2020-12-14 06:44:10 -05:00
|
|
|
window.project_id = projectId != null ? projectId : window.project_id
|
2021-04-22 04:37:26 -04:00
|
|
|
|
2021-01-14 10:16:54 -05:00
|
|
|
window._ide = {
|
|
|
|
$scope: {
|
|
|
|
project: {
|
|
|
|
owner: {
|
|
|
|
_id: '124abd'
|
|
|
|
}
|
2021-02-23 05:17:41 -05:00
|
|
|
},
|
|
|
|
ui: {
|
2021-03-10 07:19:54 -05:00
|
|
|
chatOpen: true,
|
|
|
|
pdfLayout: 'flat'
|
2021-02-23 05:17:41 -05:00
|
|
|
},
|
|
|
|
$watch: () => {}
|
2021-01-14 10:16:54 -05:00
|
|
|
},
|
2021-04-22 04:37:26 -04:00
|
|
|
socket
|
2021-01-14 10:16:54 -05:00
|
|
|
}
|
2021-04-22 04:37:26 -04:00
|
|
|
return (
|
2020-12-14 06:44:10 -05:00
|
|
|
<ApplicationProvider>
|
2021-03-10 07:19:54 -05:00
|
|
|
<EditorProvider ide={window._ide} settings={{}}>
|
2021-02-23 05:17:41 -05:00
|
|
|
<LayoutProvider $scope={window._ide.$scope}>{children}</LayoutProvider>
|
2021-02-09 10:37:48 -05:00
|
|
|
</EditorProvider>
|
2020-12-14 06:44:10 -05:00
|
|
|
</ApplicationProvider>
|
|
|
|
)
|
|
|
|
}
|
2021-02-09 10:37:48 -05:00
|
|
|
|
2021-04-22 04:37:26 -04:00
|
|
|
export function renderWithEditorContext(children, props) {
|
|
|
|
return render(<EditorProviders {...props}>{children}</EditorProviders>)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ChatProviders({ children, ...props }) {
|
|
|
|
return (
|
|
|
|
<EditorProviders {...props}>
|
|
|
|
<ChatProvider>{children}</ChatProvider>
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function renderWithChatContext(children, props) {
|
|
|
|
return render(<ChatProviders {...props}>{children}</ChatProviders>)
|
2021-02-09 10:37:48 -05:00
|
|
|
}
|
2021-02-17 05:05:33 -05:00
|
|
|
|
|
|
|
export function cleanUpContext() {
|
|
|
|
delete window.user
|
|
|
|
delete window.project_id
|
|
|
|
delete window._ide
|
|
|
|
}
|