context.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. let $scope = {}
  9. if (window._ide) {
  10. $scope = {
  11. ...window._ide.$scope,
  12. user: window.user,
  13. project: {},
  14. $watch: () => {},
  15. $applyAsync: () => {},
  16. $broadcast: () => {},
  17. ui: {
  18. chatOpen: true,
  19. pdfLayout: 'flat',
  20. },
  21. settings: {
  22. pdfViewer: 'js',
  23. },
  24. toggleHistory: () => {},
  25. rootFolder: { type: 'folder', children: [] },
  26. }
  27. }
  28. window._ide = {
  29. ...window._ide,
  30. $scope,
  31. socket: {
  32. on: sinon.stub(),
  33. removeListener: sinon.stub(),
  34. },
  35. fileTreeManager: {
  36. findEntityById: () => null,
  37. findEntityByPath: () => null,
  38. getEntityPath: () => null,
  39. getRootDocDirname: () => undefined,
  40. },
  41. editorManager: {
  42. getCurrentDocId: () => 'foo',
  43. openDoc: (id, options) => {
  44. console.log('open doc', id, options)
  45. },
  46. },
  47. metadataManager: {
  48. metadata: {
  49. state: {
  50. documents: {},
  51. },
  52. },
  53. },
  54. }
  55. window.ExposedSettings = window.ExposedSettings || {}
  56. window.ExposedSettings.appName = 'Overleaf'
  57. window.gitBridgePublicBaseUrl = 'https://git.stories.com'
  58. }