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

Commit 78636b1

Browse files
committed
Merge pull request #7328 from adobe/randy/find-replace-unit-tests
Unit Tests for Find, Replace, Find in Files, File Filters
2 parents 195fcde + bfa88ad commit 78636b1

9 files changed

Lines changed: 593 additions & 38 deletions

File tree

src/brackets.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,42 +151,44 @@ define(function (require, exports, module) {
151151
// in the modules since they would run in context of the unit test window,
152152
// and would not have access to the app html/css.
153153
brackets.test = {
154-
PreferencesManager : PreferencesManager,
155-
ProjectManager : ProjectManager,
154+
CodeHintManager : CodeHintManager,
155+
CodeInspection : CodeInspection,
156+
CommandManager : CommandManager,
157+
Commands : Commands,
158+
CSSUtils : require("language/CSSUtils"),
159+
DefaultDialogs : DefaultDialogs,
160+
Dialogs : Dialogs,
156161
DocumentCommandHandlers : DocumentCommandHandlers,
157-
FileViewController : FileViewController,
158162
DocumentManager : DocumentManager,
163+
DOMAgent : require("LiveDevelopment/Agents/DOMAgent"),
164+
DragAndDrop : DragAndDrop,
159165
EditorManager : EditorManager,
160-
Commands : Commands,
161-
WorkingSetView : WorkingSetView,
162-
PerfUtils : PerfUtils,
163-
JSUtils : JSUtils,
164-
CommandManager : CommandManager,
166+
ExtensionLoader : ExtensionLoader,
167+
ExtensionUtils : ExtensionUtils,
168+
FileFilters : require("search/FileFilters"),
165169
FileSyncManager : FileSyncManager,
166170
FileSystem : FileSystem,
167-
Menus : Menus,
171+
FileViewController : FileViewController,
172+
FindInFiles : require("search/FindInFiles"),
173+
HTMLInstrumentation : require("language/HTMLInstrumentation"),
174+
Inspector : require("LiveDevelopment/Inspector/Inspector"),
175+
InstallExtensionDialog : require("extensibility/InstallExtensionDialog"),
176+
JSUtils : JSUtils,
168177
KeyBindingManager : KeyBindingManager,
169-
CodeHintManager : CodeHintManager,
170-
Dialogs : Dialogs,
171-
DefaultDialogs : DefaultDialogs,
172-
DragAndDrop : DragAndDrop,
173-
CodeInspection : CodeInspection,
174-
CSSUtils : require("language/CSSUtils"),
178+
LanguageManager : LanguageManager,
175179
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
176180
LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"),
177-
DOMAgent : require("LiveDevelopment/Agents/DOMAgent"),
178-
Inspector : require("LiveDevelopment/Inspector/Inspector"),
181+
Menus : Menus,
182+
MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
179183
NativeApp : NativeApp,
180-
ExtensionLoader : ExtensionLoader,
181-
ExtensionUtils : ExtensionUtils,
182-
UpdateNotification : require("utils/UpdateNotification"),
183-
InstallExtensionDialog : require("extensibility/InstallExtensionDialog"),
184+
PerfUtils : PerfUtils,
185+
PreferencesManager : PreferencesManager,
186+
ProjectManager : ProjectManager,
184187
RemoteAgent : require("LiveDevelopment/Agents/RemoteAgent"),
185-
HTMLInstrumentation : require("language/HTMLInstrumentation"),
186-
MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
187-
LanguageManager : LanguageManager,
188-
FindInFiles : require("search/FindInFiles"),
189-
FileFilters : require("search/FileFilters"),
188+
ScrollTrackMarkers : require("search/ScrollTrackMarkers"),
189+
UpdateNotification : require("utils/UpdateNotification"),
190+
WorkingSetView : WorkingSetView,
191+
190192
doneLoading : false
191193
};
192194

src/search/FindInFiles.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ define(function (require, exports, module) {
12401240
CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.EDIT_FIND_IN_FILES, _doFindInFiles);
12411241
CommandManager.register(Strings.CMD_FIND_IN_SUBTREE, Commands.EDIT_FIND_IN_SUBTREE, _doFindInSubtree);
12421242

1243-
// For unit testing - updated in _doSearch() when search complete
1243+
// For unit testing
1244+
exports._doFindInFiles = _doFindInFiles;
12441245
exports._searchResults = null;
12451246
});

src/search/ScrollTrackMarkers.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,17 @@ define(function (require, exports, module) {
158158
marks = marks.concat(posArray);
159159
_renderMarks(posArray);
160160
}
161-
162-
163-
exports.clear = clear;
164-
exports.setVisible = setVisible;
165-
exports.addTickmarks = addTickmarks;
161+
162+
// Private helper for unit tests
163+
function _getTickmarks() {
164+
return marks;
165+
}
166+
167+
168+
// For unit tests
169+
exports._getTickmarks = _getTickmarks;
170+
171+
exports.clear = clear;
172+
exports.setVisible = setVisible;
173+
exports.addTickmarks = addTickmarks;
166174
});

test/spec/FileFilters-test.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ define(function (require, exports, module) {
427427
var testPath = SpecRunnerUtils.getTestPath("/spec/InlineEditorProviders-test-files"),
428428
testWindow,
429429
FileFilters,
430+
FileSystem,
430431
FindInFiles,
431432
CommandManager,
432433
$;
@@ -438,6 +439,7 @@ define(function (require, exports, module) {
438439

439440
// Load module instances from brackets.test
440441
FileFilters = testWindow.brackets.test.FileFilters;
442+
FileSystem = testWindow.brackets.test.FileSystem;
441443
FindInFiles = testWindow.brackets.test.FindInFiles;
442444
CommandManager = testWindow.brackets.test.CommandManager;
443445
$ = testWindow.$;
@@ -448,22 +450,23 @@ define(function (require, exports, module) {
448450

449451
afterLast(function () {
450452
testWindow = null;
453+
FileSystem = null;
451454
FileFilters = null;
452455
FindInFiles = null;
453456
CommandManager = null;
454457
$ = null;
455458
SpecRunnerUtils.closeTestWindow();
456459
});
457460

458-
function openSearchBar() {
461+
function openSearchBar(scope) {
459462
// Make sure search bar from previous test has animated out fully
460463
runs(function () {
461464
waitsFor(function () {
462465
return $(".modal-bar").length === 0;
463466
}, "search bar close");
464467
});
465468
runs(function () {
466-
waitsForDone(CommandManager.execute(Commands.EDIT_FIND_IN_FILES));
469+
FindInFiles._doFindInFiles(scope);
467470
});
468471
}
469472

@@ -506,11 +509,76 @@ define(function (require, exports, module) {
506509
executeSearch("{1}");
507510
});
508511
runs(function () {
509-
expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy(); // *.css should have been excluded this time
512+
// *.css should have been excluded this time
513+
expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy();
510514
expect(FindInFiles._searchResults[testPath + "/test1.html"]).toBeTruthy();
511515
});
512516
});
513517

518+
it("should respect filter when searching folder", function () {
519+
var dirEntry = FileSystem.getDirectoryForPath(testPath);
520+
openSearchBar(dirEntry);
521+
runs(function () {
522+
setExcludeCSSFiles();
523+
});
524+
runs(function () {
525+
executeSearch("{1}");
526+
});
527+
runs(function () {
528+
// *.css should have been excluded this time
529+
expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeFalsy();
530+
expect(FindInFiles._searchResults[testPath + "/test1.html"]).toBeTruthy();
531+
});
532+
});
533+
534+
it("should ignore filter when searching a single file", function () {
535+
var fileEntry = FileSystem.getFileForPath(testPath + "/test1.css");
536+
openSearchBar(fileEntry);
537+
runs(function () {
538+
// Cannot explicitly set *.css filter in dialog because button is hidden
539+
// (which is verified here), but filter persists from previous test
540+
expect($(".filter-picker button").is(":visible")).toBeFalsy();
541+
});
542+
runs(function () {
543+
executeSearch("{1}");
544+
});
545+
runs(function () {
546+
// ignore *.css exclusion since we're explicitly searching this file
547+
expect(FindInFiles._searchResults[testPath + "/test1.css"]).toBeTruthy();
548+
});
549+
});
550+
551+
it("should show error when filter excludes all files", function () {
552+
openSearchBar();
553+
runs(function () {
554+
// Launch filter editor
555+
$(".filter-picker button").click();
556+
557+
// Edit the filter & confirm changes
558+
$(".modal.instance textarea").val("test1.*\n*.css");
559+
SpecRunnerUtils.clickDialogButton(Dialogs.DIALOG_BTN_OK);
560+
});
561+
runs(function () {
562+
executeSearch("{1}");
563+
});
564+
runs(function () {
565+
var $modalBar = $(".modal-bar");
566+
567+
// Dialog still showing
568+
expect($modalBar.length).toBe(1);
569+
570+
// Error message displayed
571+
expect($modalBar.find("#find-group div.error").is(":visible")).toBeTruthy();
572+
573+
// Search panel not showing
574+
expect($("#search-results").is(":visible")).toBeFalsy();
575+
576+
// Close search bar
577+
var $searchField = $modalBar.find("#find-group input");
578+
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_ESCAPE, "keydown", $searchField[0]);
579+
});
580+
});
581+
514582
it("should respect filter when editing code", function () {
515583
openSearchBar();
516584
runs(function () {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bar.txt file
2+
3+
This file should *not* show up in certain searches
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* foo.css */
2+
body {
3+
margin: 0;
4+
}
5+
h1, footer {
6+
padding: 2px auto;
7+
}
8+
ul.foo {
9+
list-style: none;
10+
}
11+
.bar {
12+
font-size: large;
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>Foo</title>
6+
<link rel="stylesheet" href="css/foo.css">
7+
<script src="foo.js"></script>
8+
</head>
9+
10+
<body>
11+
12+
<h1>Foo</h1>
13+
<p>Intro to foo</p>
14+
<ul class="foo">
15+
<li>foo</li>
16+
<li>bar</li>
17+
<li>baz</li>
18+
</ul>
19+
<p class="bar">It's all about the bar</p>
20+
21+
</body>
22+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Test comment */
2+
define(function (require, exports, module) {
3+
var Foo = require("modules/Foo"),
4+
Bar = require("modules/Bar"),
5+
Baz = require("modules/Baz");
6+
7+
function callFoo() {
8+
9+
foo();
10+
11+
}
12+
13+
}

0 commit comments

Comments
 (0)