From e2db9348b6ff106d0cbad8d1c0afe67447712e4f Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Mon, 24 Mar 2014 15:29:24 -0700 Subject: [PATCH 01/11] initial query tests --- test/spec/FindReplace-test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 1c9cc97cb14..f8d382fcb11 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -787,6 +787,26 @@ define(function (require, exports, module) { expectSelection(barExpectedMatches[0]); }); + it("should use empty initial query for single cursor selection", function () { + myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}); + twCommandManager.execute(Commands.EDIT_FIND); + expect(getSearchField().val()).toEqual(""); + }); + + it("should use empty initial query for multiple cursor selection", function () { + myEditor.setSelections([{start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, primary: true}, + {start: {line: 1, ch: 0}, end: {line: 1, ch: 0}}]); + twCommandManager.execute(Commands.EDIT_FIND); + expect(getSearchField().val()).toEqual(""); + }); + + it("should get single selection as initial query", function () { + myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, + {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN}); + twCommandManager.execute(Commands.EDIT_FIND); + expect(getSearchField().val()).toEqual("require"); + }); + it("should get primary selection as initial query", function () { myEditor.setSelections([{start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN}, primary: true}, {start: {line: 1, ch: 0}, end: {line: 1, ch: 1}}]); From c5d466d6629a73f63436c04ba29a439dda0b5c57 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 28 Mar 2014 13:10:33 -0700 Subject: [PATCH 02/11] unit test for replace all static text --- test/spec/FindReplace-test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index f8d382fcb11..0a622624953 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1287,6 +1287,40 @@ define(function (require, exports, module) { describe("Search -> Replace All", function () { + it("should find and replace all", function () { + runs(function () { + var searchText = "require", + replaceText = "brackets.getModule"; + twCommandManager.execute(Commands.EDIT_REPLACE); + enterSearchText(searchText); + enterReplaceText(replaceText); + + expectSelection({start: {line: 1, ch: 17}, end: {line: 1, ch: 17 + searchText.length}}); + expect(myEditor.getSelectedText()).toBe(searchText); + + expect(tw$("#replace-all").is(":enabled")).toBe(true); + tw$("#replace-all").click(); + tw$(".replace-checked").click(); + + myEditor.setSelection({line: 1, ch: 17}, {line: 1, ch: 17 + replaceText.length}); + expect(myEditor.getSelectedText()).toBe(replaceText); + + // Note: LINE_FIRST_REQUIRE and CH_REQUIRE_START refer to first call to "require", + // but not first instance of "require" in text + myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, + {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START + replaceText.length}); + expect(myEditor.getSelectedText()).toBe(replaceText); + + myEditor.setSelection({line: LINE_FIRST_REQUIRE + 1, ch: CH_REQUIRE_START}, + {line: LINE_FIRST_REQUIRE + 1, ch: CH_REQUIRE_START + replaceText.length}); + expect(myEditor.getSelectedText()).toBe(replaceText); + + myEditor.setSelection({line: LINE_FIRST_REQUIRE + 2, ch: CH_REQUIRE_START}, + {line: LINE_FIRST_REQUIRE + 2, ch: CH_REQUIRE_START + replaceText.length}); + expect(myEditor.getSelectedText()).toBe(replaceText); + }); + }); + it("should find all regexps and replace them with $n", function () { runs(function () { twCommandManager.execute(Commands.EDIT_REPLACE); From 9f39b1ac25efc32fd50f3d8637126c2e243f50f2 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 28 Mar 2014 13:30:02 -0700 Subject: [PATCH 03/11] add test for skip --- test/spec/FindReplace-test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 0a622624953..d21684d0468 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1107,6 +1107,36 @@ define(function (require, exports, module) { expect(/bar/i.test(myEditor.getSelectedText())).toBe(true); }); }); + + it("should find and skip then replace string", function () { + runs(function () { + twCommandManager.execute(Commands.EDIT_REPLACE); + enterSearchText("foo"); + enterReplaceText("bar"); + + expectSelection(fooExpectedMatches[0]); + expect(/foo/i.test(myEditor.getSelectedText())).toBe(true); + + // Skip first + expect(tw$("#find-next").is(":enabled")).toBe(true); + tw$("#find-next").click(); + + expectSelection(fooExpectedMatches[1]); + expect(/foo/i.test(myEditor.getSelectedText())).toBe(true); + + // Replace second + expect(tw$("#replace-yes").is(":enabled")).toBe(true); + tw$("#replace-yes").click(); + + expectSelection(fooExpectedMatches[2]); + + myEditor.setSelection(fooExpectedMatches[0].start, fooExpectedMatches[0].end); + expect(/foo/i.test(myEditor.getSelectedText())).toBe(true); + + myEditor.setSelection(fooExpectedMatches[1].start, fooExpectedMatches[1].end); + expect(/bar/i.test(myEditor.getSelectedText())).toBe(true); + }); + }); it("should use replace keyboard shortcut for single Replace while search bar open", function () { runs(function () { From a9463c2e2073fe9bcb42575acaf124c06ef4edb3 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 28 Mar 2014 14:39:50 -0700 Subject: [PATCH 04/11] add test for scroll track markers --- src/brackets.js | 54 +++++++++++++++++--------------- src/search/ScrollTrackMarkers.js | 18 ++++++++--- test/spec/FindReplace-test.js | 18 +++++++++-- 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index b88df63c2c5..3ef7d4d3771 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -151,42 +151,44 @@ define(function (require, exports, module) { // in the modules since they would run in context of the unit test window, // and would not have access to the app html/css. brackets.test = { - PreferencesManager : PreferencesManager, - ProjectManager : ProjectManager, + CodeHintManager : CodeHintManager, + CodeInspection : CodeInspection, + CommandManager : CommandManager, + Commands : Commands, + CSSUtils : require("language/CSSUtils"), + DefaultDialogs : DefaultDialogs, + Dialogs : Dialogs, DocumentCommandHandlers : DocumentCommandHandlers, - FileViewController : FileViewController, DocumentManager : DocumentManager, + DOMAgent : require("LiveDevelopment/Agents/DOMAgent"), + DragAndDrop : DragAndDrop, EditorManager : EditorManager, - Commands : Commands, - WorkingSetView : WorkingSetView, - PerfUtils : PerfUtils, - JSUtils : JSUtils, - CommandManager : CommandManager, + ExtensionLoader : ExtensionLoader, + ExtensionUtils : ExtensionUtils, + FileFilters : require("search/FileFilters"), FileSyncManager : FileSyncManager, FileSystem : FileSystem, - Menus : Menus, + FileViewController : FileViewController, + FindInFiles : require("search/FindInFiles"), + HTMLInstrumentation : require("language/HTMLInstrumentation"), + Inspector : require("LiveDevelopment/Inspector/Inspector"), + InstallExtensionDialog : require("extensibility/InstallExtensionDialog"), + JSUtils : JSUtils, KeyBindingManager : KeyBindingManager, - CodeHintManager : CodeHintManager, - Dialogs : Dialogs, - DefaultDialogs : DefaultDialogs, - DragAndDrop : DragAndDrop, - CodeInspection : CodeInspection, - CSSUtils : require("language/CSSUtils"), + LanguageManager : LanguageManager, LiveDevelopment : require("LiveDevelopment/LiveDevelopment"), LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"), - DOMAgent : require("LiveDevelopment/Agents/DOMAgent"), - Inspector : require("LiveDevelopment/Inspector/Inspector"), + Menus : Menus, + MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor, NativeApp : NativeApp, - ExtensionLoader : ExtensionLoader, - ExtensionUtils : ExtensionUtils, - UpdateNotification : require("utils/UpdateNotification"), - InstallExtensionDialog : require("extensibility/InstallExtensionDialog"), + PerfUtils : PerfUtils, + PreferencesManager : PreferencesManager, + ProjectManager : ProjectManager, RemoteAgent : require("LiveDevelopment/Agents/RemoteAgent"), - HTMLInstrumentation : require("language/HTMLInstrumentation"), - MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor, - LanguageManager : LanguageManager, - FindInFiles : require("search/FindInFiles"), - FileFilters : require("search/FileFilters"), + ScrollTrackMarkers : require("search/ScrollTrackMarkers"), + UpdateNotification : require("utils/UpdateNotification"), + WorkingSetView : WorkingSetView, + doneLoading : false }; diff --git a/src/search/ScrollTrackMarkers.js b/src/search/ScrollTrackMarkers.js index 283ee9a5b55..e21f5b464e2 100644 --- a/src/search/ScrollTrackMarkers.js +++ b/src/search/ScrollTrackMarkers.js @@ -158,9 +158,17 @@ define(function (require, exports, module) { marks = marks.concat(posArray); _renderMarks(posArray); } - - - exports.clear = clear; - exports.setVisible = setVisible; - exports.addTickmarks = addTickmarks; + + // Private helper for unit tests + function _getMarks() { + return marks; + } + + + // For unit tests + exports._getMarks = _getMarks; + + exports.clear = clear; + exports.setVisible = setVisible; + exports.addTickmarks = addTickmarks; }); diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index d21684d0468..f7143ff10e9 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -29,9 +29,9 @@ define(function (require, exports, module) { 'use strict'; var Commands = require("command/Commands"), + FindReplace = require("search/FindReplace"), KeyEvent = require("utils/KeyEvent"), - SpecRunnerUtils = require("spec/SpecRunnerUtils"), - FindReplace = require("search/FindReplace"); + SpecRunnerUtils = require("spec/SpecRunnerUtils"); var defaultContent = "/* Test comment */\n" + "define(function (require, exports, module) {\n" + @@ -552,6 +552,20 @@ define(function (require, exports, module) { expectSelection(capitalFooSelections[0]); }); + it("should have a scroll track marker for every match", function () { + twCommandManager.execute(Commands.EDIT_FIND); + + enterSearchText("foo"); + expectHighlightedMatches(fooExpectedMatches); + + var marks = testWindow.brackets.test.ScrollTrackMarkers._getMarks(); + expect(marks.length).toEqual(fooExpectedMatches.length); + + marks.forEach(function (mark, index) { + expect(mark.line).toEqual(fooExpectedMatches[index].start.line); + }); + }); + it("toggling case-sensitive option should update results immediately", function () { myEditor.setCursorPos(0, 0); From 1712e30d391c0d3da0fc774c9a61b3c8c21116b3 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 9 Apr 2014 09:09:45 -0700 Subject: [PATCH 05/11] Find in Files tests - initial tests --- src/search/FindInFiles.js | 3 +- test/spec/FindReplace-test-files/bar.txt | 3 + test/spec/FindReplace-test-files/css/foo.css | 13 ++ test/spec/FindReplace-test-files/foo.html | 22 +++ test/spec/FindReplace-test-files/foo.js | 13 ++ test/spec/FindReplace-test.js | 150 ++++++++++++++++++- 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 test/spec/FindReplace-test-files/bar.txt create mode 100644 test/spec/FindReplace-test-files/css/foo.css create mode 100644 test/spec/FindReplace-test-files/foo.html create mode 100644 test/spec/FindReplace-test-files/foo.js diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index a203ea792df..d4e62e8bfb4 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -1240,6 +1240,7 @@ define(function (require, exports, module) { CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.EDIT_FIND_IN_FILES, _doFindInFiles); CommandManager.register(Strings.CMD_FIND_IN_SUBTREE, Commands.EDIT_FIND_IN_SUBTREE, _doFindInSubtree); - // For unit testing - updated in _doSearch() when search complete + // For unit testing + exports._doFindInFiles = _doFindInFiles; exports._searchResults = null; }); diff --git a/test/spec/FindReplace-test-files/bar.txt b/test/spec/FindReplace-test-files/bar.txt new file mode 100644 index 00000000000..b071cf9ee9c --- /dev/null +++ b/test/spec/FindReplace-test-files/bar.txt @@ -0,0 +1,3 @@ +bar.txt file + +This file should *not* show up in certain searches diff --git a/test/spec/FindReplace-test-files/css/foo.css b/test/spec/FindReplace-test-files/css/foo.css new file mode 100644 index 00000000000..02a7ad9ce7e --- /dev/null +++ b/test/spec/FindReplace-test-files/css/foo.css @@ -0,0 +1,13 @@ +/* foo.css */ +body { + margin: 0; +} +h1, footer { + padding: 2px auto; +} +ul.foo { + list-style: none; +} +.bar { + font-size: large; +} diff --git a/test/spec/FindReplace-test-files/foo.html b/test/spec/FindReplace-test-files/foo.html new file mode 100644 index 00000000000..1c7ead8038d --- /dev/null +++ b/test/spec/FindReplace-test-files/foo.html @@ -0,0 +1,22 @@ + + + + +Foo + + + + + + +

Foo

+

Intro to foo

+
    +
  • foo
  • +
  • bar
  • +
  • baz
  • +
+

It's all about the bar

+ + + diff --git a/test/spec/FindReplace-test-files/foo.js b/test/spec/FindReplace-test-files/foo.js new file mode 100644 index 00000000000..e6951ce3fa2 --- /dev/null +++ b/test/spec/FindReplace-test-files/foo.js @@ -0,0 +1,13 @@ +/* Test comment */ +define(function (require, exports, module) { + var Foo = require("modules/Foo"), + Bar = require("modules/Bar"), + Baz = require("modules/Baz"); + + function callFoo() { + + foo(); + + } + +} diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index f7143ff10e9..3964f126278 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1528,5 +1528,153 @@ define(function (require, exports, module) { }); }); }); - + + + describe("FindInFiles", function () { + + this.category = "integration"; + + var testPath = SpecRunnerUtils.getTestPath("/spec/FindReplace-test-files"), + CommandManager, + FileSystem, + FindInFiles, + testWindow, + $; + + beforeFirst(function () { + // Create a new window that will be shared by ALL tests in this spec. + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { + testWindow = w; + + // Load module instances from brackets.test + FileSystem = testWindow.brackets.test.FileSystem; + FindInFiles = testWindow.brackets.test.FindInFiles; + CommandManager = testWindow.brackets.test.CommandManager; + $ = testWindow.$; + + SpecRunnerUtils.loadProjectInTestWindow(testPath); + }); + }); + + afterLast(function () { + CommandManager = null; + FileSystem = null; + FindInFiles = null; + $ = null; + testWindow = null; + SpecRunnerUtils.closeTestWindow(); + }); + + function openSearchBar(scope) { + // Make sure search bar from previous test has animated out fully + runs(function () { + waitsFor(function () { + return $(".modal-bar").length === 0; + }, "search bar close"); + }); + runs(function () { + FindInFiles._doFindInFiles(scope); + }); + } + + function executeSearch(searchString) { + var $searchField = $(".modal-bar #find-group input"); + $searchField.val(searchString).trigger("input"); + SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_RETURN, "keydown", $searchField[0]); + waitsFor(function () { + return FindInFiles._searchResults; + }, "Find in Files done"); + } + + + it("should find all occurences in project", function () { + openSearchBar(); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + var fileResults = FindInFiles._searchResults[testPath + "/bar.txt"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/foo.html"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(7); + + fileResults = FindInFiles._searchResults[testPath + "/foo.js"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(4); + + fileResults = FindInFiles._searchResults[testPath + "/css/foo.css"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(3); + }); + }); + + it("should find all occurences in folder", function () { + var dirEntry = FileSystem.getDirectoryForPath(testPath + "/css/"); + openSearchBar(dirEntry); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + var fileResults = FindInFiles._searchResults[testPath + "/bar.txt"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/foo.html"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/foo.js"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/css/foo.css"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(3); + }); + }); + + it("should find all occurences in single file", function () { + var dirEntry = FileSystem.getFileForPath(testPath + "/foo.js"); + openSearchBar(dirEntry); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + var fileResults = FindInFiles._searchResults[testPath + "/bar.txt"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/foo.html"]; + expect(fileResults).toBeFalsy(); + + fileResults = FindInFiles._searchResults[testPath + "/foo.js"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(4); + + fileResults = FindInFiles._searchResults[testPath + "/css/foo.css"]; + expect(fileResults).toBeFalsy(); + }); + }); + + it("should find line and offsets", function () { + var dirEntry = FileSystem.getFileForPath(testPath + "/foo.js"); + openSearchBar(dirEntry); + runs(function () { + executeSearch("callFoo"); + }); + + runs(function () { + var fileResults = FindInFiles._searchResults[testPath + "/foo.js"]; + expect(fileResults).toBeTruthy(); + expect(fileResults.matches.length).toBe(1); + + var match = fileResults.matches[0]; + expect(match.start.ch).toBe(13); + expect(match.start.line).toBe(6); + expect(match.end.ch).toBe(20); + expect(match.end.line).toBe(6); + }); + }); + }); }); From 75e4f772083ff68c6022c78aa497e3c5fcee4261 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 9 Apr 2014 11:14:40 -0700 Subject: [PATCH 06/11] more tests --- test/spec/FindReplace-test.js | 68 ++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 3964f126278..74379f0bdff 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -22,7 +22,7 @@ */ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, waitsFor, waitsForDone, runs, window, jasmine */ +/*global define, describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, waits, waitsFor, waitsForDone, runs, window, jasmine */ /*unittests: FindReplace*/ define(function (require, exports, module) { @@ -1657,15 +1657,17 @@ define(function (require, exports, module) { }); }); - it("should find line and offsets", function () { - var dirEntry = FileSystem.getFileForPath(testPath + "/foo.js"); + it("should find start and end positions", function () { + var filePath = testPath + "/foo.js", + dirEntry = FileSystem.getFileForPath(filePath); + openSearchBar(dirEntry); runs(function () { executeSearch("callFoo"); }); runs(function () { - var fileResults = FindInFiles._searchResults[testPath + "/foo.js"]; + var fileResults = FindInFiles._searchResults[filePath]; expect(fileResults).toBeTruthy(); expect(fileResults.matches.length).toBe(1); @@ -1676,5 +1678,63 @@ define(function (require, exports, module) { expect(match.end.line).toBe(6); }); }); + + it("should dismiss dialog and show panel when there are results", function () { + var filePath = testPath + "/foo.js", + dirEntry = FileSystem.getFileForPath(filePath); + + openSearchBar(dirEntry); + runs(function () { + executeSearch("callFoo"); + }); + + waits(300); // .modal-bar close transition is 266ms + + runs(function () { + var fileResults = FindInFiles._searchResults[filePath]; + expect(fileResults).toBeTruthy(); + expect($("#search-results").is(":visible")).toBeTruthy(); + expect($(".modal-bar").length).toBe(0); + }); + }); + + it("should keep dialog and not show panel when there are no results", function () { + var filePath = testPath + "/bar.txt", + dirEntry = FileSystem.getFileForPath(filePath); + + openSearchBar(dirEntry); + runs(function () { + executeSearch("abcdefghi"); + }); + + waits(300); // .modal-bar close transition is 266ms + + runs(function () { + var result, resultFound = false; + + // verify _searchResults Object is empty + for (result in FindInFiles._searchResults) { + if (FindInFiles._searchResults.hasOwnProperty(result)) { + resultFound = true; + } + } + expect(resultFound).toBe(false); + + expect($("#search-results").is(":visible")).toBeFalsy(); + expect($(".modal-bar").length).toBe(1); + }); + }); + +// it("should paginate panel when results exceed 100", function () { +// }); +// +// it("should change file and selection when a result is clicked", function () { +// }); +// +// it("should open file in working set when a result is double-clicked", function () { +// }); +// +// it("should update results when a result in a file is edited", function () { +// }); }); }); From 0c955c6f8e63f964a945c501d826900bae660020 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 9 Apr 2014 14:58:08 -0700 Subject: [PATCH 07/11] interim checkin --- test/spec/FindReplace-test.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 74379f0bdff..5254520cf6a 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1722,18 +1722,30 @@ define(function (require, exports, module) { expect($("#search-results").is(":visible")).toBeFalsy(); expect($(".modal-bar").length).toBe(1); + + // Close search bar + var $searchField = $(".modal-bar #find-group input"); + SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_ESCAPE, "keydown", $searchField[0]); }); }); -// it("should paginate panel when results exceed 100", function () { -// }); -// // it("should change file and selection when a result is clicked", function () { -// }); +// openSearchBar(); +// runs(function () { +// executeSearch("foo"); +// }); +// +// runs(function () { +// var $searchResults = $("#search-results"); // +// expect($searchResults.is(":visible")).toBeTruthy(); +//// expect($searchResults.find("span.next-page").hasClass("disabled")).toBeFalsy(); +// }); +// }); + // it("should open file in working set when a result is double-clicked", function () { // }); -// + // it("should update results when a result in a file is edited", function () { // }); }); From 2b8d7a0ed2e5bc26129d5bdf0592b2bb27828bad Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 9 Apr 2014 18:02:07 -0700 Subject: [PATCH 08/11] Finish Find in Files unit tests --- test/spec/FindReplace-test.js | 151 ++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 24 deletions(-) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 5254520cf6a..c87ef3f6e38 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1536,6 +1536,8 @@ define(function (require, exports, module) { var testPath = SpecRunnerUtils.getTestPath("/spec/FindReplace-test-files"), CommandManager, + DocumentManager, + EditorManager, FileSystem, FindInFiles, testWindow, @@ -1547,6 +1549,9 @@ define(function (require, exports, module) { testWindow = w; // Load module instances from brackets.test + CommandManager = testWindow.brackets.test.CommandManager; + DocumentManager = testWindow.brackets.test.DocumentManager; + EditorManager = testWindow.brackets.test.EditorManager; FileSystem = testWindow.brackets.test.FileSystem; FindInFiles = testWindow.brackets.test.FindInFiles; CommandManager = testWindow.brackets.test.CommandManager; @@ -1557,11 +1562,13 @@ define(function (require, exports, module) { }); afterLast(function () { - CommandManager = null; - FileSystem = null; - FindInFiles = null; - $ = null; - testWindow = null; + CommandManager = null; + DocumentManager = null; + EditorManager = null; + FileSystem = null; + FindInFiles = null; + $ = null; + testWindow = null; SpecRunnerUtils.closeTestWindow(); }); @@ -1729,24 +1736,120 @@ define(function (require, exports, module) { }); }); -// it("should change file and selection when a result is clicked", function () { -// openSearchBar(); -// runs(function () { -// executeSearch("foo"); -// }); -// -// runs(function () { -// var $searchResults = $("#search-results"); -// -// expect($searchResults.is(":visible")).toBeTruthy(); -//// expect($searchResults.find("span.next-page").hasClass("disabled")).toBeFalsy(); -// }); -// }); - -// it("should open file in working set when a result is double-clicked", function () { -// }); - -// it("should update results when a result in a file is edited", function () { -// }); + it("should open file in editor and select text when a result is clicked", function () { + var filePath = testPath + "/foo.html", + dirEntry = FileSystem.getFileForPath(filePath); + + openSearchBar(dirEntry); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + // Verify no current document + var editor = EditorManager.getActiveEditor(); + expect(editor).toBeFalsy(); + + // Get panel + var $searchResults = $("#search-results"); + expect($searchResults.is(":visible")).toBeTruthy(); + + // Get list in panel + var $panelResults = $searchResults.find("table.bottom-panel-table tr"); + expect($panelResults.length).toBe(8); // 7 hits + 1 file section + + // First item in list is file section + expect($($panelResults[0]).hasClass("file-section")).toBeTruthy(); + + // Click second item which is first hit + var $firstHit = $($panelResults[1]); + expect($firstHit.hasClass("file-section")).toBeFalsy(); + $firstHit.click(); + + // Verify current document + editor = EditorManager.getActiveEditor(); + expect(editor.document.file.fullPath).toEqual(filePath); + + // Verify selection + expect(editor.getSelectedText().toLowerCase() === "foo"); + CommandManager.execute(Commands.FILE_CLOSE_ALL); + }); + }); + + it("should open file in working set when a result is double-clicked", function () { + var filePath = testPath + "/foo.js", + dirEntry = FileSystem.getFileForPath(filePath); + + openSearchBar(dirEntry); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + // Verify document is not yet in working set + expect(DocumentManager.findInWorkingSet(filePath)).toBe(-1); + + // Get list in panel + var $panelResults = $("#search-results table.bottom-panel-table tr"); + expect($panelResults.length).toBe(5); // 4 hits + 1 file section + + // Double-click second item which is first hit + var $firstHit = $($panelResults[1]); + expect($firstHit.hasClass("file-section")).toBeFalsy(); + $firstHit.dblclick(); + + // Verify document is now in working set + expect(DocumentManager.findInWorkingSet(filePath)).not.toBe(-1); + CommandManager.execute(Commands.FILE_CLOSE_ALL); + }); + }); + + it("should update results when a result in a file is edited", function () { + var filePath = testPath + "/foo.html", + dirEntry = FileSystem.getFileForPath(filePath), + panelListLen = 8, // 7 hits + 1 file section + $panelResults; + + openSearchBar(dirEntry); + runs(function () { + executeSearch("foo"); + }); + + runs(function () { + // Verify document is not yet in working set + expect(DocumentManager.findInWorkingSet(filePath)).toBe(-1); + + // Get list in panel + $panelResults = $("#search-results table.bottom-panel-table tr"); + expect($panelResults.length).toBe(panelListLen); + + // Double-click second item which is first hit + var $firstHit = $($panelResults[1]); + expect($firstHit.hasClass("file-section")).toBeFalsy(); + $firstHit.dblclick(); + + // Verify current document & selection + var editor = EditorManager.getActiveEditor(); + expect(editor.document.file.fullPath).toEqual(filePath); + expect(editor.getSelectedText().toLowerCase() === "foo"); + + // Edit text to remove hit from file + var sel = editor.getSelection(); + editor.document.replaceRange("Bar", sel.start, sel.end); + }); + + // Panel is updated asynchronously + waitsFor(function () { + $panelResults = $("#search-results table.bottom-panel-table tr"); + return ($panelResults.length < panelListLen); + }, "Results panel updated"); + + runs(function () { + // Verify list automatically updated + expect($panelResults.length).toBe(panelListLen - 1); + + CommandManager.execute(Commands.FILE_CLOSE_ALL); + }); + }); }); }); From 92d0cd76ae9d8843e58455eac9cd0f04da036e17 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 9 Apr 2014 18:44:56 -0700 Subject: [PATCH 09/11] better way to wait --- test/spec/FindReplace-test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index c87ef3f6e38..01befa85b3e 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -22,7 +22,7 @@ */ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, waits, waitsFor, waitsForDone, runs, window, jasmine */ +/*global define, describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, waitsFor, waitsForDone, runs, window, jasmine */ /*unittests: FindReplace*/ define(function (require, exports, module) { @@ -1695,7 +1695,9 @@ define(function (require, exports, module) { executeSearch("callFoo"); }); - waits(300); // .modal-bar close transition is 266ms + waitsFor(function () { + return ($(".modal-bar").length === 0); + }, "search bar close"); runs(function () { var fileResults = FindInFiles._searchResults[filePath]; @@ -1714,7 +1716,9 @@ define(function (require, exports, module) { executeSearch("abcdefghi"); }); - waits(300); // .modal-bar close transition is 266ms + waitsFor(function () { + return (FindInFiles._searchResults); + }, "search complete"); runs(function () { var result, resultFound = false; From 73ffa3ed9c9c572c72902916c788a58851b63f7a Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 10 Apr 2014 16:37:05 -0700 Subject: [PATCH 10/11] more filter tests --- test/spec/FileFilters-test.js | 74 +++++++++++++++++++++++++++++++++-- test/spec/FindReplace-test.js | 28 ++++++------- 2 files changed, 85 insertions(+), 17 deletions(-) diff --git a/test/spec/FileFilters-test.js b/test/spec/FileFilters-test.js index 19cb6003048..682e92e8624 100644 --- a/test/spec/FileFilters-test.js +++ b/test/spec/FileFilters-test.js @@ -427,6 +427,7 @@ define(function (require, exports, module) { var testPath = SpecRunnerUtils.getTestPath("/spec/InlineEditorProviders-test-files"), testWindow, FileFilters, + FileSystem, FindInFiles, CommandManager, $; @@ -438,6 +439,7 @@ define(function (require, exports, module) { // Load module instances from brackets.test FileFilters = testWindow.brackets.test.FileFilters; + FileSystem = testWindow.brackets.test.FileSystem; FindInFiles = testWindow.brackets.test.FindInFiles; CommandManager = testWindow.brackets.test.CommandManager; $ = testWindow.$; @@ -448,6 +450,7 @@ define(function (require, exports, module) { afterLast(function () { testWindow = null; + FileSystem = null; FileFilters = null; FindInFiles = null; CommandManager = null; @@ -455,7 +458,7 @@ define(function (require, exports, module) { SpecRunnerUtils.closeTestWindow(); }); - function openSearchBar() { + function openSearchBar(scope) { // Make sure search bar from previous test has animated out fully runs(function () { waitsFor(function () { @@ -463,7 +466,7 @@ define(function (require, exports, module) { }, "search bar close"); }); runs(function () { - waitsForDone(CommandManager.execute(Commands.EDIT_FIND_IN_FILES)); + FindInFiles._doFindInFiles(scope); }); } @@ -506,11 +509,76 @@ define(function (require, exports, module) { executeSearch("{1}"); }); runs(function () { - expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy(); // *.css should have been excluded this time + // *.css should have been excluded this time + expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy(); expect(FindInFiles._searchResults[testPath + "/test1.html"]).toBeTruthy(); }); }); + it("should respect filter when searching folder", function () { + var dirEntry = FileSystem.getDirectoryForPath(testPath); + openSearchBar(dirEntry); + runs(function () { + setExcludeCSSFiles(); + }); + runs(function () { + executeSearch("{1}"); + }); + runs(function () { + // *.css should have been excluded this time + expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy(); + expect(FindInFiles._searchResults[testPath + "/test1.html"]).toBeTruthy(); + }); + }); + + it("should ignore filter when searching a single file", function () { + var fileEntry = FileSystem.getFileForPath(testPath + "/test1.css"); + openSearchBar(fileEntry); + runs(function () { + // Cannot explicitly set *.css filter in dialog because button is hidden + // (which is verified here), but filter persists from previous test + expect($(".filter-picker button").is(":visible")).toBeFalsy(); + }); + runs(function () { + executeSearch("{1}"); + }); + runs(function () { + // ignore *.css exclusion since we're explicitly searching this file + expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeTruthy(); + }); + }); + + it("should show error when filter excludes all files", function () { + openSearchBar(); + runs(function () { + // Launch filter editor + $(".filter-picker button").click(); + + // Edit the filter & confirm changes + $(".modal.instance textarea").val("test1.*\n*.css"); + SpecRunnerUtils.clickDialogButton(Dialogs.DIALOG_BTN_OK); + }); + runs(function () { + executeSearch("{1}"); + }); + runs(function () { + var $modalBar = $(".modal-bar"); + + // Dialog still showing + expect($modalBar.length).toBe(1); + + // Error message displayed + expect($modalBar.find("#find-group div.error").is(":visible")).toBeTruthy(); + + // Search panel not showing + expect($("#search-results").is(":visible")).toBeFalsy(); + + // Close search bar + var $searchField = $modalBar.find("#find-group input"); + SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_ESCAPE, "keydown", $searchField[0]); + }); + }); + it("should respect filter when editing code", function () { openSearchBar(); runs(function () { diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index 01befa85b3e..c290762d357 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -1642,8 +1642,8 @@ define(function (require, exports, module) { }); it("should find all occurences in single file", function () { - var dirEntry = FileSystem.getFileForPath(testPath + "/foo.js"); - openSearchBar(dirEntry); + var fileEntry = FileSystem.getFileForPath(testPath + "/foo.js"); + openSearchBar(fileEntry); runs(function () { executeSearch("foo"); }); @@ -1666,9 +1666,9 @@ define(function (require, exports, module) { it("should find start and end positions", function () { var filePath = testPath + "/foo.js", - dirEntry = FileSystem.getFileForPath(filePath); + fileEntry = FileSystem.getFileForPath(filePath); - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("callFoo"); }); @@ -1688,9 +1688,9 @@ define(function (require, exports, module) { it("should dismiss dialog and show panel when there are results", function () { var filePath = testPath + "/foo.js", - dirEntry = FileSystem.getFileForPath(filePath); + fileEntry = FileSystem.getFileForPath(filePath); - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("callFoo"); }); @@ -1709,9 +1709,9 @@ define(function (require, exports, module) { it("should keep dialog and not show panel when there are no results", function () { var filePath = testPath + "/bar.txt", - dirEntry = FileSystem.getFileForPath(filePath); + fileEntry = FileSystem.getFileForPath(filePath); - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("abcdefghi"); }); @@ -1742,9 +1742,9 @@ define(function (require, exports, module) { it("should open file in editor and select text when a result is clicked", function () { var filePath = testPath + "/foo.html", - dirEntry = FileSystem.getFileForPath(filePath); + fileEntry = FileSystem.getFileForPath(filePath); - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("foo"); }); @@ -1782,9 +1782,9 @@ define(function (require, exports, module) { it("should open file in working set when a result is double-clicked", function () { var filePath = testPath + "/foo.js", - dirEntry = FileSystem.getFileForPath(filePath); + fileEntry = FileSystem.getFileForPath(filePath); - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("foo"); }); @@ -1810,11 +1810,11 @@ define(function (require, exports, module) { it("should update results when a result in a file is edited", function () { var filePath = testPath + "/foo.html", - dirEntry = FileSystem.getFileForPath(filePath), + fileEntry = FileSystem.getFileForPath(filePath), panelListLen = 8, // 7 hits + 1 file section $panelResults; - openSearchBar(dirEntry); + openSearchBar(fileEntry); runs(function () { executeSearch("foo"); }); From bfa88ad959a58292a94e14a37c7d1d57d5147659 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 16 Apr 2014 19:02:16 -0700 Subject: [PATCH 11/11] rename function --- src/search/ScrollTrackMarkers.js | 4 ++-- test/spec/FindReplace-test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/search/ScrollTrackMarkers.js b/src/search/ScrollTrackMarkers.js index e21f5b464e2..0325339a15b 100644 --- a/src/search/ScrollTrackMarkers.js +++ b/src/search/ScrollTrackMarkers.js @@ -160,13 +160,13 @@ define(function (require, exports, module) { } // Private helper for unit tests - function _getMarks() { + function _getTickmarks() { return marks; } // For unit tests - exports._getMarks = _getMarks; + exports._getTickmarks = _getTickmarks; exports.clear = clear; exports.setVisible = setVisible; diff --git a/test/spec/FindReplace-test.js b/test/spec/FindReplace-test.js index c290762d357..1bf5553d418 100644 --- a/test/spec/FindReplace-test.js +++ b/test/spec/FindReplace-test.js @@ -558,7 +558,7 @@ define(function (require, exports, module) { enterSearchText("foo"); expectHighlightedMatches(fooExpectedMatches); - var marks = testWindow.brackets.test.ScrollTrackMarkers._getMarks(); + var marks = testWindow.brackets.test.ScrollTrackMarkers._getTickmarks(); expect(marks.length).toEqual(fooExpectedMatches.length); marks.forEach(function (mark, index) {