Skip to content

Commit 549dc01

Browse files
committed
test: find in files integ tests
1 parent b62fb46 commit 549dc01

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

test/spec/FindInFiles-integ-test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ define(function (require, exports, module) {
4949
ProjectManager,
5050
SearchResultsView,
5151
testWindow,
52-
$;
52+
$,
53+
__PR;
5354

5455
beforeAll(async function () {
5556
await SpecRunnerUtils.createTempDirectory();
@@ -71,6 +72,7 @@ define(function (require, exports, module) {
7172
SearchResultsView = testWindow.brackets.test.SearchResultsView;
7273
$ = testWindow.$;
7374
PreferencesManager = testWindow.brackets.test.PreferencesManager;
75+
__PR = testWindow.__PR;
7476
PreferencesManager.set("findInFiles.nodeSearch", false);
7577
PreferencesManager.set("findInFiles.instantSearch", false);
7678
PreferencesManager.set("maxSearchHistory", 5);
@@ -89,6 +91,8 @@ define(function (require, exports, module) {
8991
$ = null;
9092
testWindow = null;
9193
PreferencesManager = null;
94+
__PR = null;
95+
9296
await SpecRunnerUtils.closeTestWindow();
9397
await SpecRunnerUtils.removeTempDirectory();
9498
}, 30000);
@@ -125,6 +129,10 @@ define(function (require, exports, module) {
125129
});
126130
}
127131

132+
function getSearchField() {
133+
return $("#find-what");
134+
}
135+
128136
async function closeSearchBar() {
129137
FindInFilesUI._closeFindBar();
130138
await waitForSearchBarClose();
@@ -571,6 +579,28 @@ define(function (require, exports, module) {
571579
// Search model shouldn't be cleared after search bar closed without running a search
572580
expect(Object.keys(FindInFiles.searchModel.results).length).not.toBe(0);
573581
});
582+
583+
it("should switch between find replace and find in files with selection work as expected", async function () {
584+
await closeSearchBar();
585+
const filePath = testPath + "/foo.js";
586+
await __PR.openFile(filePath);
587+
__PR.setCursors(["7:5-7:13"]); // select text: function
588+
CommandManager.execute(Commands.CMD_FIND);
589+
590+
expect(getSearchField().val()).toEql("function");
591+
592+
CommandManager.execute(Commands.CMD_FIND_IN_FILES);
593+
await awaitsFor(()=>{
594+
return $("#find-in-files-results .contracting-col").text() === "function";
595+
}, ()=>{
596+
return `Find in files search to be function but got${$("#find-in-files-results .contracting-col").text()}`;
597+
});
598+
599+
__PR.setCursors(["5:15-5:22"]); // select text: require
600+
CommandManager.execute(Commands.CMD_FIND);
601+
expect(getSearchField().val()).toEql("require");
602+
await openSearchBar();
603+
});
574604
});
575605
});
576606
});

test/spec/FindReplace-integ-test.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ define(function (require, exports, module) {
9090
];
9191

9292

93-
var testWindow, twCommandManager, twEditorManager, twFindInFiles, tw$;
93+
var testWindow, twCommandManager, twEditorManager, twFindInFiles, tw$, __PR;
9494
var myDocument, myEditor;
9595

9696
// Helper functions for testing cursor position / selection range
@@ -574,7 +574,34 @@ define(function (require, exports, module) {
574574
twCommandManager.execute(Commands.CMD_FIND_NEXT);
575575
expectSelection(capitalFooSelections[1]);
576576
expectMatchIndex(1, 3);
577-
}, 100000);
577+
});
578+
579+
it("should highlight the current position match properly", async function () {
580+
myEditor.setCursorPos(0, 0);
581+
582+
twCommandManager.execute(Commands.CMD_FIND);
583+
584+
enterSearchText("Foo");
585+
pressEscape();
586+
587+
await waitsForSearchBarClose();
588+
589+
// Open search bar a second time
590+
myEditor.setCursorPos(2, 8); // |Foo
591+
twCommandManager.execute(Commands.CMD_FIND);
592+
593+
expectSearchBarOpen();
594+
expect(getSearchField().val()).toEql("Foo");
595+
expectMatchIndex(0, 4);
596+
597+
myEditor.setCursorPos(2, 9); // F|oo
598+
twCommandManager.execute(Commands.CMD_FIND);
599+
expectMatchIndex(0, 4);
600+
601+
myEditor.setCursorPos(2, 11); // Foo|
602+
twCommandManager.execute(Commands.CMD_FIND);
603+
expectMatchIndex(0, 4);
604+
});
578605

579606
it("should open search bar on Find Next with no previous search", async function () {
580607
// Make sure we have no previous query

0 commit comments

Comments
 (0)