2022-03-30 05:49:41 -04:00
|
|
|
// Disable prop type checks for test harnesses
|
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
import sinon from 'sinon'
|
2023-10-26 06:01:08 -04:00
|
|
|
import { get, merge } from 'lodash'
|
2023-10-16 07:10:43 -04:00
|
|
|
import { SplitTestProvider } from '@/shared/context/split-test-context'
|
2023-10-24 10:57:17 -04:00
|
|
|
import { IdeAngularProvider } from '@/shared/context/ide-angular-provider'
|
2023-10-16 07:10:43 -04:00
|
|
|
import { UserProvider } from '@/shared/context/user-context'
|
|
|
|
import { ProjectProvider } from '@/shared/context/project-context'
|
|
|
|
import { FileTreeDataProvider } from '@/shared/context/file-tree-data-context'
|
|
|
|
import { EditorProvider } from '@/shared/context/editor-context'
|
|
|
|
import { DetachProvider } from '@/shared/context/detach-context'
|
|
|
|
import { LayoutProvider } from '@/shared/context/layout-context'
|
|
|
|
import { LocalCompileProvider } from '@/shared/context/local-compile-context'
|
|
|
|
import { DetachCompileProvider } from '@/shared/context/detach-compile-context'
|
|
|
|
import { ProjectSettingsProvider } from '@/features/editor-left-menu/context/project-settings-context'
|
2023-10-26 06:01:08 -04:00
|
|
|
import { FileTreePathProvider } from '@/features/file-tree/contexts/file-tree-path'
|
2023-11-21 09:29:44 -05:00
|
|
|
import { UserSettingsProvider } from '@/shared/context/user-settings-context'
|
2023-12-15 04:19:42 -05:00
|
|
|
import { OutlineProvider } from '@/features/ide-react/context/outline-context'
|
2022-03-30 05:49:41 -04:00
|
|
|
|
|
|
|
// these constants can be imported in tests instead of
|
|
|
|
// using magic strings
|
|
|
|
export const PROJECT_ID = 'project123'
|
|
|
|
export const PROJECT_NAME = 'project-name'
|
2022-07-08 03:24:14 -04:00
|
|
|
export const USER_ID = '123abd'
|
|
|
|
export const USER_EMAIL = 'testuser@example.com'
|
2022-03-30 05:49:41 -04:00
|
|
|
|
2023-11-21 09:29:44 -05:00
|
|
|
const defaultUserSettings = {
|
|
|
|
pdfViewer: 'pdfjs',
|
|
|
|
fontSize: 12,
|
|
|
|
fontFamily: 'monaco',
|
|
|
|
lineHeight: 'normal',
|
|
|
|
editorTheme: 'textmate',
|
|
|
|
overallTheme: '',
|
|
|
|
mode: 'default',
|
|
|
|
autoComplete: true,
|
|
|
|
autoPairDelimiters: true,
|
|
|
|
trackChanges: true,
|
|
|
|
syntaxValidation: false,
|
|
|
|
}
|
|
|
|
|
2022-03-30 05:49:41 -04:00
|
|
|
export function EditorProviders({
|
2022-07-08 03:24:14 -04:00
|
|
|
user = { id: USER_ID, email: USER_EMAIL },
|
2022-03-30 05:49:41 -04:00
|
|
|
projectId = PROJECT_ID,
|
2023-05-02 10:00:45 -04:00
|
|
|
projectOwner = {
|
|
|
|
_id: '124abd',
|
|
|
|
email: 'owner@example.com',
|
|
|
|
},
|
2022-03-30 05:49:41 -04:00
|
|
|
rootDocId = '_root_doc_id',
|
|
|
|
socket = {
|
|
|
|
on: sinon.stub(),
|
|
|
|
removeListener: sinon.stub(),
|
|
|
|
},
|
|
|
|
isRestrictedTokenMember = false,
|
|
|
|
clsiServerId = '1234',
|
2022-04-06 06:14:43 -04:00
|
|
|
scope = {},
|
2022-03-30 05:49:41 -04:00
|
|
|
features = {
|
|
|
|
referencesSearch: true,
|
|
|
|
},
|
|
|
|
permissionsLevel = 'owner',
|
|
|
|
children,
|
|
|
|
rootFolder = [
|
|
|
|
{
|
|
|
|
_id: 'root-folder-id',
|
|
|
|
name: 'rootFolder',
|
|
|
|
docs: [],
|
|
|
|
folders: [],
|
|
|
|
fileRefs: [],
|
|
|
|
},
|
|
|
|
],
|
2022-07-18 06:24:14 -04:00
|
|
|
ui = { view: 'editor', pdfLayout: 'sideBySide', chatOpen: true },
|
2022-03-30 05:49:41 -04:00
|
|
|
fileTreeManager = {
|
|
|
|
findEntityById: () => null,
|
|
|
|
findEntityByPath: () => null,
|
|
|
|
getEntityPath: () => '',
|
|
|
|
getRootDocDirname: () => '',
|
2023-02-16 08:23:53 -05:00
|
|
|
getPreviewByPath: path => ({ url: path, extension: 'png' }),
|
2022-03-30 05:49:41 -04:00
|
|
|
},
|
|
|
|
editorManager = {
|
|
|
|
getCurrentDocId: () => 'foo',
|
|
|
|
getCurrentDocValue: () => {},
|
|
|
|
openDoc: sinon.stub(),
|
|
|
|
},
|
2022-05-26 05:30:37 -04:00
|
|
|
metadataManager = {
|
|
|
|
metadata: {
|
|
|
|
state: {
|
|
|
|
documents: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-11-21 09:29:44 -05:00
|
|
|
userSettings = {},
|
2023-10-26 06:01:08 -04:00
|
|
|
providers = {},
|
2022-03-30 05:49:41 -04:00
|
|
|
}) {
|
|
|
|
window.user = user || window.user
|
2023-05-17 05:23:23 -04:00
|
|
|
window.gitBridgePublicBaseUrl = 'https://git.overleaf.test'
|
2022-03-30 05:49:41 -04:00
|
|
|
window.project_id = projectId != null ? projectId : window.project_id
|
|
|
|
window.isRestrictedTokenMember = isRestrictedTokenMember
|
2023-11-21 09:29:44 -05:00
|
|
|
window.metaAttributesCache.set(
|
|
|
|
'ol-userSettings',
|
|
|
|
merge({}, defaultUserSettings, userSettings)
|
|
|
|
)
|
2022-03-30 05:49:41 -04:00
|
|
|
|
2023-10-26 06:01:08 -04:00
|
|
|
const $scope = merge(
|
|
|
|
{
|
|
|
|
user: window.user,
|
|
|
|
project: {
|
|
|
|
_id: window.project_id,
|
|
|
|
name: PROJECT_NAME,
|
|
|
|
owner: projectOwner,
|
|
|
|
features,
|
|
|
|
rootDoc_id: rootDocId,
|
|
|
|
rootFolder,
|
|
|
|
},
|
|
|
|
ui,
|
|
|
|
$watch: (path, callback) => {
|
|
|
|
callback(get($scope, path))
|
|
|
|
return () => null
|
|
|
|
},
|
|
|
|
$on: sinon.stub(),
|
|
|
|
$applyAsync: sinon.stub(),
|
|
|
|
permissionsLevel,
|
2022-03-30 05:49:41 -04:00
|
|
|
},
|
2023-10-26 06:01:08 -04:00
|
|
|
scope
|
|
|
|
)
|
2022-03-30 05:49:41 -04:00
|
|
|
|
|
|
|
window._ide = {
|
|
|
|
$scope,
|
|
|
|
socket,
|
|
|
|
clsiServerId,
|
|
|
|
editorManager,
|
|
|
|
fileTreeManager,
|
|
|
|
metadataManager,
|
|
|
|
}
|
|
|
|
|
2022-12-20 08:01:54 -05:00
|
|
|
// Add details for useUserContext
|
|
|
|
window.metaAttributesCache.set('ol-user', { ...user, features })
|
2023-10-26 06:01:08 -04:00
|
|
|
const Providers = {
|
|
|
|
DetachCompileProvider,
|
|
|
|
DetachProvider,
|
|
|
|
EditorProvider,
|
|
|
|
FileTreeDataProvider,
|
|
|
|
FileTreePathProvider,
|
|
|
|
IdeAngularProvider,
|
|
|
|
LayoutProvider,
|
|
|
|
LocalCompileProvider,
|
2023-12-15 04:19:42 -05:00
|
|
|
OutlineProvider,
|
2023-10-26 06:01:08 -04:00
|
|
|
ProjectProvider,
|
|
|
|
ProjectSettingsProvider,
|
|
|
|
SplitTestProvider,
|
|
|
|
UserProvider,
|
2023-11-21 09:29:44 -05:00
|
|
|
UserSettingsProvider,
|
2023-10-26 06:01:08 -04:00
|
|
|
...providers,
|
|
|
|
}
|
2022-12-20 08:01:54 -05:00
|
|
|
|
2022-03-30 05:49:41 -04:00
|
|
|
return (
|
2023-10-26 06:01:08 -04:00
|
|
|
<Providers.SplitTestProvider>
|
|
|
|
<Providers.IdeAngularProvider ide={window._ide}>
|
|
|
|
<Providers.UserProvider>
|
2023-11-21 09:29:44 -05:00
|
|
|
<Providers.UserSettingsProvider>
|
|
|
|
<Providers.ProjectProvider>
|
|
|
|
<Providers.FileTreeDataProvider>
|
|
|
|
<Providers.FileTreePathProvider>
|
|
|
|
<Providers.DetachProvider>
|
|
|
|
<Providers.EditorProvider>
|
|
|
|
<Providers.ProjectSettingsProvider>
|
|
|
|
<Providers.LayoutProvider>
|
|
|
|
<Providers.LocalCompileProvider>
|
|
|
|
<Providers.DetachCompileProvider>
|
2023-12-15 04:19:42 -05:00
|
|
|
<Providers.OutlineProvider>
|
|
|
|
{children}
|
|
|
|
</Providers.OutlineProvider>
|
2023-11-21 09:29:44 -05:00
|
|
|
</Providers.DetachCompileProvider>
|
|
|
|
</Providers.LocalCompileProvider>
|
|
|
|
</Providers.LayoutProvider>
|
|
|
|
</Providers.ProjectSettingsProvider>
|
|
|
|
</Providers.EditorProvider>
|
|
|
|
</Providers.DetachProvider>
|
|
|
|
</Providers.FileTreePathProvider>
|
|
|
|
</Providers.FileTreeDataProvider>
|
|
|
|
</Providers.ProjectProvider>
|
|
|
|
</Providers.UserSettingsProvider>
|
2023-10-26 06:01:08 -04:00
|
|
|
</Providers.UserProvider>
|
|
|
|
</Providers.IdeAngularProvider>
|
|
|
|
</Providers.SplitTestProvider>
|
2022-03-30 05:49:41 -04:00
|
|
|
)
|
|
|
|
}
|