context.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 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. }
  38. window._ide = {
  39. ...window._ide,
  40. $scope,
  41. socket: {
  42. on: sinon.stub(),
  43. removeListener: sinon.stub(),
  44. },
  45. fileTreeManager: {
  46. findEntityById: () => null,
  47. findEntityByPath: () => null,
  48. getEntityPath: () => null,
  49. getRootDocDirname: () => undefined,
  50. },
  51. editorManager: {
  52. getCurrentDocId: () => 'foo',
  53. openDoc: (id, options) => {
  54. console.log('open doc', id, options)
  55. },
  56. },
  57. metadataManager: {
  58. metadata: {
  59. state: {
  60. documents: {},
  61. },
  62. },
  63. },
  64. }
  65. window.ExposedSettings = window.ExposedSettings || {}
  66. window.ExposedSettings.appName = 'Overleaf'
  67. window.gitBridgePublicBaseUrl = 'https://git.stories.com'
  68. }