From d1b68ddf7cfcb3e7b81334b6d419ee915f5c76c8 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 16 Apr 2018 16:27:24 +0100 Subject: [PATCH 1/3] Fix RestoreManager unit tests --- .../coffee/History/RestoreManagerTests.coffee | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/services/web/test/unit/coffee/History/RestoreManagerTests.coffee b/services/web/test/unit/coffee/History/RestoreManagerTests.coffee index b15cdab946..37fe6752e7 100644 --- a/services/web/test/unit/coffee/History/RestoreManagerTests.coffee +++ b/services/web/test/unit/coffee/History/RestoreManagerTests.coffee @@ -30,7 +30,7 @@ describe 'RestoreManager', -> describe 'restoreFileFromV2', -> beforeEach -> @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') describe "with a file not in a folder", -> @@ -44,7 +44,7 @@ describe 'RestoreManager', -> .should.equal true it 'should find the root folder', -> - @RestoreManager._findFolderOrRootFolderId + @RestoreManager._findOrCreateFolder .calledWith(@project_id, "") .should.equal true @@ -62,7 +62,7 @@ describe 'RestoreManager', -> @RestoreManager.restoreFileFromV2 @user_id, @project_id, @version, @pathname, @callback it 'should find the folder', -> - @RestoreManager._findFolderOrRootFolderId + @RestoreManager._findOrCreateFolder .calledWith(@project_id, "foo") .should.equal true @@ -71,27 +71,19 @@ describe 'RestoreManager', -> .calledWith(@user_id, @project_id, @folder_id, 'bar.tex', @fsPath, false) .should.equal true - describe '_findFolderOrRootFolderId', -> - describe 'with a folder that exists', -> - beforeEach -> - @ProjectLocator.findElementByPath = sinon.stub().yields(null, {_id: @folder_id = 'mock-folder-id'}, 'folder') - @RestoreManager._findFolderOrRootFolderId @project_id, 'folder_name', @callback + describe '_findOrCreateFolder', -> + beforeEach -> + @EditorController.mkdirp = sinon.stub().yields(null, [], {_id: @folder_id = 'mock-folder-id'}) + @RestoreManager._findOrCreateFolder @project_id, 'folder/name', @callback - it 'should look up the folder', -> - @ProjectLocator.findElementByPath - .calledWith({project_id: @project_id, path: 'folder_name'}) - .should.equal true + it 'should look up or create the folder', -> + @EditorController.mkdirp + .calledWith(@project_id, 'folder/name') + .should.equal true - it 'should return the folder_id', -> - @callback.calledWith(null, @folder_id).should.equal true + it 'should return the folder_id', -> + @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', -> beforeEach -> From d6605610f5b92303daf94cd58c76c6989d9e4310 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 16 Apr 2018 16:31:49 +0100 Subject: [PATCH 2/3] Fix HistoryV2Manager front end tests --- .../coffee/ide/history/HistoryV2ManagerTests.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/web/test/unit_frontend/coffee/ide/history/HistoryV2ManagerTests.coffee b/services/web/test/unit_frontend/coffee/ide/history/HistoryV2ManagerTests.coffee index 9d0e103e0c..7f98de7fc9 100644 --- a/services/web/test/unit_frontend/coffee/ide/history/HistoryV2ManagerTests.coffee +++ b/services/web/test/unit_frontend/coffee/ide/history/HistoryV2ManagerTests.coffee @@ -130,7 +130,7 @@ define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) -> project_ops: [{ remove: pathname: "main.tex" - atV: 2 + atV: 2 }] fromV: 1, toV: 2 }]) @@ -144,7 +144,7 @@ define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) -> project_ops: [{ remove: pathname: "main.tex" - atV: 1 + atV: 1 }] fromV: 0, toV: 1 }]) From 87cc08569a850520ee38992b90073f4fd3921d65 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 16 Apr 2018 17:03:18 +0100 Subject: [PATCH 3/3] Fix bad if statement sending doc open into infinite loop --- .../ide/history/controllers/HistoryV2DiffController.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee index 89cf3975ec..c2ced4cf59 100644 --- a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee +++ b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee @@ -29,10 +29,11 @@ define [ do tryOpen = () -> if iterations > 5 return + iterations += 1 entity = ide.fileTreeManager.findEntityById(id) if entity? and type == 'doc' ide.editorManager.openDoc(entity) - if entity? and type == 'file' + else if entity? and type == 'file' ide.binaryFilesManager.openFile(entity) else setTimeout(tryOpen, 500)