mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add some front end tests for HistoryManager
This commit is contained in:
parent
4691a6e85c
commit
8ea779af58
8 changed files with 130 additions and 40 deletions
1
services/web/.gitignore
vendored
1
services/web/.gitignore
vendored
|
@ -39,6 +39,7 @@ data/*
|
|||
app.js
|
||||
app/js/*
|
||||
test/unit/js/*
|
||||
test/unit_frontend/js/*
|
||||
test/smoke/js/*
|
||||
test/acceptance/js/*
|
||||
cookies.txt
|
||||
|
|
5
services/web/bin/compile_frontend
Executable file
5
services/web/bin/compile_frontend
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e;
|
||||
COFFEE=node_modules/.bin/coffee
|
||||
echo Compiling public/coffee;
|
||||
$COFFEE -o public/js -c public/coffee;
|
5
services/web/bin/compile_frontend_unit_tests
Executable file
5
services/web/bin/compile_frontend_unit_tests
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e;
|
||||
COFFEE=node_modules/.bin/coffee
|
||||
echo Compiling test/unit_frontend/coffee;
|
||||
$COFFEE -o test/unit_frontend/js -c test/unit_frontend/coffee;
|
5
services/web/bin/frontend_unit_test
Executable file
5
services/web/bin/frontend_unit_test
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e;
|
||||
MOCHA="node_modules/.bin/mocha --recursive --reporter spec"
|
||||
$MOCHA "$@" test/unit_frontend/js
|
||||
|
|
@ -14,11 +14,15 @@
|
|||
"test:acceptance:run": "bin/acceptance_test $@",
|
||||
"test:acceptance:dir": "npm -q run compile:acceptance_tests && npm -q run test:acceptance:wait_for_app && npm -q run test:acceptance:run -- $@",
|
||||
"test:acceptance": "npm -q run test:acceptance:dir -- $@ test/acceptance/js",
|
||||
"test:unit": "npm -q run compile:app && npm -q run compile:unit_tests && bin/unit_test $@",
|
||||
"test:unit": "npm -q run compile:backend && npm -q run compile:unit_tests && bin/unit_test $@",
|
||||
"test:frontend_unit": "npm -q run compile:frontend && npm -q run compile:frontend_unit_tests && bin/frontend_unit_test $@",
|
||||
"compile:unit_tests": "bin/compile_unit_tests",
|
||||
"compile:frontend_unit_tests": "bin/compile_frontend_unit_tests",
|
||||
"compile:acceptance_tests": "bin/compile_acceptance_tests",
|
||||
"compile:app": "bin/compile_app",
|
||||
"start": "npm -q run compile:app && node app.js"
|
||||
"compile:frontend": "bin/compile_frontend",
|
||||
"compile:backend": "bin/compile_backend",
|
||||
"compile": "npm -q run compile:backend && npm -q run compile:frontend",
|
||||
"start": "npm -q run compile && node app.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"archiver": "0.9.0",
|
||||
|
|
|
@ -191,13 +191,9 @@ define [
|
|||
return {text, highlights}
|
||||
|
||||
_loadUpdates: (updates = []) ->
|
||||
console.log "FOO"
|
||||
previousUpdate = @$scope.history.updates[@$scope.history.updates.length - 1]
|
||||
console.log "BAR", updates
|
||||
|
||||
for update in updates or []
|
||||
console.log "_loadUpdates, loading", update
|
||||
|
||||
for user in update.meta.users or []
|
||||
if user?
|
||||
user.hue = ColorManager.getHueForUserId(user.id)
|
||||
|
@ -211,50 +207,41 @@ define [
|
|||
|
||||
previousUpdate = update
|
||||
|
||||
console.log("BAZ")
|
||||
firstLoad = @$scope.history.updates.length == 0
|
||||
|
||||
@$scope.history.updates =
|
||||
@$scope.history.updates.concat(updates)
|
||||
console.log "[_loadUpdates] updates", @$scope.history.updates
|
||||
|
||||
@autoSelectRecentUpdates() if firstLoad
|
||||
|
||||
_perDocSummaryOfUpdates: (updates) ->
|
||||
current_pathnames = {}
|
||||
# Track current_pathname -> original_pathname
|
||||
original_pathnames = {}
|
||||
docs_summary = {}
|
||||
|
||||
for update in updates # Updates are reverse chronologically ordered
|
||||
console.log "[_perDocSummaryOfUpdates] update", update
|
||||
# Put updates in ascending chronological order
|
||||
updates = updates.slice().reverse()
|
||||
for update in updates
|
||||
for pathname in update.docs or []
|
||||
# current_pathname may not be the latest doc path that this doc has had
|
||||
if !current_pathnames[pathname]?
|
||||
current_pathnames[pathname] = pathname
|
||||
current_pathname = current_pathnames[pathname]
|
||||
if !docs_summary[current_pathname]?
|
||||
docs_summary[current_pathname] = {
|
||||
if !original_pathnames[pathname]?
|
||||
original_pathnames[pathname] = pathname
|
||||
original_pathname = original_pathnames[pathname]
|
||||
if !docs_summary[original_pathname]?
|
||||
docs_summary[original_pathname] = {
|
||||
fromV: update.fromV, toV: update.toV,
|
||||
pathname: pathname
|
||||
}
|
||||
console.log "[_perDocSummaryOfUpdates] creating summary", current_pathname, docs_summary[current_pathname]
|
||||
else
|
||||
console.log "[_perDocSummaryOfUpdates] updating summary", docs_summary[current_pathname], update
|
||||
docs_summary[current_pathname] = {
|
||||
fromV: Math.min(docs_summary[current_pathname].fromV, update.fromV),
|
||||
toV: Math.max(docs_summary[current_pathname].toV, update.toV),
|
||||
pathname: pathname
|
||||
docs_summary[original_pathname] = {
|
||||
fromV: Math.min(docs_summary[original_pathname].fromV, update.fromV),
|
||||
toV: Math.max(docs_summary[original_pathname].toV, update.toV),
|
||||
}
|
||||
for project_op in update.project_ops or []
|
||||
if project_op.rename?
|
||||
rename = project_op.rename
|
||||
console.log "[_perDocSummaryOfUpdates] rename", rename
|
||||
if !current_pathnames[rename.newPathname]?
|
||||
current_pathnames[rename.newPathname] = rename.newPathname
|
||||
current_pathnames[rename.current_pathname] = current_pathnames[rename.newPathname]
|
||||
delete current_pathnames[rename.newPathname]
|
||||
|
||||
console.log "[_perDocSummaryOfUpdates] docs_summary", docs_summary
|
||||
console.log "[_perDocSummaryOfUpdates] current_pathnames", current_pathnames
|
||||
if !original_pathnames[rename.pathname]?
|
||||
original_pathnames[rename.pathname] = rename.pathname
|
||||
original_pathnames[rename.newPathname] = original_pathnames[rename.pathname]
|
||||
delete original_pathnames[rename.pathname]
|
||||
|
||||
return docs_summary
|
||||
|
||||
|
@ -262,12 +249,10 @@ define [
|
|||
fromV = toV = pathname = null
|
||||
|
||||
selected_pathname = @$scope.history.selection.pathname
|
||||
console.log "[_calculateDiffDataFromSelection] selected_pathname", selected_pathname
|
||||
|
||||
for pathname, doc of @_perDocSummaryOfUpdates(@$scope.history.selection.updates)
|
||||
console.log "[_calculateDiffDataFromSelection] pathname, doc", pathname, doc
|
||||
if pathname == selected_pathname
|
||||
{fromV, toV, pathname} = doc
|
||||
{fromV, toV} = doc
|
||||
break
|
||||
|
||||
return {fromV, toV, pathname}
|
||||
|
@ -277,10 +262,8 @@ define [
|
|||
# then prefer this one if present.
|
||||
_selectDocFromUpdates: () ->
|
||||
affected_docs = @_perDocSummaryOfUpdates(@$scope.history.selection.updates)
|
||||
console.log "[_selectDocFromUpdates] affected_docs", affected_docs
|
||||
|
||||
selected_pathname = @$scope.history.selection.pathname
|
||||
console.log "[_selectDocFromUpdates] current selected_pathname", selected_pathname
|
||||
if selected_pathname? and affected_docs[selected_pathname]
|
||||
# Selected doc is already open
|
||||
else
|
||||
|
@ -289,8 +272,6 @@ define [
|
|||
selected_pathname = pathname
|
||||
break
|
||||
|
||||
console.log "[_selectDocFromUpdates] new selected_pathname", selected_pathname
|
||||
|
||||
@$scope.history.selection.pathname = selected_pathname
|
||||
if selected_pathname?
|
||||
entity = @ide.fileTreeManager.findEntityByPath(selected_pathname)
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
Path = require 'path'
|
||||
SandboxedModule = require "sandboxed-module"
|
||||
modulePath = Path.join __dirname, '../../../public/js/ide/history/HistoryManager'
|
||||
sinon = require("sinon")
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "HistoryManager", ->
|
||||
beforeEach ->
|
||||
@moment = {}
|
||||
@ColorManager = {}
|
||||
SandboxedModule.require modulePath, globals:
|
||||
"define": (dependencies, builder) =>
|
||||
@HistoryManager = builder(@moment, @ColorManager)
|
||||
|
||||
@scope =
|
||||
$watch: sinon.stub()
|
||||
$on: sinon.stub()
|
||||
@ide = {}
|
||||
|
||||
@historyManager = new @HistoryManager(@ide, @scope)
|
||||
|
||||
it "should setup the history scope on intialization", ->
|
||||
expect(@scope.history).to.deep.equal({
|
||||
updates: []
|
||||
nextBeforeTimestamp: null
|
||||
atEnd: false
|
||||
selection: {
|
||||
updates: []
|
||||
doc: null
|
||||
range: {
|
||||
fromV: null
|
||||
toV: null
|
||||
}
|
||||
}
|
||||
diff: null
|
||||
})
|
||||
|
||||
describe "_perDocSummaryOfUpdates", ->
|
||||
it "should return the range of updates for the docs", ->
|
||||
result = @historyManager._perDocSummaryOfUpdates([{
|
||||
docs: ["main.tex"]
|
||||
fromV: 7, toV: 9
|
||||
},{
|
||||
docs: ["main.tex", "foo.tex"]
|
||||
fromV: 4, toV: 6
|
||||
},{
|
||||
docs: ["main.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
docs: ["foo.tex"]
|
||||
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([{
|
||||
docs: ["main2.tex"]
|
||||
fromV: 5, toV: 9
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main1.tex",
|
||||
newPathname: "main2.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 4, toV: 4
|
||||
},{
|
||||
docs: ["main1.tex"]
|
||||
fromV: 3, toV: 3
|
||||
},{
|
||||
project_ops: [{
|
||||
rename: {
|
||||
pathname: "main0.tex",
|
||||
newPathname: "main1.tex"
|
||||
}
|
||||
}],
|
||||
fromV: 2, toV: 2
|
||||
},{
|
||||
docs: ["main0.tex"]
|
||||
fromV: 0, toV: 1
|
||||
}])
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
"main0.tex": { fromV: 0, toV: 9 }
|
||||
})
|
Loading…
Reference in a new issue