Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit d62e08e

Browse files
author
Marcel Gerber
committed
Add unit tests
1 parent 8b595dc commit d62e08e

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/search/FindInFilesUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ define(function (require, exports, module) {
136136
// The modalBar was already up. When creating the new modalBar, copy the
137137
// current query instead of using the passed-in selected text.
138138
initialString = _findBar.getQueryInfo().query;
139-
} else {
139+
} else if (initialString) {
140140
// Eliminate newlines since we don't generally support searching across line boundaries (#2960)
141141
var newline = initialString.indexOf("\n");
142142
if (newline !== -1) {

test/spec/FindInFiles-test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,52 @@ define(function (require, exports, module) {
16991699
});
17001700

17011701
describe("Full workflow", function () {
1702+
it("should prepopulate the find bar with selected text", function () {
1703+
var doc, editor;
1704+
1705+
openTestProjectCopy(defaultSourcePath);
1706+
runs(function () {
1707+
waitsForDone(CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: testPath + "/foo.html" }), "open file");
1708+
});
1709+
runs(function () {
1710+
doc = DocumentManager.getOpenDocumentForPath(testPath + "/foo.html");
1711+
expect(doc).toBeTruthy();
1712+
DocumentManager.setCurrentDocument(doc);
1713+
editor = doc._masterEditor;
1714+
expect(editor).toBeTruthy();
1715+
editor.setSelection({line: 4, ch: 7}, {line: 4, ch: 10});
1716+
});
1717+
1718+
openSearchBar(null);
1719+
runs(function () {
1720+
expect($("#find-what").val()).toBe("Foo");
1721+
});
1722+
waitsForDone(CommandManager.execute(Commands.FILE_CLOSE_ALL), "closing all files");
1723+
});
1724+
1725+
it("should prepopulate the find bar with only first line of selected text", function () {
1726+
var doc, editor;
1727+
1728+
openTestProjectCopy(defaultSourcePath);
1729+
runs(function () {
1730+
waitsForDone(CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: testPath + "/foo.html" }), "open file");
1731+
});
1732+
runs(function () {
1733+
doc = DocumentManager.getOpenDocumentForPath(testPath + "/foo.html");
1734+
expect(doc).toBeTruthy();
1735+
DocumentManager.setCurrentDocument(doc);
1736+
editor = doc._masterEditor;
1737+
expect(editor).toBeTruthy();
1738+
editor.setSelection({line: 4, ch: 7}, {line: 6, ch: 10});
1739+
});
1740+
1741+
openSearchBar(null);
1742+
runs(function () {
1743+
expect($("#find-what").val()).toBe("Foo</title>");
1744+
});
1745+
waitsForDone(CommandManager.execute(Commands.FILE_CLOSE_ALL), "closing all files");
1746+
});
1747+
17021748
it("should show results from the search with all checkboxes checked", function () {
17031749
showSearchResults("foo", "bar");
17041750
runs(function () {

0 commit comments

Comments
 (0)