diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index 7c285d68..0214dd53 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -102,7 +102,8 @@ describe "TreeView", -> beforeEach -> atom.project.setPaths([]) waitsForPromise -> - Promise.resolve(atom.packages.deactivatePackage("tree-view")) # Wrapped for both async and non-async versions of Atom + atom.packages.deactivatePackage("tree-view") + runs -> expect(atom.workspace.getLeftDock().getActivePaneItem()).toBeUndefined() @@ -159,7 +160,7 @@ describe "TreeView", -> it "does not show the dock on activation", -> waitsForPromise -> - Promise.resolve(atom.packages.deactivatePackage("tree-view")) # Wrapped for both async and non-async versions of Atom + atom.packages.deactivatePackage("tree-view") runs -> atom.packages.packageStates = {} @@ -196,7 +197,7 @@ describe "TreeView", -> atom.project.setPaths([dotGit]) waitsForPromise -> - Promise.resolve(atom.packages.deactivatePackage("tree-view")) # Wrapped for both async and non-async versions of Atom + atom.packages.deactivatePackage("tree-view") runs -> atom.packages.packageStates = {} @@ -623,7 +624,7 @@ describe "TreeView", -> treeView.focus() waitForWorkspaceOpenEvent -> - r = sampleJs.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + sampleJs.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) runs -> activePaneItem = atom.workspace.getCenter().getActivePaneItem() @@ -780,16 +781,14 @@ describe "TreeView", -> atom.workspace.open(atom.project.getDirectories()[0].resolve('tree-view.txt')) runs -> - expect(sampleTxt).toHaveClass 'selected' - expect(treeView.element.querySelectorAll('.selected').length).toBe 1 + expect(Array.from(treeView.getSelectedEntries())).toEqual([sampleTxt]) it "selects the path's parent dir if its entry is not visible", -> waitsForPromise -> atom.workspace.open(path.join('dir1', 'sub-dir1', 'sub-file1')) runs -> - dirView = root1.querySelector('.directory') - expect(dirView).toHaveClass 'selected' + expect(Array.from(treeView.getSelectedEntries())).toEqual([root1.querySelector('.directory')]) describe "when the tree-view.autoReveal config setting is true", -> beforeEach -> @@ -835,31 +834,33 @@ describe "TreeView", -> describe "core:move-down", -> describe "when a collapsed directory is selected", -> it "skips to the next directory", -> - root1.querySelector('.directory').dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + subdir = root1.querySelector('.directory') + treeView.selectEntry(subdir) + subdir.collapse() atom.commands.dispatch(treeView.element, 'core:move-down') expect(root1.querySelectorAll('.directory')[1]).toHaveClass 'selected' describe "when an expanded directory is selected", -> it "selects the first entry of the directory", -> - subdir = root1.querySelectorAll('.directory')[1] - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + subdir1 = root1.querySelectorAll('.directory')[1] + treeView.selectEntry(subdir1) + subdir1.expand() atom.commands.dispatch(treeView.element, 'core:move-down') - expect(subdir.querySelector('.entry')).toHaveClass 'selected' + expect(subdir1.querySelector('.entry')).toHaveClass 'selected' describe "when the last entry of an expanded directory is selected", -> it "selects the entry after its parent directory", -> subdir1 = root1.querySelectorAll('.directory')[1] subdir1.expand() - waitForWorkspaceOpenEvent -> - entries = subdir1.querySelectorAll('.entry') - entries[entries.length - 1].dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - runs -> - atom.commands.dispatch(treeView.element, 'core:move-down') - expect(root1.querySelectorAll('.directory')[2]).toHaveClass 'selected' + entries = subdir1.querySelectorAll('.entry') + treeView.selectEntry(entries[entries.length - 1]) + + atom.commands.dispatch(treeView.element, 'core:move-down') + expect(root1.querySelectorAll('.directory')[2]).toHaveClass 'selected' describe "when the last directory of another last directory is selected", -> [nested, nested2] = [] @@ -870,7 +871,7 @@ describe "TreeView", -> nested.expand() entries = nested.querySelectorAll('.entry') nested2 = entries[entries.length - 1] - nested2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(nested2) nested2.collapse() describe "when the directory is collapsed", -> @@ -889,12 +890,10 @@ describe "TreeView", -> it "does not change the selection", -> entries = root2.querySelectorAll('.entries .entry') lastEntry = entries[entries.length - 1] - waitForWorkspaceOpenEvent -> - lastEntry.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(lastEntry) - runs -> - atom.commands.dispatch(treeView.element, 'core:move-down') - expect(lastEntry).toHaveClass 'selected' + atom.commands.dispatch(treeView.element, 'core:move-down') + expect(lastEntry).toHaveClass 'selected' describe "core:move-up", -> describe "when there is an expanded directory before the currently selected entry", -> @@ -904,8 +903,7 @@ describe "TreeView", -> lastDir = directories[directories.length - 1] fileAfterDir = lastDir.nextSibling lastDir.expand() - waitForWorkspaceOpenEvent -> - fileAfterDir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileAfterDir) it "selects the last entry in the expanded directory", -> atom.commands.dispatch(treeView.element, 'core:move-up') @@ -932,18 +930,16 @@ describe "TreeView", -> it "selects the previous entry", -> entries = root1.querySelectorAll('.entry') lastEntry = entries[entries.length - 1] - waitForWorkspaceOpenEvent -> - lastEntry.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(lastEntry) - runs -> - atom.commands.dispatch(treeView.element, 'core:move-up') - expect(lastEntry.previousSibling).toHaveClass 'selected' + atom.commands.dispatch(treeView.element, 'core:move-up') + expect(lastEntry.previousSibling).toHaveClass 'selected' describe "when there is no entry before the currently selected entry, but there is a parent directory", -> it "selects the parent directory", -> subdir = root1.querySelector('.directory') subdir.expand() - subdir.querySelector('.entries .entry').dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir.querySelector('.entries .entry')) atom.commands.dispatch(treeView.element, 'core:move-up') @@ -951,7 +947,7 @@ describe "TreeView", -> describe "when there is no parent directory or previous entry", -> it "does not change the selection", -> - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(root1) atom.commands.dispatch(treeView.element, 'core:move-up') expect(treeView.roots[0]).toHaveClass 'selected' @@ -1053,7 +1049,7 @@ describe "TreeView", -> describe "when a directory entry is selected", -> it "expands the current directory", -> subdir = root1.querySelector('.directory') - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.collapse() expect(subdir).not.toHaveClass 'expanded' @@ -1062,14 +1058,14 @@ describe "TreeView", -> describe "when the directory is already expanded", -> describe "when the directory is empty", -> - xit "does nothing", -> + it "does nothing", -> rootDirPath = fs.absolute(temp.mkdirSync('tree-view-root1')) fs.mkdirSync(path.join(rootDirPath, "empty-dir")) atom.project.setPaths([rootDirPath]) rootView = treeView.roots[0] subdir = rootView.querySelector('.directory') - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.expand() expect(subdir).toHaveClass('expanded') expect(subdir).toHaveClass('selected') @@ -1081,7 +1077,7 @@ describe "TreeView", -> describe "when the directory has entries", -> it "moves the cursor down to the first sub-entry", -> subdir = root1.querySelector('.directory') - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.expand() atom.commands.dispatch(treeView.element, 'tree-view:expand-item') @@ -1089,21 +1085,20 @@ describe "TreeView", -> describe "when a file entry is selected", -> it "does nothing", -> - waitForWorkspaceOpenEvent -> - root1.querySelector('.file').dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + # TODO: This test should have some assertions + treeView.selectEntry(root1.querySelector('.file')) - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:expand-directory') + atom.commands.dispatch(treeView.element, 'tree-view:expand-directory') describe "tree-view:recursive-expand-directory", -> describe "when an collapsed root is recursively expanded", -> it "expands the root and all subdirectories", -> - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.roots[0].collapse() + treeView.selectEntry(root1) + root1.collapse() - expect(treeView.roots[0]).not.toHaveClass 'expanded' + expect(root1).not.toHaveClass 'expanded' atom.commands.dispatch(treeView.element, 'tree-view:recursive-expand-directory') - expect(treeView.roots[0]).toHaveClass 'expanded' + expect(root1).toHaveClass 'expanded' children = root1.querySelectorAll('.directory') expect(children.length).toBeGreaterThan 0 @@ -1118,15 +1113,13 @@ describe "TreeView", -> file1 = dir1.querySelector('.file') subdir1 = dir1.querySelector('.entries > .directory') - waitForWorkspaceOpenEvent -> - file1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(file1) - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:recursive-expand-directory') - expect(dir1).toHaveClass 'expanded' - expect(subdir1).toHaveClass 'expanded' - expect(file1).toHaveClass 'selected' - expect(dir2).toHaveClass 'collapsed' + atom.commands.dispatch(treeView.element, 'tree-view:recursive-expand-directory') + expect(dir1).toHaveClass 'expanded' + expect(subdir1).toHaveClass 'expanded' + expect(file1).toHaveClass 'selected' + expect(dir2).toHaveClass 'collapsed' describe "tree-view:collapse-directory", -> subdir = null @@ -1137,43 +1130,41 @@ describe "TreeView", -> describe "when an expanded directory is selected", -> it "collapses the selected directory", -> - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.expand() expect(subdir).toHaveClass 'expanded' atom.commands.dispatch(treeView.element, 'tree-view:collapse-directory') expect(subdir).not.toHaveClass 'expanded' - expect(treeView.roots[0]).toHaveClass 'expanded' + expect(root1).toHaveClass 'expanded' describe "when a collapsed directory is selected", -> it "collapses and selects the selected directory's parent directory", -> directories = subdir.querySelector('.directory') - directories.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(directories) directories.collapse() atom.commands.dispatch(treeView.element, 'tree-view:collapse-directory') expect(subdir).not.toHaveClass 'expanded' expect(subdir).toHaveClass 'selected' - expect(treeView.roots[0]).toHaveClass 'expanded' + expect(root1).toHaveClass 'expanded' describe "when collapsed root directory is selected", -> it "does not raise an error", -> - treeView.roots[0].collapse() - treeView.selectEntry(treeView.roots[0]) + root1.collapse() + treeView.selectEntry(root1) atom.commands.dispatch(treeView.element, 'tree-view:collapse-directory') describe "when a file is selected", -> it "collapses and selects the selected file's parent directory", -> - waitForWorkspaceOpenEvent -> - subdir.querySelector('.file').dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir.querySelector('.file')) - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:collapse-directory') - expect(subdir).not.toHaveClass 'expanded' - expect(subdir).toHaveClass 'selected' - expect(treeView.roots[0]).toHaveClass 'expanded' + atom.commands.dispatch(treeView.element, 'tree-view:collapse-directory') + expect(subdir).not.toHaveClass 'expanded' + expect(subdir).toHaveClass 'selected' + expect(treeView.roots[0]).toHaveClass 'expanded' describe "tree-view:recursive-collapse-directory", -> parent = null @@ -1188,11 +1179,11 @@ describe "TreeView", -> describe "when an expanded directory is recursively collapsed", -> it "collapses the directory and all its child directories", -> - parent.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(parent) parent.expand() expect(parent).toHaveClass 'expanded' for child in children - child.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(child) child.expand() expect(child).toHaveClass 'expanded' @@ -1280,7 +1271,7 @@ describe "TreeView", -> describe "when a directory is selected", -> it "expands or collapses the directory", -> subdir = root1.querySelector('.directory') - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.collapse() expect(subdir).not.toHaveClass 'expanded' @@ -1361,7 +1352,7 @@ describe "TreeView", -> describe "when a directory is selected", -> it "expands the directory", -> subdir = root1.querySelector('.directory') - subdir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(subdir) subdir.collapse() expect(subdir).not.toHaveClass 'expanded' @@ -1505,11 +1496,8 @@ describe "TreeView", -> beforeEach -> LocalStorage.clear() - waitForWorkspaceOpenEvent -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - - runs -> - atom.commands.dispatch(treeView.element, "tree-view:copy") + treeView.selectEntry(fileView2) + atom.commands.dispatch(treeView.element, "tree-view:copy") describe "when a file is selected", -> it "saves the selected file/directory path to localStorage['tree-view:copyPath']", -> @@ -1537,11 +1525,8 @@ describe "TreeView", -> beforeEach -> LocalStorage.clear() - waitForWorkspaceOpenEvent -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - - runs -> - atom.commands.dispatch(treeView.element, "tree-view:cut") + treeView.selectEntry(fileView2) + atom.commands.dispatch(treeView.element, "tree-view:cut") describe "when a file is selected", -> it "saves the selected file/directory path to localStorage['tree-view:cutPath']", -> @@ -1577,7 +1562,7 @@ describe "TreeView", -> # /dir-1/ -> /dir-1/ LocalStorage["tree-view:#{operation}Path"] = JSON.stringify([dirPath]) newPath = path.join(dirPath, path.basename(dirPath)) - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView) expect(-> atom.commands.dispatch(treeView.element, "tree-view:paste")).not.toThrow() expect(fs.existsSync(newPath)).toBe false expect(atom.notifications.getNotifications()[0].getMessage()).toContain 'Cannot paste a folder into itself' @@ -1592,7 +1577,7 @@ describe "TreeView", -> newPath = path.join(nestedPath, path.basename(dirPath)) dirView.reload() nestedView = dirView.querySelector('.directory') - nestedView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(nestedView) expect(-> atom.commands.dispatch(treeView.element, "tree-view:paste")).not.toThrow() expect(fs.existsSync(newPath)).toBe false expect(atom.notifications.getNotifications()[0].getMessage()).toContain 'Cannot paste a folder into itself' @@ -1602,7 +1587,7 @@ describe "TreeView", -> # /dir-1/ -> /dir-2/ LocalStorage["tree-view:#{operation}Path"] = JSON.stringify([dirPath]) newPath = path.join(dirPath2, path.basename(dirPath)) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) expect(-> atom.commands.dispatch(treeView.element, "tree-view:paste")).not.toThrow() expect(fs.existsSync(newPath)).toBe true expect(atom.notifications.getNotifications()[0]).toBeUndefined() @@ -1615,7 +1600,7 @@ describe "TreeView", -> LocalStorage["tree-view:#{operation}Path"] = JSON.stringify([dirPath]) newPath = path.join(dirPath, path.basename(dirPath)) symlinkView = root1.querySelector('.directory') - symlinkView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(symlinkView) expect(-> atom.commands.dispatch(treeView.element, "tree-view:paste")).not.toThrow() expect(fs.existsSync(newPath)).toBe false expect(atom.notifications.getNotifications()[0].getMessage()).toContain 'Cannot paste a folder into itself' @@ -1628,7 +1613,7 @@ describe "TreeView", -> # symlink of /dir-1/ -> /dir-1/ LocalStorage["tree-view:#{operation}Path"] = JSON.stringify([symlinkedPath]) newPath = path.join(dirPath, path.basename(symlinkedPath)) - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView) expect(-> atom.commands.dispatch(treeView.element, "tree-view:paste")).not.toThrow() expect(fs.existsSync(newPath)).toBe true expect(atom.notifications.getNotifications()[0]).toBeUndefined() @@ -1640,7 +1625,7 @@ describe "TreeView", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath2, filePathDoesntExist1, filePath3, filePathDoesntExist2]) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath, path.basename(filePath2)))).toBeTruthy() @@ -1656,7 +1641,7 @@ describe "TreeView", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) it "creates a copy of the original file in the selected file's parent directory", -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1666,7 +1651,7 @@ describe "TreeView", -> it "emits an event", -> callback = jasmine.createSpy("onEntryCopied") treeView.onEntryCopied(callback) - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1676,7 +1661,7 @@ describe "TreeView", -> it "appends a number to the destination name", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") atom.commands.dispatch(treeView.element, "tree-view:paste") @@ -1693,7 +1678,7 @@ describe "TreeView", -> atom.commands.dispatch(treeView.element, "tree-view:paste") - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath, path.basename(dotFilePath)))).toBeTruthy() expect(fs.existsSync(dotFilePath)).toBeTruthy() @@ -1704,7 +1689,7 @@ describe "TreeView", -> fs.writeFileSync(dotFilePath, "doesn't matter .") LocalStorage['tree-view:copyPath'] = JSON.stringify([dotFilePath]) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") atom.commands.dispatch(treeView.element, "tree-view:paste") @@ -1716,7 +1701,7 @@ describe "TreeView", -> it "creates a copy of the original file in the selected directory", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath2, path.basename(filePath)))).toBeTruthy() @@ -1726,7 +1711,7 @@ describe "TreeView", -> it "appends a number to the destination file name", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView) atom.commands.dispatch(treeView.element, "tree-view:paste") atom.commands.dispatch(treeView.element, "tree-view:paste") @@ -1748,7 +1733,7 @@ describe "TreeView", -> directories = treeView.roots[0].entries.querySelectorAll('.directory') dotDirView = directories[directories.length - 1] - dotDirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotDirView) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dotDirPath, path.basename(filePath)))).toBeTruthy() @@ -1762,7 +1747,7 @@ describe "TreeView", -> directories = treeView.roots[0].entries.querySelectorAll('.directory') dotDirView = directories[directories.length - 1] - dotDirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotDirView) atom.commands.dispatch(treeView.element, "tree-view:paste") atom.commands.dispatch(treeView.element, "tree-view:paste") @@ -1773,7 +1758,7 @@ describe "TreeView", -> describe "when pasting into a different root directory", -> it "creates the file", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath4]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath2, path.basename(filePath4)))).toBeTruthy() @@ -1785,7 +1770,7 @@ describe "TreeView", -> asteriskFilePath = path.join(dirPath, "test-file-**.txt") fs.writeFileSync(asteriskFilePath, "doesn't matter *") LocalStorage['tree-view:copyPath'] = JSON.stringify([asteriskFilePath]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath2, path.basename(asteriskFilePath)))).toBeTruthy() @@ -1798,7 +1783,7 @@ describe "TreeView", -> it "copies the selected files to the parent directory of the selected file", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath2, filePath3]) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath, path.basename(filePath2)))).toBeTruthy() @@ -1815,7 +1800,7 @@ describe "TreeView", -> fs.writeFileSync(filePath4, "doesn't matter") fs.writeFileSync(filePath5, "doesn't matter") - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath, "test-file20.txt"))).toBeTruthy() @@ -1827,7 +1812,7 @@ describe "TreeView", -> describe "when a file is selected", -> it "creates a copy of the original file in the selected file's parent directory and removes the original", -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1838,7 +1823,7 @@ describe "TreeView", -> callback = jasmine.createSpy("onEntryMoved") treeView.onEntryMoved(callback) - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1852,7 +1837,7 @@ describe "TreeView", -> filePath3 = path.join(dirPath2, "test-file.txt") fs.writeFileSync(filePath3, "doesn't matter") - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(filePath)).toBeTruthy() @@ -1867,7 +1852,7 @@ describe "TreeView", -> atom.workspace.open(filePath) it 'has its path updated', -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1881,7 +1866,7 @@ describe "TreeView", -> atom.workspace.open(filePath2) runs -> - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1895,7 +1880,7 @@ describe "TreeView", -> callback = jasmine.createSpy("onEntryMoved") treeView.onEntryMoved(callback) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath = path.join(dirPath2, path.basename(filePath)) @@ -1909,7 +1894,7 @@ describe "TreeView", -> LocalStorage['tree-view:cutPath'] = JSON.stringify([filePath2, filePath3]) it "moves the selected files to the parent directory of the selected file", -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath2 = path.join(dirPath, path.basename(filePath2)) @@ -1922,7 +1907,7 @@ describe "TreeView", -> it "emits events", -> callback = jasmine.createSpy("onEntryMoved") treeView.onEntryMoved(callback) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") newPath2 = path.join(dirPath, path.basename(filePath2)) @@ -1940,7 +1925,7 @@ describe "TreeView", -> fs.writeFileSync(filePath4, "doesn't matter") fs.writeFileSync(filePath5, "doesn't matter") - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(filePath2)).toBeTruthy() @@ -1950,7 +1935,7 @@ describe "TreeView", -> it "creates a copy of the original file in the selected directory and removes the original", -> LocalStorage['tree-view:cutPath'] = JSON.stringify([filePath]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) atom.commands.dispatch(treeView.element, "tree-view:paste") expect(fs.existsSync(path.join(dirPath2, path.basename(filePath)))).toBeTruthy() @@ -1966,7 +1951,7 @@ describe "TreeView", -> LocalStorage['tree-view:copyPath'] = JSON.stringify([filePath]) - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) atom.notifications.clear() atom.commands.dispatch(treeView.element, "tree-view:paste") @@ -1981,13 +1966,12 @@ describe "TreeView", -> callback = jasmine.createSpy("onFileCreated") treeView.onFileCreated(callback) - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:add-file") - [addPanel] = atom.workspace.getModalPanels() - addDialog = addPanel.getItem() + atom.commands.dispatch(treeView.element, "tree-view:add-file") + [addPanel] = atom.workspace.getModalPanels() + addDialog = addPanel.getItem() describe "when a file is selected", -> it "opens an add dialog with the file's current directory path populated", -> @@ -2027,17 +2011,17 @@ describe "TreeView", -> expect(treeView.element.querySelector('.selected').textContent).toBe path.basename(newPath) expect(callback).toHaveBeenCalledWith({path: newPath}) - it "adds file in any project path", -> + it "adds the new file in any project path", -> newPath = path.join(dirPath3, "new-test-file.txt") - waitForWorkspaceOpenEvent -> - fileView4.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView4) + + atom.commands.dispatch(treeView.element, "tree-view:add-file") + [addPanel] = atom.workspace.getModalPanels() + addDialog = addPanel.getItem() + addDialog.miniEditor.insertText(path.basename(newPath)) waitForWorkspaceOpenEvent -> - atom.commands.dispatch(treeView.element, "tree-view:add-file") - [addPanel] = atom.workspace.getModalPanels() - addDialog = addPanel.getItem() - addDialog.miniEditor.insertText(path.basename(newPath)) atom.commands.dispatch addDialog.element, 'core:confirm' runs -> @@ -2126,7 +2110,7 @@ describe "TreeView", -> describe "when a directory is selected", -> it "opens an add dialog with the directory's path populated", -> addDialog.cancel() - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView) atom.commands.dispatch(treeView.element, "tree-view:add-file") addDialog = atom.workspace.getModalPanels()[0].getItem() @@ -2140,7 +2124,7 @@ describe "TreeView", -> describe "when the root directory is selected", -> it "opens an add dialog with no path populated", -> addDialog.cancel() - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(root1) atom.commands.dispatch(treeView.element, "tree-view:add-file") addDialog = atom.workspace.getModalPanels()[0].getItem() @@ -2149,7 +2133,7 @@ describe "TreeView", -> describe "when there is no entry selected", -> it "opens an add dialog with no path populated", -> addDialog.cancel() - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(root1) root1.classList.remove('selected') expect(treeView.selectedEntry()).toBeNull() atom.commands.dispatch(treeView.element, "tree-view:add-file") @@ -2176,13 +2160,12 @@ describe "TreeView", -> callback = jasmine.createSpy("onDirectoryCreated") treeView.onDirectoryCreated(callback) - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:add-folder") - [addPanel] = atom.workspace.getModalPanels() - addDialog = addPanel.getItem() + atom.commands.dispatch(treeView.element, "tree-view:add-folder") + [addPanel] = atom.workspace.getModalPanels() + addDialog = addPanel.getItem() describe "when a file is selected", -> it "opens an add dialog with the file's current directory path populated", -> @@ -2201,7 +2184,6 @@ describe "TreeView", -> atom.commands.dispatch addDialog.element, 'core:confirm' expect(fs.isDirectorySync(newPath)).toBeTruthy() expect(atom.workspace.getModalPanels().length).toBe 0 - expect(atom.workspace.getCenter().getActivePaneItem().getPath()).not.toBe newPath expect(document.activeElement).toBe(treeView.element) expect(dirView.querySelector('.directory.selected').textContent).toBe('new') @@ -2215,7 +2197,6 @@ describe "TreeView", -> atom.commands.dispatch addDialog.element, 'core:confirm' expect(fs.isDirectorySync(newPath)).toBeTruthy() expect(atom.workspace.getModalPanels().length).toBe 0 - expect(atom.workspace.getCenter().getActivePaneItem().getPath()).not.toBe newPath expect(document.activeElement).toBe(treeView.element) expect(dirView.querySelector('.directory.selected').textContent).toBe('new') @@ -2234,7 +2215,6 @@ describe "TreeView", -> atom.commands.dispatch addDialog.element, 'core:confirm' expect(fs.isDirectorySync(newPath)).toBeTruthy() expect(atom.workspace.getModalPanels().length).toBe 0 - expect(atom.workspace.getCenter().getActivePaneItem().getPath()).not.toBe newPath expect(document.activeElement).toBe(treeView.element) expect(dirView.querySelector('.directory.selected').textContent).toBe('new2') @@ -2270,20 +2250,21 @@ describe "TreeView", -> expect(callback).not.toHaveBeenCalled() describe "tree-view:move", -> + beforeEach -> + jasmine.attachToDOM(workspaceElement) + describe "when a file is selected", -> [moveDialog, callback] = [] beforeEach -> - jasmine.attachToDOM(workspaceElement) callback = jasmine.createSpy("onEntryMoved") treeView.onEntryMoved(callback) - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:move") - moveDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:move") + moveDialog = atom.workspace.getModalPanels()[0].getItem() it "opens a move dialog with the file's current path (excluding extension) populated", -> extension = path.extname(filePath) @@ -2387,7 +2368,7 @@ describe "TreeView", -> expect(atom.workspace.getModalPanels().length).toBe 0 expect(atom.views.getView(atom.workspace.getCenter().getActivePane())).toHaveFocus() - describe "when a file is selected that's name starts with a '.'", -> + describe "when a file is selected whose name starts with a '.'", -> [dotFilePath, dotFileView, moveDialog] = [] beforeEach -> @@ -2397,12 +2378,11 @@ describe "TreeView", -> dirView.expand() dotFileView = treeView.entryForPath(dotFilePath) - waitForWorkspaceOpenEvent -> - dotFileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotFileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:move") - moveDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:move") + moveDialog = atom.workspace.getModalPanels()[0].getItem() it "selects the entire file name", -> expect(moveDialog.element).toExist() @@ -2419,12 +2399,11 @@ describe "TreeView", -> dirView.expand() dotFileView = treeView.entryForPath(dotFilePath) - waitForWorkspaceOpenEvent -> - dotFileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotFileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:move") - moveDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:move") + moveDialog = atom.workspace.getModalPanels()[0].getItem() it "selects only the part of the filename up to the first extension", -> expect(moveDialog.element).toExist() @@ -2435,16 +2414,14 @@ describe "TreeView", -> moveDialog = null beforeEach -> - jasmine.attachToDOM(workspaceElement) - waitForWorkspaceOpenEvent -> atom.workspace.open(filePath) - waitsForPromise -> - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - treeView.toggleFocus().then -> - atom.commands.dispatch(treeView.element, "tree-view:move") - moveDialog = atom.workspace.getModalPanels()[0].getItem() + runs -> + treeView.selectEntry(dirView) + treeView.focus() + atom.commands.dispatch(treeView.element, "tree-view:move") + moveDialog = atom.workspace.getModalPanels()[0].getItem() it "opens a move dialog with the folder's current path populated", -> extension = path.extname(dirPath) @@ -2481,23 +2458,24 @@ describe "TreeView", -> describe "when the project is selected", -> it "doesn't display the move dialog", -> - treeView.roots[0].dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(root1) + treeView.focus() atom.commands.dispatch(treeView.element, "tree-view:move") expect(atom.workspace.getModalPanels().length).toBe(0) describe "tree-view:duplicate", -> + beforeEach -> + jasmine.attachToDOM(workspaceElement) + describe "when a file is selected", -> copyDialog = null beforeEach -> - jasmine.attachToDOM(workspaceElement) - - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:duplicate") - copyDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:duplicate") + copyDialog = atom.workspace.getModalPanels()[0].getItem() afterEach -> waits 50 # The copy specs cause too many false positives because of their async nature, so wait a little bit before we cleanup @@ -2585,12 +2563,11 @@ describe "TreeView", -> dirView.expand() dotFileView = treeView.entryForPath(dotFilePath) - waitForWorkspaceOpenEvent -> - dotFileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotFileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:duplicate") - copyDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:duplicate") + copyDialog = atom.workspace.getModalPanels()[0].getItem() it "selects the entire file name", -> expect(copyDialog.element).toExist() @@ -2607,12 +2584,11 @@ describe "TreeView", -> dirView.expand() dotFileView = treeView.entryForPath(dotFilePath) - waitForWorkspaceOpenEvent -> - dotFileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dotFileView) + treeView.focus() - runs -> - atom.commands.dispatch(treeView.element, "tree-view:duplicate") - copyDialog = atom.workspace.getModalPanels()[0].getItem() + atom.commands.dispatch(treeView.element, "tree-view:duplicate") + copyDialog = atom.workspace.getModalPanels()[0].getItem() it "selects only the part of the filename up to the first extension", -> expect(copyDialog.element).toExist() @@ -2621,7 +2597,8 @@ describe "TreeView", -> describe "when the project is selected", -> it "doesn't display the copy dialog", -> - treeView.roots[0].dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(root1) + treeView.focus() atom.commands.dispatch(treeView.element, "tree-view:duplicate") expect(atom.workspace.getModalPanels().length).toBe(0) @@ -2654,8 +2631,9 @@ describe "TreeView", -> it "won't remove the root directory", -> spyOn(atom, 'confirm') + + treeView.selectEntry(root1) treeView.focus() - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) atom.commands.dispatch(treeView.element, 'tree-view:remove') args = atom.confirm.mostRecentCall.args[0] @@ -2664,13 +2642,12 @@ describe "TreeView", -> it "shows the native alert dialog", -> spyOn(atom, 'confirm') - waitForWorkspaceOpenEvent -> - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) + treeView.focus() + atom.commands.dispatch(treeView.element, 'tree-view:remove') - runs -> - atom.commands.dispatch(treeView.element, 'tree-view:remove') - args = atom.confirm.mostRecentCall.args[0] - expect(args.buttons).toEqual ['Move to Trash', 'Cancel'] + args = atom.confirm.mostRecentCall.args[0] + expect(args.buttons).toEqual ['Move to Trash', 'Cancel'] it "can delete an active path that isn't in the project", -> spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2698,7 +2675,7 @@ describe "TreeView", -> callback = jasmine.createSpy('onDeleteEntryFailed') treeView.onDeleteEntryFailed(callback) - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) treeView.focus() spyOn(shell, 'moveItemToTrash').andReturn(false) @@ -2743,7 +2720,7 @@ describe "TreeView", -> runs -> openFilePaths = atom.workspace.getTextEditors().map((editor) -> editor.getPath()) expect(openFilePaths).toEqual([filePath2, filePath3]) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2772,7 +2749,7 @@ describe "TreeView", -> expect(openFilePaths).toEqual([filePath2, filePath3]) atom.workspace.getActiveTextEditor().setText('MODIFIED') - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2807,7 +2784,7 @@ describe "TreeView", -> 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.selectEntry(dirView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2839,7 +2816,7 @@ describe "TreeView", -> 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.selectEntry(dirView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2857,7 +2834,7 @@ describe "TreeView", -> callback = jasmine.createSpy('onEntryDeleted') treeView.onEntryDeleted(callback) - dirView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(dirView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2907,7 +2884,7 @@ describe "TreeView", -> expect(openFilePaths).toEqual([filePath2]) atom.workspace.getActiveTextEditor().setText('MODIFIED') - fileView2.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2952,9 +2929,6 @@ describe "TreeView", -> callback = jasmine.createSpy('onEntryDeleted') treeView.onEntryDeleted(callback) - # 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() @@ -2976,8 +2950,8 @@ describe "TreeView", -> spyOn(fs, 'existsSync').andCallThrough() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - dirView.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) + treeView.selectEntry(fileView) + treeView.selectMultipleEntries(dirView) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -2996,8 +2970,8 @@ describe "TreeView", -> callback = jasmine.createSpy('onEntryDeleted') treeView.onEntryDeleted(callback) - dirView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) - fileView2.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, metaKey: true})) + treeView.selectEntry(dirView) + treeView.selectMultipleEntries(fileView2) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> callback(0) @@ -3018,7 +2992,7 @@ describe "TreeView", -> spyOn(fs, 'existsSync').andCallThrough() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) treeView.focus() spyOn(atom, 'confirm').andCallFake (options, callback) -> @@ -3068,15 +3042,18 @@ describe "TreeView", -> describe "when a root folder is added", -> it "maintains expanded folders", -> - root1.querySelector('.directory').dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + subdir = root1.querySelector('.directory') + subdir.expand() + atom.project.setPaths([path1, path2]) treeView = atom.workspace.getLeftDock().getActivePaneItem() expect(treeView.element).toExist() - expect(treeView.roots[0].querySelector(".directory")).toHaveClass("expanded") + expect(subdir).toHaveClass("expanded") it "maintains collapsed (root) folders", -> - root1.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + root1.collapse() + atom.project.setPaths([path1, path2]) treeView = atom.workspace.getLeftDock().getActivePaneItem() @@ -3222,7 +3199,6 @@ describe "TreeView", -> zetaDir = path.join(rootDir, "zeta") fs.makeTreeSync(zetaDir) atom.project.setPaths([rootDir]) - jasmine.attachToDOM(workspaceElement) rootDirPath = treeView.roots[0].getPath() expect(rootDirPath).toBe(rootDir) @@ -3283,7 +3259,6 @@ describe "TreeView", -> describe "when a file is created within a directory with another squashed directory", -> it "un-squashes the directories", -> - jasmine.attachToDOM(workspaceElement) piDir = findDirectoryContainingText(treeView.roots[0], "omicron#{path.sep}pi") expect(piDir).not.toBeNull() # omicron is a squashed dir, so searching for omicron would give us omicron/pi instead @@ -3294,7 +3269,7 @@ describe "TreeView", -> omicronDir = findDirectoryContainingText(treeView.roots[0], "omicron") expect(omicronDir.header.textContent).toEqual("omicron") - omicronDir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + omicronDir.expand() piDir = findDirectoryContainingText(omicronDir, "pi") expect(piDir.header.textContent).toEqual("pi") sigmaFile = findFileContainingText(omicronDir, "sigma.txt") @@ -3302,7 +3277,6 @@ describe "TreeView", -> describe "when a directory is created within a directory with another squashed directory", -> it "un-squashes the directories", -> - jasmine.attachToDOM(workspaceElement) piDir = findDirectoryContainingText(treeView.roots[0], "omicron#{path.sep}pi") expect(piDir).not.toBeNull() # omicron is a squashed dir, so searching for omicron would give us omicron/pi instead @@ -3313,7 +3287,7 @@ describe "TreeView", -> omicronDir = findDirectoryContainingText(treeView.roots[0], "omicron") expect(omicronDir.header.textContent).toEqual("omicron") - omicronDir.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + omicronDir.expand() piDir = findDirectoryContainingText(omicronDir, "pi") expect(piDir.header.textContent).toEqual("pi") rhoDir = findDirectoryContainingText(omicronDir, "rho") @@ -3410,7 +3384,7 @@ describe "TreeView", -> element.expand() for element in treeView.element.querySelectorAll('.directory') fileView = treeView.element.querySelector('.file.status-added') expect(fileView).not.toBeNull() - fileView.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(fileView) describe "when the file is deleted", -> it "updates the style of the directory", -> @@ -3948,10 +3922,10 @@ describe "TreeView", -> deltaFilePath2 = path.join(gammaDirPath, 'delta.txt2') fs.writeFileSync(deltaFilePath2, 'copy') - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(deltaFilePath) - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(deltaFilePath2) runs -> @@ -4002,10 +3976,10 @@ describe "TreeView", -> deltaFilePath2 = path.join(gammaDirPath, 'delta.txt2') fs.writeFileSync(deltaFilePath2, 'copy') - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(deltaFilePath) - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(deltaFilePath2) runs -> @@ -4121,7 +4095,7 @@ describe "TreeView", -> thetaFilePath2 = path.join(thetaDir2Path, 'theta.txt2') fs.writeFileSync(thetaFilePath2, 'copy') - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(thetaFilePath2) runs -> @@ -4134,7 +4108,7 @@ describe "TreeView", -> thetaDir = gammaDir.entries.children[0] thetaDir.expand() - waitForWorkspaceOpenEvent -> + waitsForPromise -> atom.workspace.open(thetaFilePath) runs -> @@ -4244,9 +4218,8 @@ describe "TreeView", -> dropEvent = eventHelpers.buildExternalDropEvent([deltaFilePath], alphaDir) - runs -> - treeView.onDrop(dropEvent) - expect(alphaDir.children.length).toBe 2 + treeView.onDrop(dropEvent) + expect(alphaDir.children.length).toBe 2 waitsFor "directory view contents to refresh", -> findDirectoryContainingText(treeView.roots[0], 'alpha').querySelectorAll('.entry').length > 2 @@ -4278,9 +4251,8 @@ describe "TreeView", -> dropEvent = eventHelpers.buildExternalDropEvent([deltaFilePath, gammaDirPath], alphaDir) - runs -> - treeView.onDrop(dropEvent) - expect(alphaDir.children.length).toBe 2 + treeView.onDrop(dropEvent) + expect(alphaDir.children.length).toBe 2 waitsFor "directory view contents to refresh", -> findDirectoryContainingText(treeView.roots[0], 'alpha').querySelectorAll('.entry').length > 3 @@ -4625,12 +4597,10 @@ describe "TreeView", -> nonProjectPath = path.join(temp.mkdirSync(), 'new-file.txt') fs.writeFileSync(nonProjectPath, 'test') - waitForWorkspaceOpenEvent -> - sampleJs.dispatchEvent(new MouseEvent('click', {bubbles: true, detail: 1})) + treeView.selectEntry(sampleJs) - runs -> - expect(sampleJs).toHaveClass 'selected' - expect(treeView.getSelectedEntries().length).toBe 1 + expect(sampleJs).toHaveClass 'selected' + expect(treeView.getSelectedEntries().length).toBe 1 waitsForPromise -> atom.workspace.open(nonProjectPath)