2017-12-07 06:21:49 -05:00
|
|
|
Path = require 'path'
|
|
|
|
SandboxedModule = require "sandboxed-module"
|
2017-12-13 11:11:12 -05:00
|
|
|
modulePath = Path.join __dirname, '../../../public/js/ide/history/HistoryV2Manager'
|
2017-12-07 06:21:49 -05:00
|
|
|
sinon = require("sinon")
|
|
|
|
expect = require("chai").expect
|
|
|
|
|
2017-12-13 11:11:12 -05:00
|
|
|
describe "HistoryV2Manager", ->
|
2017-12-07 06:21:49 -05:00
|
|
|
beforeEach ->
|
|
|
|
@moment = {}
|
|
|
|
@ColorManager = {}
|
|
|
|
SandboxedModule.require modulePath, globals:
|
|
|
|
"define": (dependencies, builder) =>
|
2017-12-13 11:11:12 -05:00
|
|
|
@HistoryV2Manager = builder(@moment, @ColorManager)
|
2017-12-07 06:21:49 -05:00
|
|
|
|
|
|
|
@scope =
|
|
|
|
$watch: sinon.stub()
|
|
|
|
$on: sinon.stub()
|
|
|
|
@ide = {}
|
|
|
|
|
2017-12-13 11:11:12 -05:00
|
|
|
@historyManager = new @HistoryV2Manager(@ide, @scope)
|
2017-12-07 06:21:49 -05:00
|
|
|
|
|
|
|
it "should setup the history scope on intialization", ->
|
|
|
|
expect(@scope.history).to.deep.equal({
|
2017-12-13 11:48:48 -05:00
|
|
|
isV2: true
|
2017-12-07 06:21:49 -05:00
|
|
|
updates: []
|
|
|
|
nextBeforeTimestamp: null
|
|
|
|
atEnd: false
|
|
|
|
selection: {
|
|
|
|
updates: []
|
2017-12-14 05:18:17 -05:00
|
|
|
pathname: null
|
2017-12-20 10:08:45 -05:00
|
|
|
docs: {}
|
2017-12-07 06:21:49 -05:00
|
|
|
range: {
|
|
|
|
fromV: null
|
|
|
|
toV: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
diff: null
|
|
|
|
})
|
|
|
|
|
|
|
|
describe "_perDocSummaryOfUpdates", ->
|
|
|
|
it "should return the range of updates for the docs", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 7, toV: 9
|
|
|
|
},{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main.tex", "foo.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 4, toV: 6
|
|
|
|
},{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 3, toV: 3
|
|
|
|
},{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["foo.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 0, toV: 2
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main.tex": { fromV: 3, toV: 9 },
|
|
|
|
"foo.tex": { fromV: 0, toV: 6 }
|
|
|
|
})
|
|
|
|
|
|
|
|
it "should track renames", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main2.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 5, toV: 9
|
|
|
|
},{
|
|
|
|
project_ops: [{
|
|
|
|
rename: {
|
|
|
|
pathname: "main1.tex",
|
|
|
|
newPathname: "main2.tex"
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
fromV: 4, toV: 4
|
|
|
|
},{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main1.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 3, toV: 3
|
|
|
|
},{
|
|
|
|
project_ops: [{
|
|
|
|
rename: {
|
|
|
|
pathname: "main0.tex",
|
|
|
|
newPathname: "main1.tex"
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
fromV: 2, toV: 2
|
|
|
|
},{
|
2017-12-13 11:11:12 -05:00
|
|
|
pathnames: ["main0.tex"]
|
2017-12-07 06:21:49 -05:00
|
|
|
fromV: 0, toV: 1
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main0.tex": { fromV: 0, toV: 9 }
|
|
|
|
})
|
2017-12-13 11:11:12 -05:00
|
|
|
|
|
|
|
it "should track single renames", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
|
|
|
project_ops: [{
|
|
|
|
rename: {
|
|
|
|
pathname: "main1.tex",
|
|
|
|
newPathname: "main2.tex"
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
fromV: 4, toV: 5
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main1.tex": { fromV: 4, toV: 5 }
|
|
|
|
})
|
|
|
|
|
|
|
|
it "should track additions", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
|
|
|
project_ops: [{
|
|
|
|
add:
|
|
|
|
pathname: "main.tex"
|
|
|
|
}]
|
|
|
|
fromV: 0, toV: 1
|
|
|
|
}, {
|
|
|
|
pathnames: ["main.tex"]
|
|
|
|
fromV: 1, toV: 4
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main.tex": { fromV: 0, toV: 4 }
|
|
|
|
})
|
|
|
|
|
|
|
|
it "should track single additions", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
|
|
|
project_ops: [{
|
|
|
|
add:
|
|
|
|
pathname: "main.tex"
|
|
|
|
}]
|
|
|
|
fromV: 0, toV: 1
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main.tex": { fromV: 0, toV: 1 }
|
|
|
|
})
|
2017-12-20 10:08:45 -05:00
|
|
|
|
|
|
|
it "should track deletions", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
|
|
|
pathnames: ["main.tex"]
|
|
|
|
fromV: 0, toV: 1
|
|
|
|
}, {
|
|
|
|
project_ops: [{
|
|
|
|
remove:
|
|
|
|
pathname: "main.tex"
|
|
|
|
}]
|
|
|
|
fromV: 1, toV: 2
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main.tex": { fromV: 0, toV: 2, deleted: true }
|
|
|
|
})
|
|
|
|
|
|
|
|
it "should track single deletions", ->
|
|
|
|
result = @historyManager._perDocSummaryOfUpdates([{
|
|
|
|
project_ops: [{
|
|
|
|
remove:
|
|
|
|
pathname: "main.tex"
|
|
|
|
}]
|
|
|
|
fromV: 0, toV: 1
|
|
|
|
}])
|
|
|
|
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
"main.tex": { fromV: 0, toV: 1, deleted: true }
|
|
|
|
})
|