From daad82d05ac49f45198750baba96929ea7772e6b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 8 Apr 2021 15:48:32 -0500 Subject: [PATCH] test: run delete tests for both remove and remove-permanently --- spec/tree-view-package-spec.coffee | 546 +++++++++++++++-------------- 1 file changed, 274 insertions(+), 272 deletions(-) diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index 85a2233d..a8d6259a 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -2747,391 +2747,393 @@ describe "TreeView", -> atom.commands.dispatch(treeView.element, "tree-view:duplicate") expect(atom.workspace.getModalPanels().length).toBe(0) - describe "tree-view:remove", -> - beforeEach -> - jasmine.attachToDOM(workspaceElement) + for cmd in ["remove", "remove-permanently"] - it "won't remove the root directory", -> - spyOn(atom, 'confirm') - treeView.focus() - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - atom.commands.dispatch(treeView.element, 'tree-view:remove') + describe "tree-view:#{cmd}", -> + beforeEach -> + jasmine.attachToDOM(workspaceElement) - args = atom.confirm.mostRecentCall.args[0] - expect(args.buttons).toEqual ['OK'] + it "won't remove the root directory", -> + spyOn(atom, 'confirm') + treeView.focus() + root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - it "shows the native alert dialog", -> - spyOn(atom, 'confirm') + args = atom.confirm.mostRecentCall.args[0] + expect(args.buttons).toEqual ['OK'] - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + it "shows the native alert dialog", -> + spyOn(atom, 'confirm') - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:remove') - args = atom.confirm.mostRecentCall.args[0] - expect(args.buttons).toEqual ['Move to Trash', 'Cancel'] + waitForWorkspaceOpenEvent -> + fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - it "can delete an active path that isn't in the project", -> - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") + args = atom.confirm.mostRecentCall.args[0] + expect(args.buttons).toEqual ['Move to Trash', 'Cancel'] - filePath = path.join(os.tmpdir(), 'non-project-file.txt') - fs.writeFileSync(filePath, 'test') + it "can delete an active path that isn't in the project", -> + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitsForPromise -> - atom.workspace.open(filePath) + filePath = path.join(os.tmpdir(), 'non-project-file.txt') + fs.writeFileSync(filePath, 'test') - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:remove') + waitsForPromise -> + atom.workspace.open(filePath) - waitsFor 'onEntryDeleted to be called', -> - callback.callCount is 1 + runs -> + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(fs.existsSync(filePath)).toBe(false) + waitsFor 'onEntryDeleted to be called', -> + callback.callCount is 1 - it "shows a notification on failure", -> - atom.notifications.clear() + runs -> + expect(fs.existsSync(filePath)).toBe(false) - callback = jasmine.createSpy('onDeleteEntryFailed') - treeView.onDeleteEntryFailed(callback) + it "shows a notification on failure", -> + atom.notifications.clear() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + callback = jasmine.createSpy('onDeleteEntryFailed') + treeView.onDeleteEntryFailed(callback) - spyOn(shell, 'moveItemToTrash').andReturn(false) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(shell, 'moveItemToTrash').andReturn(false) + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'onDeleteEntryFailed to be called', -> - callback.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - notificationsNumber = atom.notifications.getNotifications().length - expect(notificationsNumber).toBe 1 - if notificationsNumber is 1 - notification = atom.notifications.getNotifications()[0] - expect(notification.getMessage()).toContain 'The following file couldn\'t be moved to the trash' - expect(notification.getDetail()).toContain 'test-file.txt' - - it "does nothing when no file is selected", -> - atom.notifications.clear() + waitsFor 'onDeleteEntryFailed to be called', -> + callback.callCount is 1 - spyOn(atom, 'confirm') + runs -> + notificationsNumber = atom.notifications.getNotifications().length + expect(notificationsNumber).toBe 1 + if notificationsNumber is 1 + notification = atom.notifications.getNotifications()[0] + expect(notification.getMessage()).toContain 'The following file couldn\'t be moved to the trash' + expect(notification.getDetail()).toContain 'test-file.txt' + + it "does nothing when no file is selected", -> + atom.notifications.clear() - treeView.focus() - treeView.deselect() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm') - expect(atom.confirm.mostRecentCall).not.toExist() - expect(atom.notifications.getNotifications().length).toBe 0 + treeView.focus() + treeView.deselect() + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - describe "when a directory is removed", -> - it "closes editors with filepaths belonging to the removed folder", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + expect(atom.confirm.mostRecentCall).not.toExist() + expect(atom.notifications.getNotifications().length).toBe 0 - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath2) + describe "when a directory is removed", -> + it "closes editors with filepaths belonging to the removed folder", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath3) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath2) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2, filePath3]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath3) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2, filePath3]) + dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'directory to be deleted', -> - callback.mostRecentCall.args[0].pathToDelete is dirPath2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([]) + waitsFor 'directory to be deleted', -> + callback.mostRecentCall.args[0].pathToDelete is dirPath2 - it "does not close modified editors with filepaths belonging to the removed folder", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([]) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath2) + it "does not close modified editors with filepaths belonging to the removed folder", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath3) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath2) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2, filePath3]) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath3) - atom.workspace.getActiveTextEditor().setText('MODIFIED') - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2, filePath3]) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + atom.workspace.getActiveTextEditor().setText('MODIFIED') + dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'directory to be deleted', -> - callback.mostRecentCall.args[0].pathToDelete is dirPath2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath3]) + waitsFor 'directory to be deleted', -> + callback.mostRecentCall.args[0].pathToDelete is dirPath2 - it "does not close editors with filepaths belonging to a folder that starts with the removed folder", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath3]) - dirPath20 = path.join(rootDirPath, 'test-dir20') - filePath20 = path.join(dirPath20, 'test-file20.txt') - fs.makeTreeSync(dirPath20) - fs.writeFileSync(filePath20, "doesn't matter 20") + it "does not close editors with filepaths belonging to a folder that starts with the removed folder", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath2) + dirPath20 = path.join(rootDirPath, 'test-dir20') + filePath20 = path.join(dirPath20, 'test-file20.txt') + fs.makeTreeSync(dirPath20) + fs.writeFileSync(filePath20, "doesn't matter 20") - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath3) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath2) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath20) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath3) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2, filePath3, filePath20]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath20) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2, filePath3, filePath20]) + dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'directory to be deleted', -> - callback.mostRecentCall.args[0].pathToDelete is dirPath2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath20]) + waitsFor 'directory to be deleted', -> + callback.mostRecentCall.args[0].pathToDelete is dirPath2 - it "does not error when Untitled editors are also open (regresssion)", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath20]) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath2) + it "does not error when Untitled editors are also open (regresssion)", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath3) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath2) - waitForWorkspaceOpenEvent -> - # Untitled editors (which have an undefined path) should not affect file deletion - # https://github.com/atom/atom/issues/16147 - atom.workspace.open() + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath3) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2, filePath3, undefined]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + waitForWorkspaceOpenEvent -> + # Untitled editors (which have an undefined path) should not affect file deletion + # https://github.com/atom/atom/issues/16147 + atom.workspace.open() - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2, filePath3, undefined]) + dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'directory to be deleted', -> - callback.mostRecentCall.args[0].pathToDelete is dirPath2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([undefined]) + waitsFor 'directory to be deleted', -> + callback.mostRecentCall.args[0].pathToDelete is dirPath2 - it "focuses the directory's parent folder", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([undefined]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + it "focuses the directory's parent folder", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'directory to be deleted', -> - callback.mostRecentCall.args[0].pathToDelete is dirPath2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(root1).toHaveClass('selected') + waitsFor 'directory to be deleted', -> + callback.mostRecentCall.args[0].pathToDelete is dirPath2 - describe "when a file is removed", -> - it "closes editors with filepaths belonging to the removed file", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + expect(root1).toHaveClass('selected') - waitsForPromise -> - atom.workspace.open(filePath2) + describe "when a file is removed", -> + it "closes editors with filepaths belonging to the removed file", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2]) - treeView.selectEntry(fileView2) - treeView.focus() + waitsForPromise -> + atom.workspace.open(filePath2) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2]) + treeView.selectEntry(fileView2) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'onEntryDeleted to be called', -> - callback.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([]) + waitsFor 'onEntryDeleted to be called', -> + callback.callCount is 1 - it "does not close editors that have been modified", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([]) - waitForWorkspaceOpenEvent -> - atom.workspace.open(filePath2) + it "does not close editors that have been modified", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2]) + waitForWorkspaceOpenEvent -> + atom.workspace.open(filePath2) - atom.workspace.getActiveTextEditor().setText('MODIFIED') - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2]) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + atom.workspace.getActiveTextEditor().setText('MODIFIED') + fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'onEntryDeleted to be called', -> - callback.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2]) + waitsFor 'onEntryDeleted to be called', -> + callback.callCount is 1 - it "does not close editors with filepaths that begin with the removed file", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2]) - filePath2Copy = path.join(dirPath2, 'test-file2.txt0') - fs.writeFileSync(filePath2Copy, "doesn't matter 2 copy") + it "does not close editors with filepaths that begin with the removed file", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - waitsForPromise -> - atom.workspace.open(filePath2Copy) + filePath2Copy = path.join(dirPath2, 'test-file2.txt0') + fs.writeFileSync(filePath2Copy, "doesn't matter 2 copy") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2Copy]) - treeView.selectEntry(fileView2) - treeView.focus() + waitsForPromise -> + atom.workspace.open(filePath2Copy) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2Copy]) + treeView.selectEntry(fileView2) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'onEntryDeleted to be called', -> - callback.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) - expect(openFilePaths).toEqual([filePath2Copy]) + waitsFor 'onEntryDeleted to be called', -> + callback.callCount is 1 - it "focuses the file's parent folder", -> - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + runs -> + openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) + expect(openFilePaths).toEqual([filePath2Copy]) - # Don't click so that we don't open an editor - # If an editor is opened, this test doesn't work as the editor will be removed, - # prompting selectActiveFile to unselect everything - treeView.selectEntry(fileView2) - treeView.focus() + it "focuses the file's parent folder", -> + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + # Don't click so that we don't open an editor + # If an editor is opened, this test doesn't work as the editor will be removed, + # prompting selectActiveFile to unselect everything + treeView.selectEntry(fileView2) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'onEntryDeleted to be called', -> - callback.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(dirView2).toHaveClass('selected') + waitsFor 'onEntryDeleted to be called', -> + callback.callCount is 1 - describe "when multiple files and folders are deleted", -> - it "does not error when the selected entries form a parent/child relationship", -> - # If dir1 and dir1/file1 are both selected for deletion, - # and dir1 is deleted first, do not error when attempting to delete dir1/file1 - atom.notifications.clear() + runs -> + expect(dirView2).toHaveClass('selected') - spyOn(fs, 'existsSync').andCallThrough() + describe "when multiple files and folders are deleted", -> + it "does not error when the selected entries form a parent/child relationship", -> + # If dir1 and dir1/file1 are both selected for deletion, + # and dir1 is deleted first, do not error when attempting to delete dir1/file1 + atom.notifications.clear() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - dirView.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) - treeView.focus() + spyOn(fs, 'existsSync').andCallThrough() - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + dirView.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'dir1/file1 to attempt to be deleted', -> - fs.existsSync.mostRecentCall.args[0] is filePath + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(atom.notifications.getNotifications().length).toBe 0 + waitsFor 'dir1/file1 to attempt to be deleted', -> + fs.existsSync.mostRecentCall.args[0] is filePath - it "focuses the first selected entry's parent folder", -> - jasmine.attachToDOM(workspaceElement) + runs -> + expect(atom.notifications.getNotifications().length).toBe 0 - callback = jasmine.createSpy('onEntryDeleted') - treeView.onEntryDeleted(callback) + it "focuses the first selected entry's parent folder", -> + jasmine.attachToDOM(workspaceElement) - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - fileView2.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) - treeView.focus() + callback = jasmine.createSpy('onEntryDeleted') + treeView.onEntryDeleted(callback) - spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) + dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + fileView2.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) - waitsFor 'all selected entries to be deleted', -> - callback.callCount is 2 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(root1).toHaveClass('selected') + waitsFor 'all selected entries to be deleted', -> + callback.callCount is 2 - describe "when the entry is deleted before 'Move to Trash' is selected", -> - it "does not error", -> - # If the file is marked for deletion but has already been deleted - # outside of Atom by the time the deletion is confirmed, do not error - atom.notifications.clear() + runs -> + expect(root1).toHaveClass('selected') - spyOn(fs, 'existsSync').andCallThrough() + describe "when the entry is deleted before 'Move to Trash' is selected", -> + it "does not error", -> + # If the file is marked for deletion but has already been deleted + # outside of Atom by the time the deletion is confirmed, do not error + atom.notifications.clear() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.focus() + spyOn(fs, 'existsSync').andCallThrough() - spyOn(atom, 'confirm').andCallFake (options, callback) -> - # Remove the directory before confirming the deletion - fs.unlinkSync(filePath) - callback(0) + fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.focus() - atom.commands.dispatch(treeView.element, 'tree-view:remove') + spyOn(atom, 'confirm').andCallFake (options, callback) -> + # Remove the directory before confirming the deletion + fs.unlinkSync(filePath) + callback(0) - waitsFor 'the entry to attempt to be deleted', -> - fs.existsSync.callCount is 1 + atom.commands.dispatch(treeView.element, "tree-view:#{cmd}") - runs -> - expect(atom.notifications.getNotifications().length).toBe 0 + waitsFor 'the entry to attempt to be deleted', -> + fs.existsSync.callCount is 1 + + runs -> + expect(atom.notifications.getNotifications().length).toBe 0 describe "file system events", -> temporaryFilePath = null