mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Convert existing frontend tests to run in karma
This commit is contained in:
parent
3faa0556e8
commit
c7957b8ad4
2 changed files with 189 additions and 210 deletions
|
@ -1,164 +1,152 @@
|
|||
Path = require 'path'
|
||||
SandboxedModule = require "sandboxed-module"
|
||||
modulePath = Path.join __dirname, '../../../../../public/js/ide/history/HistoryV2Manager'
|
||||
sinon = require("sinon")
|
||||
expect = require("chai").expect
|
||||
define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) ->
|
||||
describe "HistoryV2Manager", ->
|
||||
beforeEach ->
|
||||
@scope =
|
||||
$watch: sinon.stub()
|
||||
$on: sinon.stub()
|
||||
@ide = {}
|
||||
@historyManager = new HistoryV2Manager(@ide, @scope)
|
||||
|
||||
describe "HistoryV2Manager", ->
|
||||
beforeEach ->
|
||||
@moment = {}
|
||||
@ColorManager = {}
|
||||
SandboxedModule.require modulePath, globals:
|
||||
"define": (dependencies, builder) =>
|
||||
@HistoryV2Manager = builder(@moment, @ColorManager)
|
||||
|
||||
@scope =
|
||||
$watch: sinon.stub()
|
||||
$on: sinon.stub()
|
||||
@ide = {}
|
||||
|
||||
@historyManager = new @HistoryV2Manager(@ide, @scope)
|
||||
|
||||
it "should setup the history scope on intialization", ->
|
||||
expect(@scope.history).to.deep.equal({
|
||||
isV2: true
|
||||
updates: []
|
||||
nextBeforeTimestamp: null
|
||||
atEnd: false
|
||||
selection: {
|
||||
it "should setup the history scope on intialization", ->
|
||||
expect(@scope.history).to.deep.equal({
|
||||
isV2: true
|
||||
updates: []
|
||||
pathname: null
|
||||
docs: {}
|
||||
range: {
|
||||
fromV: null
|
||||
toV: null
|
||||
nextBeforeTimestamp: null
|
||||
atEnd: false
|
||||
selection: {
|
||||
updates: []
|
||||
pathname: null
|
||||
docs: {}
|
||||
range: {
|
||||
fromV: null
|
||||
toV: null
|
||||
}
|
||||
}
|
||||
}
|
||||
diff: null
|
||||
})
|
||||
|
||||
describe "_perDocSummaryOfUpdates", ->
|
||||
it "should return the range of updates for the docs", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 7, toV: 9
|
||||
},{
|
||||
pathnames: ["main.tex", "foo.tex"]
|
||||
fromV: 4, toV: 6
|
||||
},{
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
pathnames: ["foo.tex"]
|
||||
fromV: 0, toV: 2
|
||||
}])
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
"main.tex": { fromV: 3, toV: 9 },
|
||||
"foo.tex": { fromV: 0, toV: 6 }
|
||||
diff: null
|
||||
})
|
||||
|
||||
it "should track renames", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
pathnames: ["main2.tex"]
|
||||
fromV: 5, toV: 9
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main1.tex",
|
||||
newPathname: "main2.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 4, toV: 4
|
||||
},{
|
||||
pathnames: ["main1.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main0.tex",
|
||||
newPathname: "main1.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 2, toV: 2
|
||||
},{
|
||||
pathnames: ["main0.tex"]
|
||||
fromV: 0, toV: 1
|
||||
}])
|
||||
describe "_perDocSummaryOfUpdates", ->
|
||||
it "should return the range of updates for the docs", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 7, toV: 9
|
||||
},{
|
||||
pathnames: ["main.tex", "foo.tex"]
|
||||
fromV: 4, toV: 6
|
||||
},{
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
pathnames: ["foo.tex"]
|
||||
fromV: 0, toV: 2
|
||||
}])
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
"main0.tex": { fromV: 0, toV: 9 }
|
||||
})
|
||||
expect(result).to.deep.equal({
|
||||
"main.tex": { fromV: 3, toV: 9 },
|
||||
"foo.tex": { fromV: 0, toV: 6 }
|
||||
})
|
||||
|
||||
it "should track single renames", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main1.tex",
|
||||
newPathname: "main2.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 4, toV: 5
|
||||
}])
|
||||
it "should track renames", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
pathnames: ["main2.tex"]
|
||||
fromV: 5, toV: 9
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main1.tex",
|
||||
newPathname: "main2.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 4, toV: 4
|
||||
},{
|
||||
pathnames: ["main1.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main0.tex",
|
||||
newPathname: "main1.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 2, toV: 2
|
||||
},{
|
||||
pathnames: ["main0.tex"]
|
||||
fromV: 0, toV: 1
|
||||
}])
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
"main1.tex": { fromV: 4, toV: 5 }
|
||||
})
|
||||
expect(result).to.deep.equal({
|
||||
"main0.tex": { fromV: 0, toV: 9 }
|
||||
})
|
||||
|
||||
it "should track additions", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
project_ops: [{
|
||||
add:
|
||||
pathname: "main.tex"
|
||||
}]
|
||||
fromV: 0, toV: 1
|
||||
}, {
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 1, toV: 4
|
||||
}])
|
||||
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({
|
||||
"main.tex": { fromV: 0, toV: 4 }
|
||||
})
|
||||
expect(result).to.deep.equal({
|
||||
"main1.tex": { fromV: 4, toV: 5 }
|
||||
})
|
||||
|
||||
it "should track single additions", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
project_ops: [{
|
||||
add:
|
||||
pathname: "main.tex"
|
||||
}]
|
||||
fromV: 0, toV: 1
|
||||
}])
|
||||
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: 1 }
|
||||
})
|
||||
expect(result).to.deep.equal({
|
||||
"main.tex": { fromV: 0, toV: 4 }
|
||||
})
|
||||
|
||||
it "should track deletions", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
pathnames: ["main.tex"]
|
||||
fromV: 0, toV: 1
|
||||
}, {
|
||||
project_ops: [{
|
||||
remove:
|
||||
pathname: "main.tex"
|
||||
}]
|
||||
fromV: 1, toV: 2
|
||||
}])
|
||||
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: 2, deleted: true }
|
||||
})
|
||||
expect(result).to.deep.equal({
|
||||
"main.tex": { fromV: 0, toV: 1 }
|
||||
})
|
||||
|
||||
it "should track single deletions", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
project_ops: [{
|
||||
remove:
|
||||
pathname: "main.tex"
|
||||
}]
|
||||
fromV: 0, toV: 1
|
||||
}])
|
||||
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: 1, deleted: true }
|
||||
})
|
||||
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 }
|
||||
})
|
||||
|
|
|
@ -1,68 +1,59 @@
|
|||
Path = require 'path'
|
||||
SandboxedModule = require "sandboxed-module"
|
||||
modulePath = Path.join __dirname, '../../../../../public/js/ide/history/util/displayNameForUser'
|
||||
sinon = require("sinon")
|
||||
expect = require("chai").expect
|
||||
define ['ide/history/util/displayNameForUser'], (displayNameForUser) ->
|
||||
describe "displayNameForUser", ->
|
||||
beforeEach ->
|
||||
window.user = { id: 42 }
|
||||
|
||||
describe "displayNameForUser", ->
|
||||
beforeEach ->
|
||||
SandboxedModule.require modulePath, globals:
|
||||
"define": (dependencies, builder) =>
|
||||
@displayNameForUser = builder()
|
||||
"window": @window = {}
|
||||
@window.user = { id: 42 }
|
||||
it "should return 'Anonymous' with no user", ->
|
||||
expect(
|
||||
displayNameForUser(null)
|
||||
).to.equal "Anonymous"
|
||||
|
||||
it "should return 'Anonymous' with no user", ->
|
||||
expect(
|
||||
@displayNameForUser(null)
|
||||
).to.equal "Anonymous"
|
||||
it "should return 'you' when the user has the same id as the window", ->
|
||||
expect(
|
||||
displayNameForUser({
|
||||
id: window.user.id
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: "Allen"
|
||||
})
|
||||
).to.equal "you"
|
||||
|
||||
it "should return 'you' when the user has the same id as the window", ->
|
||||
expect(
|
||||
@displayNameForUser({
|
||||
id: @window.user.id
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: "Allen"
|
||||
})
|
||||
).to.equal "you"
|
||||
it "should return the first_name and last_name when present", ->
|
||||
expect(
|
||||
displayNameForUser({
|
||||
id: window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: "Allen"
|
||||
})
|
||||
).to.equal "James Allen"
|
||||
|
||||
it "should return the first_name and last_name when present", ->
|
||||
expect(
|
||||
@displayNameForUser({
|
||||
id: @window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: "Allen"
|
||||
})
|
||||
).to.equal "James Allen"
|
||||
it "should return only the firstAname if no last_name", ->
|
||||
expect(
|
||||
displayNameForUser({
|
||||
id: window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "James"
|
||||
|
||||
it "should return only the firstAname if no last_name", ->
|
||||
expect(
|
||||
@displayNameForUser({
|
||||
id: @window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: "James"
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "James"
|
||||
it "should return the email username if there are no names", ->
|
||||
expect(
|
||||
displayNameForUser({
|
||||
id: window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: ""
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "james.allen"
|
||||
|
||||
it "should return the email username if there are no names", ->
|
||||
expect(
|
||||
@displayNameForUser({
|
||||
id: @window.user.id + 1
|
||||
email: "james.allen@overleaf.com"
|
||||
first_name: ""
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "james.allen"
|
||||
|
||||
it "should return the '?' if it has nothing", ->
|
||||
expect(
|
||||
@displayNameForUser({
|
||||
id: @window.user.id + 1
|
||||
email: ""
|
||||
first_name: ""
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "?"
|
||||
it "should return the '?' if it has nothing", ->
|
||||
expect(
|
||||
displayNameForUser({
|
||||
id: window.user.id + 1
|
||||
email: ""
|
||||
first_name: ""
|
||||
last_name: ""
|
||||
})
|
||||
).to.equal "?"
|
||||
|
|
Loading…
Reference in a new issue