Merge pull request #499 from sharelatex/ja-restore-files-fix

Fix doc open looping bug and tests for restoring files
This commit is contained in:
James Allen 2018-04-17 09:34:11 +01:00 committed by GitHub
commit 7364f607d0
3 changed files with 17 additions and 24 deletions

View file

@ -29,10 +29,11 @@ define [
do tryOpen = () -> do tryOpen = () ->
if iterations > 5 if iterations > 5
return return
iterations += 1
entity = ide.fileTreeManager.findEntityById(id) entity = ide.fileTreeManager.findEntityById(id)
if entity? and type == 'doc' if entity? and type == 'doc'
ide.editorManager.openDoc(entity) ide.editorManager.openDoc(entity)
if entity? and type == 'file' else if entity? and type == 'file'
ide.binaryFilesManager.openFile(entity) ide.binaryFilesManager.openFile(entity)
else else
setTimeout(tryOpen, 500) setTimeout(tryOpen, 500)

View file

@ -30,7 +30,7 @@ describe 'RestoreManager', ->
describe 'restoreFileFromV2', -> describe 'restoreFileFromV2', ->
beforeEach -> beforeEach ->
@RestoreManager._writeFileVersionToDisk = sinon.stub().yields(null, @fsPath = "/tmp/path/on/disk") @RestoreManager._writeFileVersionToDisk = sinon.stub().yields(null, @fsPath = "/tmp/path/on/disk")
@RestoreManager._findFolderOrRootFolderId = sinon.stub().yields(null, @folder_id = 'mock-folder-id') @RestoreManager._findOrCreateFolder = sinon.stub().yields(null, @folder_id = 'mock-folder-id')
@FileSystemImportManager.addEntity = sinon.stub().yields(null, @entity = 'mock-entity') @FileSystemImportManager.addEntity = sinon.stub().yields(null, @entity = 'mock-entity')
describe "with a file not in a folder", -> describe "with a file not in a folder", ->
@ -44,7 +44,7 @@ describe 'RestoreManager', ->
.should.equal true .should.equal true
it 'should find the root folder', -> it 'should find the root folder', ->
@RestoreManager._findFolderOrRootFolderId @RestoreManager._findOrCreateFolder
.calledWith(@project_id, "") .calledWith(@project_id, "")
.should.equal true .should.equal true
@ -62,7 +62,7 @@ describe 'RestoreManager', ->
@RestoreManager.restoreFileFromV2 @user_id, @project_id, @version, @pathname, @callback @RestoreManager.restoreFileFromV2 @user_id, @project_id, @version, @pathname, @callback
it 'should find the folder', -> it 'should find the folder', ->
@RestoreManager._findFolderOrRootFolderId @RestoreManager._findOrCreateFolder
.calledWith(@project_id, "foo") .calledWith(@project_id, "foo")
.should.equal true .should.equal true
@ -71,27 +71,19 @@ describe 'RestoreManager', ->
.calledWith(@user_id, @project_id, @folder_id, 'bar.tex', @fsPath, false) .calledWith(@user_id, @project_id, @folder_id, 'bar.tex', @fsPath, false)
.should.equal true .should.equal true
describe '_findFolderOrRootFolderId', -> describe '_findOrCreateFolder', ->
describe 'with a folder that exists', -> beforeEach ->
beforeEach -> @EditorController.mkdirp = sinon.stub().yields(null, [], {_id: @folder_id = 'mock-folder-id'})
@ProjectLocator.findElementByPath = sinon.stub().yields(null, {_id: @folder_id = 'mock-folder-id'}, 'folder') @RestoreManager._findOrCreateFolder @project_id, 'folder/name', @callback
@RestoreManager._findFolderOrRootFolderId @project_id, 'folder_name', @callback
it 'should look up the folder', -> it 'should look up or create the folder', ->
@ProjectLocator.findElementByPath @EditorController.mkdirp
.calledWith({project_id: @project_id, path: 'folder_name'}) .calledWith(@project_id, 'folder/name')
.should.equal true .should.equal true
it 'should return the folder_id', -> it 'should return the folder_id', ->
@callback.calledWith(null, @folder_id).should.equal true @callback.calledWith(null, @folder_id).should.equal true
describe "with a folder that doesn't exist", ->
beforeEach ->
@ProjectLocator.findElementByPath = sinon.stub().yields(new Errors.NotFoundError())
@RestoreManager._findFolderOrRootFolderId @project_id, 'folder_name', @callback
it 'should return null', ->
@callback.calledWith(null, null).should.equal true
describe '_addEntityWithUniqueName', -> describe '_addEntityWithUniqueName', ->
beforeEach -> beforeEach ->

View file

@ -130,7 +130,7 @@ define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) ->
project_ops: [{ project_ops: [{
remove: remove:
pathname: "main.tex" pathname: "main.tex"
atV: 2 atV: 2
}] }]
fromV: 1, toV: 2 fromV: 1, toV: 2
}]) }])
@ -144,7 +144,7 @@ define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) ->
project_ops: [{ project_ops: [{
remove: remove:
pathname: "main.tex" pathname: "main.tex"
atV: 1 atV: 1
}] }]
fromV: 0, toV: 1 fromV: 0, toV: 1
}]) }])