2020-12-14 06:44:10 -05:00
|
|
|
import React from 'react'
|
|
|
|
import { render } from '@testing-library/react'
|
|
|
|
import { ApplicationProvider } from '../../../frontend/js/shared/context/application-context'
|
|
|
|
import { EditorProvider } from '../../../frontend/js/shared/context/editor-context'
|
2021-01-14 10:16:54 -05:00
|
|
|
import sinon from 'sinon'
|
2021-02-09 10:37:48 -05:00
|
|
|
import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-context'
|
2021-02-23 05:17:41 -05:00
|
|
|
import { LayoutProvider } from '../../../frontend/js/shared/context/layout-context'
|
2020-12-14 06:44:10 -05:00
|
|
|
|
2021-01-14 10:16:54 -05:00
|
|
|
export function renderWithEditorContext(
|
|
|
|
children,
|
2021-02-10 05:36:41 -05:00
|
|
|
{ user = { id: '123abd' }, projectId = 'project123' } = {}
|
2021-01-14 10:16:54 -05:00
|
|
|
) {
|
2020-12-14 06:44:10 -05:00
|
|
|
window.user = user || window.user
|
|
|
|
window.project_id = projectId != null ? projectId : window.project_id
|
2021-01-14 10:16:54 -05:00
|
|
|
window._ide = {
|
|
|
|
$scope: {
|
|
|
|
project: {
|
|
|
|
owner: {
|
|
|
|
_id: '124abd'
|
|
|
|
}
|
2021-02-23 05:17:41 -05:00
|
|
|
},
|
|
|
|
ui: {
|
|
|
|
chatOpen: true
|
|
|
|
},
|
|
|
|
$watch: () => {}
|
2021-01-14 10:16:54 -05:00
|
|
|
},
|
|
|
|
socket: {
|
|
|
|
on: sinon.stub(),
|
|
|
|
removeListener: sinon.stub()
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 06:44:10 -05:00
|
|
|
return render(
|
|
|
|
<ApplicationProvider>
|
2021-02-10 05:57:25 -05:00
|
|
|
<EditorProvider
|
|
|
|
openDoc={() => {}}
|
|
|
|
onlineUsersArray={[]}
|
2021-02-23 05:17:41 -05:00
|
|
|
$scope={window._ide.$scope}
|
2021-02-10 05:57:25 -05:00
|
|
|
>
|
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
|
|
|
|
|
|
|
export function renderWithChatContext(children, { user, projectId } = {}) {
|
|
|
|
return renderWithEditorContext(<ChatProvider>{children}</ChatProvider>, {
|
|
|
|
user,
|
|
|
|
projectId
|
|
|
|
})
|
|
|
|
}
|
2021-02-17 05:05:33 -05:00
|
|
|
|
|
|
|
export function cleanUpContext() {
|
|
|
|
delete window.user
|
|
|
|
delete window.project_id
|
|
|
|
delete window._ide
|
|
|
|
}
|