diff --git a/spec/find-spec.js b/spec/find-spec.js index 01298a8e..36dda22e 100644 --- a/spec/find-spec.js +++ b/spec/find-spec.js @@ -11,7 +11,7 @@ describe('Find', () => { atom.workspace.addOpener(DeferredEditorItem.opener) const activationPromise = atom.packages.activatePackage('find-and-replace') - atom.commands.dispatch(atom.views.getView(atom.workspace), 'find-and-replace:show') + await atom.commands.dispatch(atom.views.getView(atom.workspace), 'find-and-replace:show') await activationPromise spyOn(BufferSearch.prototype, 'setEditor') diff --git a/spec/find-view-spec.js b/spec/find-view-spec.js index feade45c..58f099ee 100644 --- a/spec/find-view-spec.js +++ b/spec/find-view-spec.js @@ -41,7 +41,7 @@ describe("FindView", () => { describe("when find-and-replace:show is triggered", () => { it("attaches FindView to the root view", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(workspaceElement.querySelector(".find-and-replace")).toBeDefined(); @@ -50,7 +50,7 @@ describe("FindView", () => { it("populates the findEditor with selection when there is a selection", async () => { editor.setSelectedBufferRange([[2, 8], [2, 13]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(getFindAtomPanel()).toBeVisible(); @@ -58,7 +58,7 @@ describe("FindView", () => { findView.findEditor.setText(""); editor.setSelectedBufferRange([[2, 14], [2, 20]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); expect(getFindAtomPanel()).toBeVisible(); expect(findView.findEditor.getText()).toBe("length"); }); @@ -66,18 +66,18 @@ describe("FindView", () => { it("does not change the findEditor text when there is no selection", async () => { editor.setSelectedBufferRange([[2, 8], [2, 8]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; findView.findEditor.setText("kitten"); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); expect(findView.findEditor.getText()).toBe("kitten"); }); it("does not change the findEditor text when there is a multiline selection", async () => { editor.setSelectedBufferRange([[2, 8], [3, 12]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(getFindAtomPanel()).toBeVisible(); @@ -89,7 +89,7 @@ describe("FindView", () => { atom.config.set("find-and-replace.caseSensitive", true); atom.config.set("find-and-replace.inCurrentSelection", true); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(findView.refs.caseOptionButton).toHaveClass("selected"); @@ -101,7 +101,7 @@ describe("FindView", () => { atom.config.set("find-and-replace.useRegex", true); editor.setSelectedBufferRange([[6, 6], [6, 65]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(findView.findEditor.getText()).toBe( @@ -110,7 +110,7 @@ describe("FindView", () => { }); it('selects the text to find when the panel is re-shown', async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; const stringToSearch = "not found"; @@ -118,9 +118,9 @@ describe("FindView", () => { findEditor.setText(stringToSearch); - atom.commands.dispatch(findEditor.element, "core:confirm"); - atom.commands.dispatch(document.activeElement, "core:cancel"); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(findEditor.element, "core:confirm"); + await atom.commands.dispatch(document.activeElement, "core:cancel"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); expect(findEditor.getSelectedBufferRange()).toEqual([[0, 0], [0, stringToSearch.length]]); @@ -132,29 +132,29 @@ describe("FindView", () => { describe("when find-and-replace:toggle is triggered", () => { it("toggles the visibility of the FindView", async () => { - atom.commands.dispatch(workspaceElement, "find-and-replace:toggle"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:toggle"); await activationPromise; expect(getFindAtomPanel()).toBeVisible(); - atom.commands.dispatch(workspaceElement, "find-and-replace:toggle"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:toggle"); expect(getFindAtomPanel()).not.toBeVisible(); }); }); describe("when the find-view is focused and window:focus-next-pane is triggered", () => { it("attaches FindView to the root view", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(workspaceElement.querySelector(".find-and-replace")).toHaveFocus(); - atom.commands.dispatch(findView.findEditor.element, "window:focus-next-pane"); + await atom.commands.dispatch(findView.findEditor.element, "window:focus-next-pane"); expect(workspaceElement.querySelector(".find-and-replace")).not.toHaveFocus(); }); }); describe("find-and-replace:show-replace", () => { it("focuses the replace editor", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show-replace"); + await atom.commands.dispatch(editorView, "find-and-replace:show-replace"); await activationPromise; expect(findView.replaceEditor.element).toHaveFocus(); @@ -163,7 +163,7 @@ describe("FindView", () => { it("places the current selection in the replace editor", async () => { editor.setSelectedBufferRange([[0, 16], [0, 27]]); - atom.commands.dispatch(editorView, "find-and-replace:show-replace"); + await atom.commands.dispatch(editorView, "find-and-replace:show-replace"); await activationPromise; expect(findView.replaceEditor.getText()).toBe("function ()"); @@ -172,9 +172,9 @@ describe("FindView", () => { it("does not escape the text when the regex option is enabled", async () => { editor.setSelectedBufferRange([[0, 16], [0, 27]]); - atom.commands.dispatch(editorView, "find-and-replace:show"); - atom.commands.dispatch(editorView, "find-and-replace:toggle-regex-option"); - atom.commands.dispatch(editorView, "find-and-replace:show-replace"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(editorView, "find-and-replace:show-replace"); await activationPromise; expect(findView.replaceEditor.getText()).toBe("function ()"); @@ -183,7 +183,7 @@ describe("FindView", () => { describe("when find-and-replace:clear-history is triggered", () => { it("clears the find and replace histories", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; findView.findEditor.setText("items"); @@ -192,43 +192,43 @@ describe("FindView", () => { findView.findEditor.setText("sort"); findView.replaceEditor.setText("dog"); findView.replaceNext(); - atom.commands.dispatch(editorView, "find-and-replace:clear-history"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(editorView, "find-and-replace:clear-history"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toBe(""); - atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); expect(findView.replaceEditor.getText()).toBe(""); }); }); describe("core:cancel", () => { beforeEach(async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); findView.element.focus(); }); describe("when core:cancel is triggered on the find view", () => { - it("detaches from the workspace view", () => { - atom.commands.dispatch(document.activeElement, "core:cancel"); + it("detaches from the workspace view", async () => { + await atom.commands.dispatch(document.activeElement, "core:cancel"); expect(getFindAtomPanel()).not.toBeVisible(); }); - it("removes highlighted matches", () => { + it("removes highlighted matches", async () => { expect(workspaceElement).toHaveClass("find-visible"); - atom.commands.dispatch(document.activeElement, "core:cancel"); + await atom.commands.dispatch(document.activeElement, "core:cancel"); expect(workspaceElement).not.toHaveClass("find-visible"); }); }); describe("when core:cancel is triggered on an empty pane", () => { - it("hides the find panel", () => { + it("hides the find panel", async () => { const paneElement = atom.views.getView(atom.workspace.getCenter().getActivePane()); paneElement.focus(); - atom.commands.dispatch(paneElement, "core:cancel"); + await atom.commands.dispatch(paneElement, "core:cancel"); expect(getFindAtomPanel()).not.toBeVisible(); }); }); @@ -236,13 +236,13 @@ describe("FindView", () => { describe("when core:cancel is triggered on an editor", () => { it("detaches from the workspace view", async () => { atom.workspace.open(); - atom.commands.dispatch(editorView, "core:cancel"); + await atom.commands.dispatch(editorView, "core:cancel"); expect(getFindAtomPanel()).not.toBeVisible(); }); }); describe("when core:cancel is triggered on a mini editor", () => { - it("leaves the find view attached", () => { + it("leaves the find view attached", async () => { const miniEditor = document.createElement("atom-text-editor"); miniEditor.setAttribute("mini", ""); @@ -251,7 +251,7 @@ describe("FindView", () => { }); miniEditor.focus(); - atom.commands.dispatch(miniEditor, "core:cancel"); + await atom.commands.dispatch(miniEditor, "core:cancel"); expect(getFindAtomPanel()).toBeVisible(); }); }); @@ -259,7 +259,7 @@ describe("FindView", () => { describe("serialization", () => { it("serializes find and replace history", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; findView.findEditor.setText("items"); @@ -277,23 +277,23 @@ describe("FindView", () => { mainModule.createViews(); ({findView} = mainModule); }); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toBe("shift"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toBe("sort"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toBe("items"); - atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); expect(findView.replaceEditor.getText()).toBe("dog"); - atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:move-up"); expect(findView.replaceEditor.getText()).toBe("cat"); }); it("serializes find options ", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(findView.refs.caseOptionButton).not.toHaveClass("selected"); @@ -315,7 +315,7 @@ describe("FindView", () => { mainModule.createViews(); ({findView} = mainModule); }); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(findView.refs.caseOptionButton).toHaveClass("selected"); @@ -330,37 +330,37 @@ describe("FindView", () => { atom.config.set("find-and-replace.focusEditorAfterSearch", false); editor.setCursorBufferPosition([2, 0]); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); }); describe("when find-and-replace:confirm is triggered", () => { - it("runs a search", () => { + it("runs a search", async () => { findView.findEditor.setText("notinthefile"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(0); findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(5); }); }); describe("when no results are found", () => { - it("adds a .has-no-results class", () => { + it("adds a .has-no-results class", async () => { findView.findEditor.setText("notinthefile"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); expect(findView.element).toHaveClass("has-no-results"); }); }); describe("when results are found", () => { - it("adds a .has-results class", () => { + it("adds a .has-results class", async () => { findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:confirm"); expect(findView.element).toHaveClass("has-results"); }); }); @@ -372,60 +372,60 @@ describe("FindView", () => { }); describe("when regex search is enabled", () => { - beforeEach(() => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + beforeEach(async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); }); - it("finds a backslash", () => { + it("finds a backslash", async () => { findView.findEditor.setText("\\\\"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 0], [1, 1]]); }); - it("finds a newline", () => { + it("finds a newline", async () => { findView.findEditor.setText("\\n"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[0, 1], [1, 0]]); }); - it("finds a tab character", () => { + it("finds a tab character", async () => { findView.findEditor.setText("\\t"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[0, 0], [0, 1]]); }); }); describe("when regex search is disabled", () => { - it("finds the literal backslash t", () => { + it("finds the literal backslash t", async () => { findView.findEditor.setText("\\t"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 0], [1, 2]]); }); - it("finds a backslash", () => { + it("finds a backslash", async () => { findView.findEditor.setText("\\"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 0], [1, 1]]); }); - it("finds two backslashes", () => { + it("finds two backslashes", async () => { findView.findEditor.setText('\\\\'); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 2], [1, 4]]); }); - it("doesn't find when escaped", () => { + it("doesn't find when escaped", async () => { findView.findEditor.setText("\\\\t"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[0, 0], [0, 0]]); }); }); }); describe("when focusEditorAfterSearch is set", () => { - beforeEach(() => { + beforeEach(async () => { atom.config.set("find-and-replace.focusEditorAfterSearch", true); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); }); it("selects the first match following the cursor and correctly focuses the editor", () => { @@ -436,31 +436,31 @@ describe("FindView", () => { }); describe("when whole-word search is enabled", () => { - beforeEach(() => { + beforeEach(async () => { editor.setText("-----\nswhole-wordy\nwhole-word\nword\nwhole-swords"); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); }); - it("finds the whole words", () => { + it("finds the whole words", async () => { findView.findEditor.setText("word"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[2, 6], [2, 10]]); }); - it("doesn't highlight the search inside words", () => { + it("doesn't highlight the search inside words", async () => { findView.findEditor.setText("word"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(1); expect(getResultDecorations(editor, "current-result")).toHaveLength(1); }); }); - it("doesn't change the selection, beeps if there are no matches and keeps focus on the find view", () => { + it("doesn't change the selection, beeps if there are no matches and keeps focus on the find view", async () => { editor.setCursorBufferPosition([2, 0]); findView.findEditor.setText("notinthefilebro"); findView.findEditor.element.focus(); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getCursorBufferPosition()).toEqual([2, 0]); expect(atom.beep).toHaveBeenCalled(); expect(findView.element).toHaveFocus(); @@ -468,63 +468,63 @@ describe("FindView", () => { }); describe("updating the replace button enablement", () => { - it("enables the replace buttons when are search results", () => { + it("enables the replace buttons when are search results", async () => { findView.findEditor.setText("item"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.replaceAllButton).not.toHaveClass("disabled"); expect(findView.refs.replaceNextButton).not.toHaveClass("disabled"); const disposable = findView.replaceTooltipSubscriptions; spyOn(disposable, "dispose"); findView.findEditor.setText("it"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.replaceAllButton).not.toHaveClass("disabled"); expect(findView.refs.replaceNextButton).not.toHaveClass("disabled"); expect(disposable.dispose).not.toHaveBeenCalled(); findView.findEditor.setText("nopenotinthefile"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.replaceAllButton).toHaveClass("disabled"); expect(findView.refs.replaceNextButton).toHaveClass("disabled"); expect(disposable.dispose).toHaveBeenCalled(); findView.findEditor.setText("i"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.replaceAllButton).not.toHaveClass("disabled"); expect(findView.refs.replaceNextButton).not.toHaveClass("disabled"); findView.findEditor.setText(""); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.replaceAllButton).toHaveClass("disabled"); expect(findView.refs.replaceNextButton).toHaveClass("disabled"); }); }); describe("updating the descriptionLabel", () => { - it("properly updates the info message", () => { + it("properly updates the info message", async () => { findView.findEditor.setText("item"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel.textContent).toEqual("6 results found for 'item'"); findView.findEditor.setText("notinthefilenope"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel.textContent).toEqual("No results found for 'notinthefilenope'"); findView.findEditor.setText("item"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel.textContent).toEqual("6 results found for 'item'"); findView.findEditor.setText(""); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel.textContent).toContain("Find in Current Buffer"); }); describe("when there is an error", () => { - describe("when the regex search string is invalid", () => { - beforeEach(() => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + describe("when the regex search string is invalid", async () => { + beforeEach(async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("i[t"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); }); it("displays the error", () => { @@ -532,25 +532,25 @@ describe("FindView", () => { expect(findView.refs.descriptionLabel.textContent).toContain("Invalid regular expression"); }); - it("will be reset when there is no longer an error", () => { + it("will be reset when there is no longer an error", async () => { expect(findView.refs.descriptionLabel).toHaveClass("text-error"); findView.findEditor.setText(""); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel).not.toHaveClass("text-error"); expect(findView.refs.descriptionLabel.textContent).toContain("Find in Current Buffer"); findView.findEditor.setText("item"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel).not.toHaveClass("text-error"); expect(findView.refs.descriptionLabel.textContent).toContain("6 results"); }); }); describe("when the search string is too large", () => { - beforeEach(() => { + beforeEach(async () => { findView.findEditor.setText("x".repeat(50000)); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); }); it("displays the error", () => { @@ -558,14 +558,14 @@ describe("FindView", () => { expect(findView.refs.descriptionLabel.textContent).toBe("regular expression is too large"); }); - it("will be reset when there is no longer an error", () => { + it("will be reset when there is no longer an error", async () => { findView.findEditor.setText(""); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel).not.toHaveClass("text-error"); expect(findView.refs.descriptionLabel.textContent).toContain("Find in Current Buffer"); findView.findEditor.setText("item"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel).not.toHaveClass("text-error"); expect(findView.refs.descriptionLabel.textContent).toContain("6 results"); }); @@ -573,11 +573,11 @@ describe("FindView", () => { }); }); - it("selects the first match following the cursor", () => { + it("selects the first match following the cursor", async () => { expect(findView.refs.resultCounter.textContent).toEqual("2 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[2, 8], [2, 13]]); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.resultCounter.textContent).toEqual("3 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[2, 34], [2, 39]]); expect(findView.findEditor.element).toHaveFocus(); @@ -598,69 +598,69 @@ describe("FindView", () => { expect(editor.getSelectedBufferRange()).toEqual([[1, 22], [1, 27]]); }); - it("selects the next match when the 'find-and-replace:find-next' event is triggered and correctly focuses the editor", () => { + it("selects the next match when the 'find-and-replace:find-next' event is triggered and correctly focuses the editor", async () => { expect(findView.element).toHaveFocus(); - atom.commands.dispatch(editorView, "find-and-replace:find-next"); + await atom.commands.dispatch(editorView, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("3 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[2, 34], [2, 39]]); expect(editorView).toHaveFocus(); }); - it("selects the previous match before the cursor when the 'find-and-replace:show-previous' event is triggered", () => { + it("selects the previous match before the cursor when the 'find-and-replace:show-previous' event is triggered", async () => { expect(findView.refs.resultCounter.textContent).toEqual("2 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[2, 8], [2, 13]]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:show-previous"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:show-previous"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[1, 22], [1, 27]]); expect(findView.findEditor.element).toHaveFocus(); }); describe("when the match is folded", () => { - it("unfolds the match", () => { + it("unfolds the match", async () => { editor.foldAll(); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[2, 34], [2, 39]]); expect(editor.isFoldedAtBufferRow(2)).toBe(false); expect(editor.getCursorBufferPosition()).toEqual([2, 39]); }) }) - it("will re-run search if 'find-and-replace:find-next' is triggered after changing the findEditor's text", () => { + it("will re-run search if 'find-and-replace:find-next' is triggered after changing the findEditor's text", async () => { findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("3 of 5"); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); }); - it("'find-and-replace:find-next' adds to the findEditor's history", () => { + it("'find-and-replace:find-next' adds to the findEditor's history", async () => { findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("3 of 5"); findView.findEditor.setText("nope"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("sort"); }); - it("selects the previous match when the 'find-and-replace:find-previous' event is triggered and correctly focuses the editor", () => { + it("selects the previous match when the 'find-and-replace:find-previous' event is triggered and correctly focuses the editor", async () => { expect(findView.element).toHaveFocus(); - atom.commands.dispatch(editorView, "find-and-replace:find-previous"); + await atom.commands.dispatch(editorView, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); expect(editor.getSelectedBufferRange()).toEqual([[1, 27], [1, 22]]); expect(editorView).toHaveFocus(); }); - it("will re-run search if 'find-and-replace:find-previous' is triggered after changing the findEditor's text", () => { + it("will re-run search if 'find-and-replace:find-previous' is triggered after changing the findEditor's text", async () => { findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("2 of 5"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); - it("selects all matches when 'find-and-replace:find-all' is triggered and correctly focuses the editor", () => { + it("selects all matches when 'find-and-replace:find-all' is triggered and correctly focuses the editor", async () => { expect(findView.element).toHaveFocus(); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-all"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-all"); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 27], [1, 22]], @@ -673,9 +673,9 @@ describe("FindView", () => { expect(editorView).toHaveFocus(); }); - it("will re-run search if 'find-and-replace:find-all' is triggered after changing the findEditor's text", () => { + it("will re-run search if 'find-and-replace:find-all' is triggered after changing the findEditor's text", async () => { findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-all"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-all"); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 9], [0, 13]], @@ -697,7 +697,7 @@ describe("FindView", () => { expect(findView.refs.resultCounter.textContent).toEqual("3 of 6"); }); - it("shows an icon when search wraps around and the editor scrolls", () => { + it("shows an icon when search wraps around and the editor scrolls", async () => { editorView.style.height = "80px"; editorView.component.measureDimensions(); @@ -705,193 +705,193 @@ describe("FindView", () => { expect(findView.refs.resultCounter.textContent).toEqual("2 of 6"); expect(findView.wrapIcon).not.toBeVisible(); - atom.commands.dispatch(editorView, "find-and-replace:find-previous"); + await atom.commands.dispatch(editorView, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); expect(editor.getLastVisibleScreenRow()).toBe(3); expect(findView.wrapIcon).not.toBeVisible(); - atom.commands.dispatch(editorView, "find-and-replace:find-previous"); + await atom.commands.dispatch(editorView, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("6 of 6"); expect(editor.getLastVisibleScreenRow()).toBe(7); expect(findView.wrapIcon).toBeVisible(); expect(findView.wrapIcon).toHaveClass("icon-move-down"); - atom.commands.dispatch(editorView, "find-and-replace:find-next"); + await atom.commands.dispatch(editorView, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); expect(editor.getLastVisibleScreenRow()).toBe(3); expect(findView.wrapIcon).toBeVisible(); expect(findView.wrapIcon).toHaveClass("icon-move-up"); }); - it("does not show the wrap icon when the editor does not scroll", () => { + it("does not show the wrap icon when the editor does not scroll", async () => { editorView.style.height = "400px"; editor.update({autoHeight: false}) editorView.component.measureDimensions(); expect(editor.getVisibleRowRange()).toEqual([0, 12]); - atom.commands.dispatch(editorView, "find-and-replace:find-previous"); + await atom.commands.dispatch(editorView, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); - atom.commands.dispatch(editorView, "find-and-replace:find-previous"); + await atom.commands.dispatch(editorView, "find-and-replace:find-previous"); expect(findView.refs.resultCounter.textContent).toEqual("6 of 6"); expect(editor.getVisibleRowRange()).toEqual([0, 12]); expect(findView.wrapIcon).not.toBeVisible(); - atom.commands.dispatch(editorView, "find-and-replace:find-next"); + await atom.commands.dispatch(editorView, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); expect(editor.getVisibleRowRange()).toEqual([0, 12]); expect(findView.wrapIcon).not.toBeVisible(); }); - it("allows searching for dashes in combination with non-ascii characters (regression)", () => { + it("allows searching for dashes in combination with non-ascii characters (regression)", async () => { editor.setText("123-Âbc"); findView.findEditor.setText("3-â"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); expect(findView.refs.descriptionLabel).not.toHaveClass("text-error"); expect(editor.getSelectedBufferRange()).toEqual([[0, 2], [0, 5]]); }); describe("when find-and-replace:use-selection-as-find-pattern is triggered", () => { - it("places the selected text into the find editor", () => { + it("places the selected text into the find editor", async () => { editor.setSelectedBufferRange([[1, 6], [1, 10]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-next"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-next"); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); atom.workspace.destroyActivePane(); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe("sort"); }); - it("places the word under the cursor into the find editor", () => { + it("places the word under the cursor into the find editor", async () => { editor.setSelectedBufferRange([[1, 8], [1, 8]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[1, 8], [1, 8]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-next"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-next"); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); }); - it("places the previously selected text into the find editor if no selection", () => { + it("places the previously selected text into the find editor if no selection", async () => { editor.setSelectedBufferRange([[1, 6], [1, 10]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe("sort"); editor.setSelectedBufferRange([[1, 1], [1, 1]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe("sort"); }); - it("places selected text into the find editor and escapes it when Regex is enabled", () => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + it("places selected text into the find editor and escapes it when Regex is enabled", async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); editor.setSelectedBufferRange([[6, 6], [6, 65]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.findEditor.getText()).toBe( "current < pivot \\? left\\.push\\(current\\) : right\\.push\\(current\\);" ); }); - it("searches for the amount of results", () => { + it("searches for the amount of results", async () => { spyOn(findView, 'liveSearch') // ignore live search - we're interested in the explicit search call editor.setSelectedBufferRange([[1, 8], [1, 8]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:use-selection-as-find-pattern"); expect(findView.refs.resultCounter.textContent).toEqual("5 found"); }) }); describe("when find-and-replace:use-selection-as-replace-pattern is triggered", () => { - it("places the selected text into the replace editor", () => { + it("places the selected text into the replace editor", async () => { editor.setSelectedBufferRange([[3, 8], [3, 13]]); - atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); expect(findView.replaceEditor.getText()).toBe('pivot'); expect(editor.getSelectedBufferRange()).toEqual([[3, 8], [3, 13]]); findView.findEditor.setText('sort'); - atom.commands.dispatch(workspaceElement, 'find-and-replace:find-next'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:find-next'); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); expect(editor.getTextInBufferRange(editor.getSelectedBufferRange())).toEqual('sort'); - atom.commands.dispatch(workspaceElement, 'find-and-replace:replace-next'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:replace-next'); expect(editor.getTextInBufferRange([[8, 11], [8, 16]])).toEqual('pivot'); expect(editor.getSelectedBufferRange()).toEqual([[8, 44], [8, 48]]); expect(editor.getTextInBufferRange(editor.getSelectedBufferRange())).toEqual('sort'); }); - it("places the word under the cursor into the replace editor", () => { + it("places the word under the cursor into the replace editor", async () => { editor.setSelectedBufferRange([[3, 8], [3, 8]]); - atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); expect(findView.replaceEditor.getText()).toBe('pivot'); expect(editor.getSelectedBufferRange()).toEqual([[3, 8], [3, 8]]); findView.findEditor.setText('sort'); - atom.commands.dispatch(workspaceElement, 'find-and-replace:find-next'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:find-next'); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); expect(editor.getTextInBufferRange(editor.getSelectedBufferRange())).toEqual('sort'); - atom.commands.dispatch(workspaceElement, 'find-and-replace:replace-next'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:replace-next'); expect(editor.getTextInBufferRange([[8, 11], [8, 16]])).toEqual('pivot'); expect(editor.getSelectedBufferRange()).toEqual([[8, 44], [8, 48]]); expect(editor.getTextInBufferRange(editor.getSelectedBufferRange())).toEqual('sort'); }); - it("places the previously selected text into the replace editor if no selection", () => { + it("places the previously selected text into the replace editor if no selection", async () => { editor.setSelectedBufferRange([[1, 6], [1, 10]]); - atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); expect(findView.replaceEditor.getText()).toBe('sort'); editor.setSelectedBufferRange([[1, 1], [1, 1]]); - atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); expect(findView.replaceEditor.getText()).toBe('sort'); }); - it("places selected text into the replace editor and escapes it when Regex is enabled", () => { - atom.commands.dispatch(findView.replaceEditor.element, 'find-and-replace:toggle-regex-option'); + it("places selected text into the replace editor and escapes it when Regex is enabled", async () => { + await atom.commands.dispatch(findView.replaceEditor.element, 'find-and-replace:toggle-regex-option'); editor.setSelectedBufferRange([[6, 6], [6, 65]]); - atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); + await atom.commands.dispatch(workspaceElement, 'find-and-replace:use-selection-as-replace-pattern'); expect(findView.replaceEditor.getText()).toBe('current < pivot \\? left\\.push\\(current\\) : right\\.push\\(current\\);'); }); }); - describe("when find-and-replace:find-next-selected is triggered", () => { - it("places the selected text into the find editor and finds the next occurrence", () => { + describe("when find-and-replace:find-next-selected is triggered", async () => { + it("places the selected text into the find editor and finds the next occurrence", async () => { editor.setSelectedBufferRange([[0, 9], [0, 13]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-next-selected"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-next-selected"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); - it("places the word under the cursor into the find editor and finds the next occurrence", () => { + it("places the word under the cursor into the find editor and finds the next occurrence", async () => { editor.setSelectedBufferRange([[1, 8], [1, 8]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-next-selected"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-next-selected"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[8, 11], [8, 15]]); }); }); describe("when find-and-replace:find-previous-selected is triggered", () => { - it("places the selected text into the find editor and finds the previous occurrence ", () => { + it("places the selected text into the find editor and finds the previous occurrence ", async () => { editor.setSelectedBufferRange([[0, 9], [0, 13]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-previous-selected"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-previous-selected"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[11, 9], [11, 13]]); }); - it("places the word under the cursor into the find editor and finds the previous occurrence", () => { + it("places the word under the cursor into the find editor and finds the previous occurrence", async () => { editor.setSelectedBufferRange([[8, 13], [8, 13]]); - atom.commands.dispatch(workspaceElement, "find-and-replace:find-previous-selected"); + await atom.commands.dispatch(workspaceElement, "find-and-replace:find-previous-selected"); expect(findView.findEditor.getText()).toBe("sort"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); }); - it("does not highlight the found text when the find view is hidden", () => { - atom.commands.dispatch(findView.findEditor.element, "core:cancel"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + it("does not highlight the found text when the find view is hidden", async () => { + await atom.commands.dispatch(findView.findEditor.element, "core:cancel"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); }); describe("when the active pane item changes", () => { @@ -920,7 +920,7 @@ describe("FindView", () => { it("highlights the found text in the new editor when find next is triggered", async () => { await atom.workspace.open("sample.coffee"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); const newEditor = atom.workspace.getCenter().getActiveTextEditor(); expect(getResultDecorations(newEditor, "find-result")).toHaveLength(6); expect(getResultDecorations(newEditor, "current-result")).toHaveLength(1); @@ -928,8 +928,8 @@ describe("FindView", () => { }); describe("when all active pane items are closed", () => { - it("updates the result count", () => { - atom.commands.dispatch(editorView, "core:close"); + it("updates the result count", async () => { + await atom.commands.dispatch(editorView, "core:close"); expect(findView.refs.resultCounter.textContent).toEqual("no results"); }); }); @@ -984,7 +984,7 @@ describe("FindView", () => { expect(findView.refs.resultCounter.textContent).toEqual("7 found"); expect(newEditor.getSelectedBufferRange()).toEqual([[0, 0], [0, 0]]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-next"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 7"); expect(newEditor.getSelectedBufferRange()).toEqual([[1, 9], [1, 14]]); }); @@ -1002,7 +1002,7 @@ describe("FindView", () => { originalPane.moveItemToPane(newEditor, splitPane, 0); expect(getResultDecorations(newEditor, "find-result")).toHaveLength(7); - atom.commands.dispatch(editor.element, "core:close"); + await atom.commands.dispatch(editor.element, "core:close"); editorView.focus(); expect(atom.workspace.getCenter().getActiveTextEditor()).toBe(editor); expect(getResultDecorations(editor, "find-result")).toHaveLength(6); @@ -1022,10 +1022,10 @@ describe("FindView", () => { expect(findView.refs.resultCounter.textContent).toEqual("6 found"); }); - it("does not beep if no matches were found", () => { + it("does not beep if no matches were found", async () => { editor.setCursorBufferPosition([2, 0]); findView.findEditor.setText("notinthefilebro"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); atom.beep.reset(); editor.insertText("blah blah"); expect(atom.beep).not.toHaveBeenCalled(); @@ -1037,9 +1037,9 @@ describe("FindView", () => { editor.setSelectedBufferRange([[2, 0], [4, 0]]); }); - it("toggles find within a selection via an event and only finds matches within the selection", () => { + it("toggles find within a selection via an event and only finds matches within the selection", async () => { findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); expect(editor.getSelectedBufferRange()).toEqual([[2, 0], [4, 0]]); expect(findView.refs.resultCounter.textContent).toEqual("3 found"); }); @@ -1056,9 +1056,9 @@ describe("FindView", () => { editor.setSelectedBufferRange([[0, 0], [0, 0]]); }); - it("toggles find within a selection via an event", () => { + it("toggles find within a selection via an event", async () => { findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); expect(editor.getSelectedBufferRange()).toEqual([[1, 22], [1, 27]]); expect(findView.refs.resultCounter.textContent).toEqual("1 of 6"); }); @@ -1066,9 +1066,9 @@ describe("FindView", () => { }); describe("when regex is toggled", () => { - it("toggles regex via an event and finds text matching the pattern", () => { + it("toggles regex via an event and finds text matching the pattern", async () => { editor.setCursorBufferPosition([2, 0]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("i[t]em+s"); expect(editor.getSelectedBufferRange()).toEqual([[2, 8], [2, 13]]); }); @@ -1080,19 +1080,19 @@ describe("FindView", () => { expect(editor.getSelectedBufferRange()).toEqual([[2, 8], [2, 13]]); }); - it("re-runs the search using the new find text when toggled", () => { + it("re-runs the search using the new find text when toggled", async () => { editor.setCursorBufferPosition([1, 0]); findView.findEditor.setText("s(o)rt"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); describe("when an invalid regex is entered", () => { - it("displays an error", () => { + it("displays an error", async () => { editor.setCursorBufferPosition([2, 0]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("i[t"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(findView.refs.descriptionLabel).toHaveClass("text-error"); }); }); @@ -1127,45 +1127,45 @@ describe("FindView", () => { }); }); - it("matches astral-plane unicode characters with .", () => { + it("matches astral-plane unicode characters with .", async () => { if (!editor.getBuffer().hasAstral) { console.log('Skipping astral-plane test case') return } editor.setText("\n\nbefore😄after\n\n"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("before.after"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[2, 0], [2, 13]]) }); }); describe("when whole-word is toggled", () => { - it("toggles whole-word via an event and finds text matching the pattern", () => { + it("toggles whole-word via an event and finds text matching the pattern", async () => { editor.setCursorBufferPosition([0, 0]); findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[0, 9], [0, 13]]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); - it("toggles whole-word via a button and finds text matching the pattern", () => { + it("toggles whole-word via a button and finds text matching the pattern", async () => { editor.setCursorBufferPosition([0, 0]); findView.findEditor.setText("sort"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[0, 9], [0, 13]]); findView.refs.wholeWordOptionButton.click(); expect(editor.getSelectedBufferRange()).toEqual([[1, 6], [1, 10]]); }); - it("re-runs the search using the new find text when toggled", () => { + it("re-runs the search using the new find text when toggled", async () => { editor.setCursorBufferPosition([8, 0]); findView.findEditor.setText("apply"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-whole-word-option"); expect(editor.getSelectedBufferRange()).toEqual([[11, 20], [11, 25]]); }); @@ -1207,19 +1207,19 @@ describe("FindView", () => { editor.setCursorBufferPosition([0, 0]); }); - it("toggles case sensitivity via an event and finds text matching the pattern", () => { + it("toggles case sensitivity via an event and finds text matching the pattern", async () => { findView.findEditor.setText("WORDs"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 0], [1, 5]]); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-case-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-case-option"); expect(editor.getSelectedBufferRange()).toEqual([[2, 0], [2, 5]]); }); - it("toggles case sensitivity via a button and finds text matching the pattern", () => { + it("toggles case sensitivity via a button and finds text matching the pattern", async () => { findView.findEditor.setText("WORDs"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(editor.getSelectedBufferRange()).toEqual([[1, 0], [1, 5]]); editor.setCursorBufferPosition([0, 0]); @@ -1258,7 +1258,7 @@ describe("FindView", () => { }); }); - it("finds unicode characters with case folding", () => { + it("finds unicode characters with case folding", async () => { if (!editor.getBuffer().hasAstral) { console.log('Skipping unicode test case') return @@ -1266,7 +1266,7 @@ describe("FindView", () => { editor.setText("---\n> április\n---\n") findView.findEditor.setText("Április") - atom.commands.dispatch(findView.findEditor.element, "core:confirm") + await atom.commands.dispatch(findView.findEditor.element, "core:confirm") expect(editor.getSelectedBufferRange()).toEqual([[1, 2], [1, 9]]) }); }); @@ -1276,24 +1276,24 @@ describe("FindView", () => { return getResultDecorations(editor, clazz)[0]; } - it("only highlights matches", () => { + it("only highlights matches", async () => { expect(getResultDecorations(editor, "find-result")).toHaveLength(5); findView.findEditor.setText("notinthefilebro"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(0); }); - it("adds a class to the current match indicating it is the current match", () => { + it("adds a class to the current match indicating it is the current match", async () => { const firstResultMarker = getResultDecoration("current-result"); expect(getResultDecorations(editor, "find-result")).toHaveLength(5); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); const nextResultMarker = getResultDecoration("current-result"); expect(nextResultMarker).not.toEqual(firstResultMarker); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:find-previous"); const originalResultMarker = getResultDecoration("current-result"); expect(originalResultMarker).toEqual(firstResultMarker); }); @@ -1409,19 +1409,19 @@ describe("FindView", () => { expect(findView.element).toHaveFocus(); }); - it("doesn't live search on a regex that matches empty string", () => { + it("doesn't live search on a regex that matches empty string", async () => { expect(findView.refs.descriptionLabel.textContent).toContain("6 results"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("asdf|"); advance(); expect(findView.refs.descriptionLabel.textContent).toContain("6 results"); }); - it("doesn't live search on a invalid regex", () => { + it("doesn't live search on a invalid regex", async () => { expect(findView.refs.descriptionLabel.textContent).toContain("6 results"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("\\(.*)"); advance(); expect(findView.refs.descriptionLabel).toHaveClass("text-error"); @@ -1430,26 +1430,26 @@ describe("FindView", () => { }); describe("when another find is called", () => { - it("clears existing markers for another search", () => { + it("clears existing markers for another search", async () => { findView.findEditor.setText("notinthefile"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(0); }); - it("clears existing markers for an empty search", () => { + it("clears existing markers for an empty search", async () => { findView.findEditor.setText(""); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); expect(getResultDecorations(editor, "find-result")).toHaveLength(0); }); }); }); it("doesn't throw an exception when toggling the regex option with an invalid pattern before performing any other search (regression)", async () => { - atom.commands.dispatch(editorView, 'find-and-replace:show'); + await atom.commands.dispatch(editorView, 'find-and-replace:show'); await activationPromise; findView.findEditor.setText('('); - atom.commands.dispatch(findView.findEditor.element, 'find-and-replace:toggle-regex-option'); + await atom.commands.dispatch(findView.findEditor.element, 'find-and-replace:toggle-regex-option'); editor.insertText('hi'); advanceClock(editor.getBuffer().stoppedChangingDelay); @@ -1458,7 +1458,7 @@ describe("FindView", () => { describe("replacing", () => { beforeEach(async () => { editor.setCursorBufferPosition([2, 0]); - atom.commands.dispatch(editorView, "find-and-replace:show-replace"); + await atom.commands.dispatch(editorView, "find-and-replace:show-replace"); await activationPromise; @@ -1467,44 +1467,44 @@ describe("FindView", () => { }); describe("when the find string is empty", () => { - it("beeps", () => { + it("beeps", async () => { findView.findEditor.setText(""); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(atom.beep).toHaveBeenCalled(); }); }); describe("when the replacement string contains an escaped char", () => { describe("when the regex option is chosen", () => { - beforeEach(() => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + beforeEach(async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); }); - it("inserts newlines and tabs", () => { + it("inserts newlines and tabs", async () => { findView.replaceEditor.setText("\\n\\t"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(editor.getText()).toMatch(/\n\t/); }); - it("doesn't insert a escaped char if there are multiple backslashes in front of the char", () => { + it("doesn't insert a escaped char if there are multiple backslashes in front of the char", async () => { findView.replaceEditor.setText("\\\\t\\\t"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(editor.getText()).toMatch(/\\t\\\t/); }); }); describe("when in normal mode", () => { - it("inserts backslash n and t", () => { + it("inserts backslash n and t", async () => { findView.replaceEditor.setText("\\t\\n"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(editor.getText()).toMatch(/\\t\\n/); }); - it("inserts carriage returns", () => { + it("inserts carriage returns", async () => { const textWithCarriageReturns = editor.getText().replace(/\n/g, "\r"); editor.setText(textWithCarriageReturns); findView.replaceEditor.setText("\\t\\r"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(editor.getText()).toMatch(/\\t\\r/); }); }); @@ -1512,36 +1512,36 @@ describe("FindView", () => { describe("replace next", () => { describe("when core:confirm is triggered", () => { - it("replaces the match after the cursor and selects the next match", () => { - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + it("replaces the match after the cursor and selects the next match", async () => { + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(findView.refs.resultCounter.textContent).toEqual("2 of 5"); expect(editor.lineTextForBufferRow(2)).toBe(" if (cats.length <= 1) return items;"); expect(editor.getSelectedBufferRange()).toEqual([[2, 33], [2, 38]]); }); - it("replaceEditor maintains focus after core:confirm is run", () => { + it("replaceEditor maintains focus after core:confirm is run", async () => { findView.replaceEditor.element.focus(); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(findView.replaceEditor.element).toHaveFocus(); }); - it("replaces the _current_ match and selects the next match", () => { - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + it("replaces the _current_ match and selects the next match", async () => { + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); editor.setSelectedBufferRange([[2, 8], [2, 13]]); expect(findView.refs.resultCounter.textContent).toEqual("2 of 6"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(findView.refs.resultCounter.textContent).toEqual("2 of 5"); expect(editor.lineTextForBufferRow(2)).toBe(" if (cats.length <= 1) return items;"); expect(editor.getSelectedBufferRange()).toEqual([[2, 33], [2, 38]]); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(findView.refs.resultCounter.textContent).toEqual("2 of 4"); expect(editor.lineTextForBufferRow(2)).toBe(" if (cats.length <= 1) return cats;"); expect(editor.getSelectedBufferRange()).toEqual([[3, 16], [3, 21]]); }); - it("replaces the _current_ match and selects the next match", () => { + it("replaces the _current_ match and selects the next match", async () => { editor.setText( "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s" ); @@ -1549,7 +1549,7 @@ describe("FindView", () => { editor.setSelectedBufferRange([[0, 0], [0, 5]]); findView.findEditor.setText("Lorem"); findView.replaceEditor.setText("replacement"); - atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.replaceEditor.element, "core:confirm"); expect(editor.lineTextForBufferRow(0)).toBe( "replacement Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s" @@ -1570,8 +1570,8 @@ describe("FindView", () => { }); describe("when the 'find-and-replace:replace-next' event is triggered", () => { - it("replaces the match after the cursor and selects the next match", () => { - atom.commands.dispatch(editorView, "find-and-replace:replace-next"); + it("replaces the match after the cursor and selects the next match", async () => { + await atom.commands.dispatch(editorView, "find-and-replace:replace-next"); expect(findView.refs.resultCounter.textContent).toEqual("2 of 5"); expect(editor.lineTextForBufferRow(2)).toBe(" if (cats.length <= 1) return items;"); expect(editor.getSelectedBufferRange()).toEqual([[2, 33], [2, 38]]); @@ -1581,9 +1581,9 @@ describe("FindView", () => { describe("replace previous", () => { describe("when command is triggered", () => { - it("replaces the match after the cursor and selects the previous match", () => { - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); - atom.commands.dispatch(findView.element, "find-and-replace:replace-previous"); + it("replaces the match after the cursor and selects the previous match", async () => { + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.element, "find-and-replace:replace-previous"); expect(findView.refs.resultCounter.textContent).toEqual("1 of 5"); expect(editor.lineTextForBufferRow(2)).toBe(" if (cats.length <= 1) return items;"); expect(editor.getSelectedBufferRange()).toEqual([[1, 22], [1, 27]]); @@ -1609,8 +1609,8 @@ describe("FindView", () => { }); describe("when the 'find-and-replace:replace-all' event is triggered", () => { - it("replaces all matched text", () => { - atom.commands.dispatch(editorView, "find-and-replace:replace-all"); + it("replaces all matched text", async () => { + await atom.commands.dispatch(editorView, "find-and-replace:replace-all"); expect(findView.refs.resultCounter.textContent).toEqual("no results"); expect(editor.getText()).not.toMatch(/items/); expect(editor.getText().match(/\bcats\b/g)).toHaveLength(6); @@ -1621,21 +1621,21 @@ describe("FindView", () => { describe("replacement patterns", () => { describe("when the regex option is true", () => { - it("replaces $1, $2, etc... with substring matches", () => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + it("replaces $1, $2, etc... with substring matches", async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); findView.findEditor.setText("(items)([\\.;])"); findView.replaceEditor.setText("$2$1"); - atom.commands.dispatch(editorView, "find-and-replace:replace-all"); + await atom.commands.dispatch(editorView, "find-and-replace:replace-all"); expect(editor.getText()).toMatch(/;items/); expect(editor.getText()).toMatch(/\.items/); }); }); describe("when the regex option is false", () => { - it("replaces the matches with without any regex subsitions", () => { + it("replaces the matches with without any regex subsitions", async () => { findView.findEditor.setText("items"); findView.replaceEditor.setText("$&cats"); - atom.commands.dispatch(editorView, "find-and-replace:replace-all"); + await atom.commands.dispatch(editorView, "find-and-replace:replace-all"); expect(editor.getText()).not.toMatch(/items/); expect(editor.getText().match(/\$&cats\b/g)).toHaveLength(6); }); @@ -1645,18 +1645,18 @@ describe("FindView", () => { describe("history", () => { beforeEach(async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; }); describe("when there is no history", () => { - it("retains unsearched text", () => { + it("retains unsearched text", async () => { const text = "something I want to search for but havent yet"; findView.findEditor.setText(text); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual(""); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual(text); }); }); @@ -1664,68 +1664,68 @@ describe("FindView", () => { describe("when there is history", () => { const [oneRange, twoRange, threeRange] = []; - beforeEach(() => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + beforeEach(async () => { + await atom.commands.dispatch(editorView, "find-and-replace:show"); editor.setText("zero\none\ntwo\nthree\n"); findView.findEditor.setText("one"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); findView.findEditor.setText("two"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); findView.findEditor.setText("three"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); }); - it("can navigate the entire history stack", () => { + it("can navigate the entire history stack", async () => { expect(findView.findEditor.getText()).toEqual("three"); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual(""); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual(""); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("three"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("two"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("one"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("one"); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual("two"); }); - it("retains the current unsearched text", () => { + it("retains the current unsearched text", async () => { const text = "something I want to search for but havent yet"; findView.findEditor.setText(text); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("three"); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual(text); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("three"); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); - atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-down"); expect(findView.findEditor.getText()).toEqual(""); }); - it("adds confirmed patterns to the history", () => { + it("adds confirmed patterns to the history", async () => { findView.findEditor.setText("cool stuff"); - atom.commands.dispatch(findView.findEditor.element, "core:confirm"); + await atom.commands.dispatch(findView.findEditor.element, "core:confirm"); findView.findEditor.setText("cooler stuff"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("cool stuff"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("three"); }); @@ -1738,7 +1738,7 @@ describe("FindView", () => { findView.findEditor.element.focus(); }); - it("does not add live searches to the history", () => { + it("does not add live searches to the history", async () => { expect(findView.refs.descriptionLabel.textContent).toContain("1 result"); findView.findEditor.setText("FIXME: necessary search for some reason??"); @@ -1751,7 +1751,7 @@ describe("FindView", () => { advance(); expect(findView.refs.descriptionLabel.textContent).toContain("zero"); - atom.commands.dispatch(findView.findEditor.element, "core:move-up"); + await atom.commands.dispatch(findView.findEditor.element, "core:move-up"); expect(findView.findEditor.getText()).toEqual("three"); }); }); @@ -1760,7 +1760,7 @@ describe("FindView", () => { describe("panel focus", () => { beforeEach(async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; }); @@ -1771,16 +1771,16 @@ describe("FindView", () => { expect(findView.findEditor.element).toHaveFocus(); }); - it("moves focus between editors with find-and-replace:focus-next", () => { + it("moves focus between editors with find-and-replace:focus-next", async () => { findView.findEditor.element.focus(); expect(findView.findEditor.element).toHaveClass("is-focused"); expect(findView.replaceEditor).not.toHaveClass("is-focused"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:focus-next"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:focus-next"); expect(findView.findEditor.element).not.toHaveClass("is-focused"); expect(findView.replaceEditor.element).toHaveClass("is-focused"); - atom.commands.dispatch(findView.replaceEditor.element, "find-and-replace:focus-next"); + await atom.commands.dispatch(findView.replaceEditor.element, "find-and-replace:focus-next"); expect(findView.findEditor.element).toHaveClass("is-focused"); expect(findView.replaceEditor.element).not.toHaveClass("is-focused"); }); @@ -1793,7 +1793,7 @@ describe("FindView", () => { it("uses the regexp grammar when regex-mode is loaded from configuration", async () => { atom.config.set("find-and-replace.useRegex", true); - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; expect(findView.model.getFindOptions().useRegex).toBe(true); @@ -1801,9 +1801,9 @@ describe("FindView", () => { expect(findView.replaceEditor.getGrammar().scopeName).toBe("source.js.regexp.replacement"); }); - describe("when panel is active", () => { + describe("when panel is active", async () => { beforeEach(async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); await activationPromise; }); @@ -1813,13 +1813,13 @@ describe("FindView", () => { expect(findView.replaceEditor.getGrammar().scopeName).toBe("text.plain.null-grammar"); }); - it("uses regexp grammar when in regex mode and clears the regexp grammar when regex is disabled", () => { - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + it("uses regexp grammar when in regex mode and clears the regexp grammar when regex is disabled", async () => { + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); expect(findView.model.getFindOptions().useRegex).toBe(true); expect(findView.findEditor.getGrammar().scopeName).toBe("source.js.regexp"); expect(findView.replaceEditor.getGrammar().scopeName).toBe("source.js.regexp.replacement"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); expect(findView.model.getFindOptions().useRegex).not.toBe(true); expect(findView.findEditor.getGrammar().scopeName).toBe("text.plain.null-grammar"); expect(findView.replaceEditor.getGrammar().scopeName).toBe("text.plain.null-grammar"); @@ -1829,23 +1829,23 @@ describe("FindView", () => { describe("when no buffer is open", () => { it("toggles regex via an event and finds text matching the pattern", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); editor.destroy(); await activationPromise; findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-regex-option"); expect(findView.model.getFindOptions().useRegex).toBe(true); expect(findView.refs.descriptionLabel.textContent).toContain("No results"); }); it("toggles selection via an event and finds text matching the pattern", async () => { - atom.commands.dispatch(editorView, "find-and-replace:show"); + await atom.commands.dispatch(editorView, "find-and-replace:show"); editor.destroy(); await activationPromise; findView.findEditor.setText("items"); - atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); + await atom.commands.dispatch(findView.findEditor.element, "find-and-replace:toggle-selection-option"); expect(findView.model.getFindOptions().inCurrentSelection).toBe(true); expect(findView.refs.descriptionLabel.textContent).toContain("No results"); }); diff --git a/spec/project-find-view-spec.js b/spec/project-find-view-spec.js index d83b0bf3..574698f9 100644 --- a/spec/project-find-view-spec.js +++ b/spec/project-find-view-spec.js @@ -328,7 +328,7 @@ describe(`ProjectFindView (ripgrep=${ripgrep})`, () => { expect(resultsView.refs.listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(3); }); - it("doesn't insert a escaped char if there are multiple backslashs in front of the char", async () => { + it("doesn't insert a escaped char if there are multiple backslashes in front of the char", async () => { projectFindView.findEditor.setText('\\\\t'); atom.commands.dispatch(projectFindView.element, 'core:confirm'); diff --git a/spec/results-view-spec.js b/spec/results-view-spec.js index f17ca8a7..07c7fe53 100644 --- a/spec/results-view-spec.js +++ b/spec/results-view-spec.js @@ -83,7 +83,7 @@ describe('ResultsView', () => { }); }); - atom.commands.dispatch(workspaceElement, 'project-find:show'); + await atom.commands.dispatch(workspaceElement, 'project-find:show'); await activationPromise; }); @@ -91,7 +91,7 @@ describe('ResultsView', () => { describe("when the result is for a long line", () => { it("renders the context around the match", async () => { projectFindView.findEditor.setText('ghijkl'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -109,7 +109,7 @@ describe('ResultsView', () => { it("includes the basename of the project path that contains the match", async () => { projectFindView.findEditor.setText('ghijkl'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -127,7 +127,7 @@ describe('ResultsView', () => { it("renders the replacement when doing a search and there is a replacement pattern", async () => { projectFindView.replaceEditor.setText('cats'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -138,7 +138,7 @@ describe('ResultsView', () => { }); it("renders the replacement when changing the text in the replacement field", async () => { - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -169,7 +169,7 @@ describe('ResultsView', () => { projectFindView.refs.regexOptionButton.click(); projectFindView.findEditor.setText('function ?(\\([^)]*\\))'); projectFindView.replaceEditor.setText('$1 =>') - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -320,7 +320,7 @@ describe('ResultsView', () => { it("selects the path when when core:move-to-top is triggered and first item is collapsed", async () => { await resultsView.moveToTop(); - atom.commands.dispatch(resultsView.element, 'core:move-left'); + await atom.commands.dispatch(resultsView.element, 'core:move-left'); await resultsView.moveToTop(); expect(resultsView.refs.listView.element.querySelector('.path-row').parentElement).toHaveClass('selected'); @@ -330,7 +330,7 @@ describe('ResultsView', () => { describe("expanding and collapsing results", () => { it('preserves the selected file when collapsing all results', async () => { projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -368,7 +368,7 @@ describe('ResultsView', () => { it('re-expands all results when running a new search', async () => { projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -377,7 +377,7 @@ describe('ResultsView', () => { expect(resultsView.element.querySelector('.collapsed')).not.toBe(null); projectFindView.findEditor.setText('sort'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; expect(resultsView.element.querySelector('.collapsed')).toBe(null); @@ -385,7 +385,7 @@ describe('ResultsView', () => { it('preserves the collapsed state of the right files when results are removed', async () => { projectFindView.findEditor.setText('push'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -405,7 +405,7 @@ describe('ResultsView', () => { it('preserves the collapsed state of the right files when results are added', async () => { projectFindView.findEditor.setText('push'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -431,7 +431,7 @@ describe('ResultsView', () => { it("does not contract result when right clicked", async () => { projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -443,7 +443,7 @@ describe('ResultsView', () => { it("does not expand result when right clicked", async () => { projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -460,7 +460,7 @@ describe('ResultsView', () => { await atom.workspace.open('sample.js'); projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -482,14 +482,14 @@ describe('ResultsView', () => { // open something in sample.coffee resultsView.element.focus(); _.times(3, () => atom.commands.dispatch(resultsView.element, 'core:move-down')); - atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); await paneItemOpening() expect(atom.workspace.getCenter().getActivePaneItem().getPath()).toContain('sample.'); // open something in sample.js resultsView.element.focus(); _.times(6, () => atom.commands.dispatch(resultsView.element, 'core:move-down')); - atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); await paneItemOpening() expect(atom.workspace.getCenter().getActivePaneItem().getPath()).toContain('sample.'); }); @@ -522,7 +522,7 @@ describe('ResultsView', () => { it("opens the file in a new non-active tab on 'find-and-replace:open-in-new-tab'", async () => { const resultsPane = atom.workspace.paneForURI(ResultsPaneView.URI); const preEditors = atom.workspace.getTextEditors(); // keep track of editor list before command execution - atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); await paneItemOpening(); const postEditors = atom.workspace.getTextEditors(); // editors after command execution const found = _.find(postEditors, (editor) => { @@ -537,9 +537,9 @@ describe('ResultsView', () => { }); it("brings an already opened tab into focus on 'find-and-replace:open-in-new-tab'", async () => { - atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); await paneItemOpening(); - atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:open-in-new-tab'); await paneItemOpening(); expect(atom.workspace.getCenter().getActivePaneItem().getPath()).toContain('sample.'); }) @@ -548,7 +548,7 @@ describe('ResultsView', () => { spyOn(resultsView,'setScrollTop').andCallThrough(); projectFindView.findEditor.setText('1'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView.moveToBottom(); @@ -567,24 +567,24 @@ describe('ResultsView', () => { it("does not create a split when the option is 'none'", async () => { atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'none'); - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); await paneItemOpening() expect(atom.workspace.open.mostRecentCall.args[1].split).toBeUndefined(); }); it("always opens the file in the left pane when the option is 'right'", async () => { atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'right'); - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); await paneItemOpening() expect(atom.workspace.open.mostRecentCall.args[1].split).toBe('left'); }); it("always opens the file in the pane above when the options is 'down'", async () => { atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'down') - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); await paneItemOpening() expect(atom.workspace.open.mostRecentCall.args[1].split).toBe('up'); }); @@ -596,7 +596,7 @@ describe('ResultsView', () => { await atom.workspace.open('sample.js'); projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -644,7 +644,7 @@ describe('ResultsView', () => { describe("when there are a list of items", () => { beforeEach(async () => { projectFindView.findEditor.setText('items'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); }); @@ -713,13 +713,13 @@ describe('ResultsView', () => { describe("when the results view is empty", () => { it("ignores core:confirm and other commands for selecting results", async () => { const resultsView = buildResultsView({ empty: true }); - atom.commands.dispatch(resultsView.element, 'core:confirm'); - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'core:move-up'); - atom.commands.dispatch(resultsView.element, 'core:move-to-top'); - atom.commands.dispatch(resultsView.element, 'core:move-to-bottom'); - atom.commands.dispatch(resultsView.element, 'core:page-down'); - atom.commands.dispatch(resultsView.element, 'core:page-up'); + await atom.commands.dispatch(resultsView.element, 'core:confirm'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'core:move-up'); + await atom.commands.dispatch(resultsView.element, 'core:move-to-top'); + await atom.commands.dispatch(resultsView.element, 'core:move-to-bottom'); + await atom.commands.dispatch(resultsView.element, 'core:page-down'); + await atom.commands.dispatch(resultsView.element, 'core:page-up'); }); it("won't show the preview-controls", async () => { @@ -729,32 +729,32 @@ describe('ResultsView', () => { }); describe("copying items with core:copy", () => { - it("copies the selected line onto the clipboard", () => { + it("copies the selected line onto the clipboard", async () => { const resultsView = buildResultsView(); resultsView.selectFirstResult(); _.times(3, () => atom.commands.dispatch(resultsView.element, 'core:move-down')); - atom.commands.dispatch(resultsView.element, 'core:copy'); + await atom.commands.dispatch(resultsView.element, 'core:copy'); expect(atom.clipboard.read()).toBe('goodnight moon'); }); }); describe("copying path with find-and-replace:copy-path", () => { - it("copies the selected file path to clipboard", () => { + it("copies the selected file path to clipboard", async () => { const resultsView = buildResultsView(); resultsView.selectFirstResult(); // await resultsView.collapseResult(); - atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); expect(atom.clipboard.read()).toBe('/a/b.txt'); - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'core:move-down'); - atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'core:move-down'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); expect(atom.clipboard.read()).toBe('/c/d.txt'); - atom.commands.dispatch(resultsView.element, 'core:move-up'); - atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); + await atom.commands.dispatch(resultsView.element, 'core:move-up'); + await atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path'); expect(atom.clipboard.read()).toBe('/a/b.txt'); }); }); @@ -801,7 +801,7 @@ describe('ResultsView', () => { expect(getIconServices().fileIcons).toBe(provider) projectFindView.findEditor.setText('i'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -812,7 +812,7 @@ describe('ResultsView', () => { disposable.dispose(); projectFindView.findEditor.setText('e'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -846,17 +846,17 @@ describe('ResultsView', () => { } let disposable - waitsForPromise(() => { + waitsForPromise(async () => { disposable = atom.packages.serviceHub.provide('file-icons.element-icons', '1.0.0', provider) expect(getIconServices().elementIcons).toBe(provider) projectFindView.findEditor.setText('i'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); return searchPromise }) waitsForPromise(() => delayFor(35)) - runs(() => { + runs(async () => { resultsView = getResultsView() const iconElements = resultsView.element.querySelectorAll(iconSelector) expect(iconElements[0].className.trim()).toBe('icon foo bar') @@ -865,7 +865,7 @@ describe('ResultsView', () => { disposable.dispose() projectFindView.findEditor.setText('e') - atom.commands.dispatch(projectFindView.element, 'core:confirm') + await atom.commands.dispatch(projectFindView.element, 'core:confirm') }) waitsForPromise(() => searchPromise) @@ -886,7 +886,7 @@ describe('ResultsView', () => { describe('updating the search while viewing results', () => { it('resets the results message', async () => { projectFindView.findEditor.setText('a'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; const resultsPane = getResultsPane(); @@ -894,7 +894,7 @@ describe('ResultsView', () => { expect(resultsPane.refs.previewCount.textContent).toContain('3 files'); projectFindView.findEditor.setText(''); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await etch.update(resultsPane); expect(resultsPane.refs.previewCount.textContent).toContain('Project search results'); }) @@ -908,7 +908,7 @@ describe('ResultsView', () => { atom.config.set('find-and-replace.trailingContextLineCount', 0); projectFindView.findEditor.setText('items.'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); @@ -980,7 +980,7 @@ describe('ResultsView', () => { describe('selected result and match index', () => { beforeEach(async () => { projectFindView.findEditor.setText('push'); - atom.commands.dispatch(projectFindView.element, 'core:confirm'); + await atom.commands.dispatch(projectFindView.element, 'core:confirm'); await searchPromise; resultsView = getResultsView(); diff --git a/spec/select-next-spec.js b/spec/select-next-spec.js index 566633e1..338c546e 100644 --- a/spec/select-next-spec.js +++ b/spec/select-next-spec.js @@ -15,15 +15,15 @@ describe("SelectNext", () => { jasmine.attachToDOM(workspaceElement); const activationPromise = atom.packages.activatePackage("find-and-replace"); - atom.commands.dispatch(editorElement, 'find-and-replace:show'); + await atom.commands.dispatch(editorElement, 'find-and-replace:show'); await activationPromise; }); describe("find-and-replace:select-next", () => { describe("when nothing is selected", () => { - it("selects the word under the cursor", () => { + it("selects the word under the cursor", async () => { editor.setCursorBufferPosition([1, 3]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([[[1, 2], [1, 5]]]); }); }); @@ -41,25 +41,25 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], @@ -69,18 +69,18 @@ describe("SelectNext", () => { editor.setText("Testing reallyTesting"); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 7]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 7]] ]);});}); describe("when the selection was not created using select-next", () => { - it("selects the next occurrence of the selected characters including non-word matches", () => { + it("selects the next occurrence of the selected characters including non-word matches", async () => { editor.setText(dedent` for information @@ -92,20 +92,20 @@ describe("SelectNext", () => { editor.setSelectedBufferRange([[0, 0], [0, 3]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[1, 2], [1, 5]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[1, 2], [1, 5]], [[2, 0], [2, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[1, 2], [1, 5]], @@ -116,7 +116,7 @@ describe("SelectNext", () => { editor.setText("Testing reallyTesting"); editor.setSelectedBufferRange([[0, 0], [0, 7]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 7]], [[0, 14], [0, 21]] @@ -126,7 +126,7 @@ describe("SelectNext", () => { }); describe("when part of a word is selected", () => { - it("selects the next occurrence of the selected text", () => { + it("selects the next occurrence of the selected text", async () => { editor.setText(dedent` for information @@ -138,20 +138,20 @@ describe("SelectNext", () => { editor.setSelectedBufferRange([[1, 2], [1, 5]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 2], [1, 5]], [[2, 0], [2, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 2], [1, 5]], [[2, 0], [2, 3]], [[3, 8], [3, 11]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 2], [1, 5]], [[2, 0], [2, 3]], @@ -159,7 +159,7 @@ describe("SelectNext", () => { [[4, 0], [4, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 2], [1, 5]], [[2, 0], [2, 3]], @@ -168,7 +168,7 @@ describe("SelectNext", () => { [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[1, 2], [1, 5]], [[2, 0], [2, 3]], @@ -181,13 +181,13 @@ describe("SelectNext", () => { }); describe("when a non-word is selected", () => { - it("selects the next occurrence of the selected text", () => { + it("selects the next occurrence of the selected text", async () => { editor.setText(dedent` { }); describe("when the word is at a line boundary", () => { - it("does not select the newlines", () => { + it("does not select the newlines", async () => { editor.setText(dedent` a a `); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 1]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 1]], [[2, 0], [2, 1]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 1]], [[2, 0], [2, 1]] @@ -222,25 +222,25 @@ describe("SelectNext", () => { }); }); - it('honors the reversed orientation of previous selections', () => { + it('honors the reversed orientation of previous selections', async () => { editor.setText('ab ab ab ab') editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: true}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') expect(editor.getSelections().length).toBe(2) expect(editor.getSelections().every(s => s.isReversed())).toBe(true) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') expect(editor.getSelections().length).toBe(3) expect(editor.getSelections().every(s => s.isReversed())).toBe(true) editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: false}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') expect(editor.getSelections().length).toBe(2) expect(editor.getSelections().every(s => !s.isReversed())).toBe(true) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') expect(editor.getSelections().length).toBe(3) expect(editor.getSelections().every(s => !s.isReversed())).toBe(true) }) @@ -248,7 +248,7 @@ describe("SelectNext", () => { describe("find-and-replace:select-all", () => { describe("when there is no selection", () => { - it("find and selects all occurrences of the word under the cursor", () => { + it("find and selects all occurrences of the word under the cursor", async () => { editor.setText(dedent` for information @@ -258,14 +258,14 @@ describe("SelectNext", () => { a 3rd for is here `); - atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], @@ -276,7 +276,7 @@ describe("SelectNext", () => { describe("when a word is selected", () => { describe("when the word was selected using select-next", () => { - it("find and selects all occurrences of the word", () => { + it("find and selects all occurrences of the word", async () => { editor.setText(dedent` for information @@ -286,14 +286,14 @@ describe("SelectNext", () => { a 3rd for is here `); - atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]], @@ -303,7 +303,7 @@ describe("SelectNext", () => { }); describe("when the word was not selected using select-next", () => { - it("find and selects all occurrences including non-words", () => { + it("find and selects all occurrences including non-words", async () => { editor.setText(dedent` for information @@ -315,7 +315,7 @@ describe("SelectNext", () => { editor.setSelectedBufferRange([[3, 8], [3, 11]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all'); expect(editor.getSelectedBufferRanges()).toEqual([ [[3, 8], [3, 11]], [[0, 0], [0, 3]], @@ -329,13 +329,13 @@ describe("SelectNext", () => { }); describe("when a non-word is selected", () => { - it("selects the next occurrence of the selected text", () => { + it("selects the next occurrence of the selected text", async () => { editor.setText(dedent` { }); }); - it('honors the reversed orientation of previous selections', () => { + it('honors the reversed orientation of previous selections', async () => { editor.setText('ab ab ab ab') editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: true}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-all') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all') expect(editor.getSelections().length).toBe(4) expect(editor.getSelections().every(s => s.isReversed())).toBe(true) editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: false}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-all') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-all') expect(editor.getSelections().length).toBe(4) expect(editor.getSelections().every(s => !s.isReversed())).toBe(true) }) @@ -371,7 +371,7 @@ describe("SelectNext", () => { a 3rd for is here `); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 0]] ]); @@ -379,7 +379,7 @@ describe("SelectNext", () => { }); describe("when a word is selected", () => { - it("unselects current word", () => { + it("unselects current word", async () => { editor.setText(dedent` for information @@ -391,7 +391,7 @@ describe("SelectNext", () => { editor.setSelectedBufferRange([[3, 8], [3, 11]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[3, 11], [3, 11]] ]); @@ -399,7 +399,7 @@ describe("SelectNext", () => { }); describe("when two words are selected", () => { - it("unselects words in order", () => { + it("unselects words in order", async () => { editor.setText(dedent` for information @@ -411,13 +411,13 @@ describe("SelectNext", () => { editor.setSelectedBufferRange([[3, 8], [3, 11]]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[3, 8], [3, 11]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[3, 11], [3, 11]] ]); @@ -425,7 +425,7 @@ describe("SelectNext", () => { }); describe("when three words are selected", () => { - it("unselects words in order", () => { + it("unselects words in order", async () => { editor.setText(dedent` for information @@ -436,17 +436,17 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[3, 8], [3, 11]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]] ]); @@ -454,7 +454,7 @@ describe("SelectNext", () => { }); describe("when starting at the bottom word", () => { - it("unselects words in order", () => { + it("unselects words in order", async () => { editor.setText(dedent` for information @@ -465,21 +465,21 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([5, 7]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]], [[0, 0], [0, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]] ]);}); - it("doesn't stack previously selected", () => { + it("doesn't stack previously selected", async () => { editor.setText(dedent` for information @@ -490,14 +490,14 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([5, 7]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-undo'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]], [[0, 0], [0, 3]] @@ -508,7 +508,7 @@ describe("SelectNext", () => { describe("find-and-replace:select-skip", () => { describe("when there is no selection", () => { - it("does nothing", () => { + it("does nothing", async () => { editor.setText(dedent` for information @@ -518,7 +518,7 @@ describe("SelectNext", () => { a 3rd for is here `); - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 0]] ]); @@ -526,7 +526,7 @@ describe("SelectNext", () => { }); describe("when a word is selected", () => { - it("unselects current word and selects next match", () => { + it("unselects current word and selects next match", async () => { editor.setText(dedent` for information @@ -537,12 +537,12 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([3, 8]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[3, 8], [3, 11]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]] ]); @@ -550,7 +550,7 @@ describe("SelectNext", () => { }); describe("when two words are selected", () => { - it("unselects second word and selects next match", () => { + it("unselects second word and selects next match", async () => { editor.setText(dedent` for information @@ -561,19 +561,19 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([0, 0]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]], [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); expect(editor.getSelectedBufferRanges()).toEqual([ [[0, 0], [0, 3]] ]); @@ -581,7 +581,7 @@ describe("SelectNext", () => { }); describe("when starting at the bottom word", () => { - it("unselects second word and selects next match", () => { + it("unselects second word and selects next match", async () => { editor.setText(dedent` for information @@ -592,12 +592,12 @@ describe("SelectNext", () => { `); editor.setCursorBufferPosition([5, 7]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]] ]); - atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next'); + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip'); expect(editor.getSelectedBufferRanges()).toEqual([ [[5, 6], [5, 9]], [[3, 8], [3, 11]] @@ -605,27 +605,27 @@ describe("SelectNext", () => { }); }); - it('honors the reversed orientation of previous selections', () => { + it('honors the reversed orientation of previous selections', async () => { editor.setText('ab ab ab ab') editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: true}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') expect(editor.getSelections().length).toBe(1) expect(editor.getSelections().every(s => s.isReversed())).toBe(true) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') expect(editor.getSelections().length).toBe(2) expect(editor.getSelections().every(s => s.isReversed())).toBe(true) editor.setSelectedBufferRange([[0, 0], [0, 2]], {reversed: false}) - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') expect(editor.getSelections().length).toBe(1) expect(editor.getSelections().every(s => !s.isReversed())).toBe(true) - atom.commands.dispatch(editorElement, 'find-and-replace:select-next') - atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-next') + await atom.commands.dispatch(editorElement, 'find-and-replace:select-skip') expect(editor.getSelections().length).toBe(2) expect(editor.getSelections().every(s => !s.isReversed())).toBe(true) })