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

Commit

Permalink
more filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
redmunds committed Apr 10, 2014
1 parent 8df314a commit 73ffa3e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 17 deletions.
74 changes: 71 additions & 3 deletions test/spec/FileFilters-test.js
Expand Up @@ -427,6 +427,7 @@ define(function (require, exports, module) {
var testPath = SpecRunnerUtils.getTestPath("/spec/InlineEditorProviders-test-files"),
testWindow,
FileFilters,
FileSystem,
FindInFiles,
CommandManager,
$;
Expand All @@ -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.$;
Expand All @@ -448,22 +450,23 @@ define(function (require, exports, module) {

afterLast(function () {
testWindow = null;
FileSystem = null;
FileFilters = null;
FindInFiles = null;
CommandManager = null;
$ = null;
SpecRunnerUtils.closeTestWindow();
});

function openSearchBar() {
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 () {
waitsForDone(CommandManager.execute(Commands.EDIT_FIND_IN_FILES));
FindInFiles._doFindInFiles(scope);
});
}

Expand Down Expand Up @@ -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 () {
Expand Down
28 changes: 14 additions & 14 deletions test/spec/FindReplace-test.js
Expand Up @@ -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");
});
Expand All @@ -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");
});
Expand All @@ -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");
});
Expand All @@ -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");
});
Expand Down Expand Up @@ -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");
});
Expand Down Expand Up @@ -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");
});
Expand All @@ -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");
});
Expand Down

0 comments on commit 73ffa3e

Please sign in to comment.