context.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import sinon from 'sinon'
  2. export function setupContext() {
  3. window.project_id = '1234'
  4. window.user = {
  5. id: 'fake_user',
  6. allowedFreeTrial: true,
  7. }
  8. const $scope = {
  9. ...window._ide?.$scope,
  10. user: window.user,
  11. project: {
  12. _id: window.project_id,
  13. name: 'Project Fake Name',
  14. features: {},
  15. rootFolder: [
  16. {
  17. _id: 'root-folder-id',
  18. name: 'rootFolder',
  19. docs: [],
  20. folders: [],
  21. fileRefs: [],
  22. },
  23. ],
  24. },
  25. $watch: () => {},
  26. $applyAsync: () => {},
  27. $broadcast: () => {},
  28. ui: {
  29. chatOpen: true,
  30. pdfLayout: 'flat',
  31. },
  32. settings: {
  33. pdfViewer: 'js',
  34. },
  35. toggleHistory: () => {},
  36. }
  37. window._ide = {
  38. ...window._ide,
  39. $scope,
  40. socket: {
  41. on: sinon.stub(),
  42. removeListener: sinon.stub(),
  43. },
  44. fileTreeManager: {
  45. findEntityById: () => null,
  46. findEntityByPath: () => null,
  47. getEntityPath: () => null,
  48. getRootDocDirname: () => undefined,
  49. },
  50. editorManager: {
  51. getCurrentDocId: () => 'foo',
  52. openDoc: (id, options) => {
  53. console.log('open doc', id, options)
  54. },
  55. },
  56. metadataManager: {
  57. metadata: {
  58. state: {
  59. documents: {},
  60. },
  61. },
  62. },
  63. }
  64. window.ExposedSettings = window.ExposedSettings || {}
  65. window.ExposedSettings.appName = 'Overleaf'
  66. window.gitBridgePublicBaseUrl = 'https://git.stories.com'
  67. window.metaAttributesCache = window.metaAttributesCache || new Map()
  68. window.metaAttributesCache.set('ol-user', window.user)
  69. }