From cca47d785f95f6b38ffda2c7042fb0ef6161946f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 7 Apr 2017 14:28:51 -0700 Subject: [PATCH] Handle active pane items that aren't text editors in main process test Signed-off-by: Nathan Sobo --- spec/main-process/atom-application.test.js | 53 ++++++++++++---------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index 71d59a736..8b2fd9a95 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -51,8 +51,8 @@ describe('AtomApplication', function () { await focusWindow(window) const cursorRow = await evalInWebContents(window.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (textEditor) { - if (textEditor) sendBackToMainProcess(textEditor.getCursorBufferPosition().row) + atom.workspace.observeTextEditors(function (textEditor) { + sendBackToMainProcess(textEditor.getCursorBufferPosition().row) }) }) @@ -68,8 +68,8 @@ describe('AtomApplication', function () { await focusWindow(window) const cursorPosition = await evalInWebContents(window.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (textEditor) { - if (textEditor) sendBackToMainProcess(textEditor.getCursorBufferPosition()) + atom.workspace.observeTextEditors(function (textEditor) { + sendBackToMainProcess(textEditor.getCursorBufferPosition()) }) }) @@ -85,8 +85,8 @@ describe('AtomApplication', function () { await focusWindow(window) const openedPath = await evalInWebContents(window.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (textEditor) { - if (textEditor) sendBackToMainProcess(textEditor.getPath()) + atom.workspace.observeTextEditors(function (textEditor) { + sendBackToMainProcess(textEditor.getPath()) }) }) @@ -137,8 +137,9 @@ describe('AtomApplication', function () { assert.equal(reusedWindow, window1) assert.deepEqual(atomApplication.windows, [window1]) activeEditorPath = await evalInWebContents(window1.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.onDidChangeActivePaneItem(function (textEditor) { + const subscription = atom.workspace.onDidChangeActivePaneItem(function (textEditor) { sendBackToMainProcess(textEditor.getPath()) + subscription.dispose() }) }) assert.equal(activeEditorPath, existingDirCFilePath) @@ -163,10 +164,9 @@ describe('AtomApplication', function () { const window1 = atomApplication.launch(parseCommandLine([path.join(dirAPath, 'new-file')])) await focusWindow(window1) - let activeEditorPath - activeEditorPath = await evalInWebContents(window1.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (textEditor) { - if (textEditor) sendBackToMainProcess(textEditor.getPath()) + let activeEditorPath = await evalInWebContents(window1.browserWindow.webContents, function (sendBackToMainProcess) { + atom.workspace.observeTextEditors(function (textEditor) { + sendBackToMainProcess(textEditor.getPath()) }) }) assert.equal(activeEditorPath, path.join(dirAPath, 'new-file')) @@ -177,8 +177,9 @@ describe('AtomApplication', function () { assert.equal(reusedWindow, window1) assert.deepEqual(atomApplication.windows, [window1]) activeEditorPath = await evalInWebContents(window1.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.onDidChangeActivePaneItem(function (textEditor) { + const subscription = atom.workspace.onDidChangeActivePaneItem(function (textEditor) { sendBackToMainProcess(textEditor.getPath()) + subscription.dispose() }) }) assert.equal(activeEditorPath, existingDirCFilePath) @@ -201,11 +202,9 @@ describe('AtomApplication', function () { const window1 = atomApplication.launch(parseCommandLine([nonExistentFilePath])) await evalInWebContents(window1.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (textEditor) { - if (textEditor) { - textEditor.insertText('Hello World!') - sendBackToMainProcess(null) - } + atom.workspace.observeTextEditors(function (textEditor) { + textEditor.insertText('Hello World!') + sendBackToMainProcess(null) }) }) await window1.saveState() @@ -313,8 +312,8 @@ describe('AtomApplication', function () { const window = atomApplication.launch(parseCommandLine([newFilePath])) await focusWindow(window) const {editorTitle, editorText} = await evalInWebContents(window.browserWindow.webContents, function (sendBackToMainProcess) { - atom.workspace.observeActivePaneItem(function (editor) { - if (editor) sendBackToMainProcess({editorTitle: editor.getTitle(), editorText: editor.getText()}) + atom.workspace.observeTextEditors(function (editor) { + sendBackToMainProcess({editorTitle: editor.getTitle(), editorText: editor.getText()}) }) }) assert.equal(editorTitle, path.basename(newFilePath)) @@ -395,7 +394,7 @@ describe('AtomApplication', function () { const atomApplication2 = buildAtomApplication() const app2Window = atomApplication2.launch(parseCommandLine([])) await focusWindow(app2Window) - assert.deepEqual(await getTreeViewRootDirectories(app2Window), []) + assert.deepEqual(app2Window.representedDirectoryPaths, []) }) describe('when closing the last window', function () { @@ -520,11 +519,15 @@ describe('AtomApplication', function () { function getTreeViewRootDirectories (atomWindow) { return evalInWebContents(atomWindow.browserWindow.webContents, function (sendBackToMainProcess) { - sendBackToMainProcess( - Array - .from(document.querySelectorAll('.tree-view .project-root > .header .name')) - .map(element => element.dataset.path) - ) + atom.workspace.getLeftDock().observeActivePaneItem((treeView) => { + if (treeView) { + sendBackToMainProcess( + Array + .from(treeView.element.querySelectorAll('.project-root > .header .name')) + .map(element => element.dataset.path) + ) + } + }) }) }