HistoryManagerV2Tests.coffee 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Path = require 'path'
  2. SandboxedModule = require "sandboxed-module"
  3. modulePath = Path.join __dirname, '../../../public/js/ide/history/HistoryV2Manager'
  4. sinon = require("sinon")
  5. expect = require("chai").expect
  6. describe "HistoryV2Manager", ->
  7. beforeEach ->
  8. @moment = {}
  9. @ColorManager = {}
  10. SandboxedModule.require modulePath, globals:
  11. "define": (dependencies, builder) =>
  12. @HistoryV2Manager = builder(@moment, @ColorManager)
  13. @scope =
  14. $watch: sinon.stub()
  15. $on: sinon.stub()
  16. @ide = {}
  17. @historyManager = new @HistoryV2Manager(@ide, @scope)
  18. it "should setup the history scope on intialization", ->
  19. expect(@scope.history).to.deep.equal({
  20. isV2: true
  21. updates: []
  22. nextBeforeTimestamp: null
  23. atEnd: false
  24. selection: {
  25. updates: []
  26. pathname: null
  27. range: {
  28. fromV: null
  29. toV: null
  30. }
  31. }
  32. diff: null
  33. })
  34. describe "_perDocSummaryOfUpdates", ->
  35. it "should return the range of updates for the docs", ->
  36. result = @historyManager._perDocSummaryOfUpdates([{
  37. pathnames: ["main.tex"]
  38. fromV: 7, toV: 9
  39. },{
  40. pathnames: ["main.tex", "foo.tex"]
  41. fromV: 4, toV: 6
  42. },{
  43. pathnames: ["main.tex"]
  44. fromV: 3, toV: 3
  45. },{
  46. pathnames: ["foo.tex"]
  47. fromV: 0, toV: 2
  48. }])
  49. expect(result).to.deep.equal({
  50. "main.tex": { fromV: 3, toV: 9 },
  51. "foo.tex": { fromV: 0, toV: 6 }
  52. })
  53. it "should track renames", ->
  54. result = @historyManager._perDocSummaryOfUpdates([{
  55. pathnames: ["main2.tex"]
  56. fromV: 5, toV: 9
  57. },{
  58. project_ops: [{
  59. rename: {
  60. pathname: "main1.tex",
  61. newPathname: "main2.tex"
  62. }
  63. }],
  64. fromV: 4, toV: 4
  65. },{
  66. pathnames: ["main1.tex"]
  67. fromV: 3, toV: 3
  68. },{
  69. project_ops: [{
  70. rename: {
  71. pathname: "main0.tex",
  72. newPathname: "main1.tex"
  73. }
  74. }],
  75. fromV: 2, toV: 2
  76. },{
  77. pathnames: ["main0.tex"]
  78. fromV: 0, toV: 1
  79. }])
  80. expect(result).to.deep.equal({
  81. "main0.tex": { fromV: 0, toV: 9 }
  82. })
  83. it "should track single renames", ->
  84. result = @historyManager._perDocSummaryOfUpdates([{
  85. project_ops: [{
  86. rename: {
  87. pathname: "main1.tex",
  88. newPathname: "main2.tex"
  89. }
  90. }],
  91. fromV: 4, toV: 5
  92. }])
  93. expect(result).to.deep.equal({
  94. "main1.tex": { fromV: 4, toV: 5 }
  95. })
  96. it "should track additions", ->
  97. result = @historyManager._perDocSummaryOfUpdates([{
  98. project_ops: [{
  99. add:
  100. pathname: "main.tex"
  101. }]
  102. fromV: 0, toV: 1
  103. }, {
  104. pathnames: ["main.tex"]
  105. fromV: 1, toV: 4
  106. }])
  107. expect(result).to.deep.equal({
  108. "main.tex": { fromV: 0, toV: 4 }
  109. })
  110. it "should track single additions", ->
  111. result = @historyManager._perDocSummaryOfUpdates([{
  112. project_ops: [{
  113. add:
  114. pathname: "main.tex"
  115. }]
  116. fromV: 0, toV: 1
  117. }])
  118. expect(result).to.deep.equal({
  119. "main.tex": { fromV: 0, toV: 1 }
  120. })