Browse files

Add a few more unit tests for Find. Update unit-test harness files to

include this suite.

Update a few other unit tests to use KeyEvent constants, and remove unused
dependencies. (All those suites still pass too).
  • Loading branch information...
1 parent 4c9bb22 commit 1328419383514e03fed495c8e6fa9245162ceef9 @peterflynn peterflynn committed Dec 10, 2012
View
2 src/index.html
@@ -77,7 +77,7 @@
<script src="thirdparty/jquery-1.7.min.js"></script>
<script src="thirdparty/CodeMirror2/lib/codemirror.js"></script>
- <!-- JS for CodeMirror search support, currently for debugging only -->
+ <!-- JS for CodeMirror search support -->
<script src="thirdparty/CodeMirror2/lib/util/dialog.js"></script>
<script src="thirdparty/CodeMirror2/lib/util/searchcursor.js"></script>
<script src="thirdparty/CodeMirror2/lib/util/search.js"></script>
View
3 test/SpecRunner.html
@@ -36,6 +36,9 @@
<!-- Pre-load third party scripts that cannot be async loaded. -->
<script src="../src/thirdparty/jquery-1.7.min.js"></script>
<script src="../src/thirdparty/CodeMirror2/lib/codemirror.js"></script>
+ <script src="../src/thirdparty/CodeMirror2/lib/util/dialog.js"></script>
+ <script src="../src/thirdparty/CodeMirror2/lib/util/searchcursor.js"></script>
+ <script src="../src/thirdparty/CodeMirror2/lib/util/search.js"></script>
<script src="../src/thirdparty/mustache/mustache.js"></script>
<script src="thirdparty/bootstrap2/js/bootstrap.min.js"></script>
View
1 test/UnitTestSuite.js
@@ -37,6 +37,7 @@ define(function (require, exports, module) {
require("spec/EditorCommandHandlers-test");
require("spec/ExtensionUtils-test");
require("spec/FileIndexManager-test");
+ require("spec/FindReplace-test");
require("spec/InlineEditorProviders-test");
require("spec/KeyBindingManager-test");
require("spec/LiveDevelopment-test");
View
8 test/spec/CodeHint-test.js
@@ -104,7 +104,7 @@ define(function (require, exports, module) {
// simulate Ctrl+space keystroke to invoke code hints menu
runs(function () {
var e = $.Event("keydown");
- e.keyCode = KeyEvent.DOM_VK_SPACE; // spacebar key
+ e.keyCode = KeyEvent.DOM_VK_SPACE;
e.ctrlKey = true;
editor = EditorManager.getCurrentFullEditor();
@@ -125,7 +125,7 @@ define(function (require, exports, module) {
// simulate Enter key to insert code hint into doc
runs(function () {
var e = $.Event("keydown");
- e.keyCode = 13; // Enter/return key
+ e.keyCode = KeyEvent.DOM_VK_RETURN;
editor = EditorManager.getCurrentFullEditor();
expect(editor).toBeTruthy();
@@ -150,7 +150,7 @@ define(function (require, exports, module) {
// simulate Ctrl+space keystroke to invoke code hints menu
runs(function () {
var e = $.Event("keydown");
- e.keyCode = 32; // spacebar key
+ e.keyCode = KeyEvent.DOM_VK_SPACE;
e.ctrlKey = true;
editor = EditorManager.getCurrentFullEditor();
@@ -168,7 +168,7 @@ define(function (require, exports, module) {
// simulate Esc key to dismiss code hints menu
runs(function () {
- var key = 27, // Esc key
+ var key = KeyEvent.DOM_VK_ESCAPE,
element = testWindow.$(".dropdown.open")[0];
SpecRunnerUtils.simulateKeyEvent(key, "keydown", element);
View
4 test/spec/EditorCommandHandlers-test.js
@@ -29,11 +29,9 @@ define(function (require, exports, module) {
var Editor = require("editor/Editor").Editor,
EditorCommandHandlers = require("editor/EditorCommandHandlers"),
- EditorManager = require("editor/EditorManager"),
Commands = require("command/Commands"),
CommandManager = require("command/CommandManager"),
- SpecRunnerUtils = require("spec/SpecRunnerUtils"),
- EditorUtils = require("editor/EditorUtils");
+ SpecRunnerUtils = require("spec/SpecRunnerUtils");
describe("EditorCommandHandlers", function () {
View
36 test/spec/FindReplace-test.js
@@ -160,7 +160,7 @@ define(function (require, exports, module) {
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
});
- it("should Find Next after search bar closed", function () {
+ it("should Find Next after search bar closed, including wraparound", function () {
myEditor.setCursorPos(0, 0);
CommandManager.execute(Commands.EDIT_FIND);
@@ -171,8 +171,41 @@ define(function (require, exports, module) {
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
+ // Simple linear Find Next
CommandManager.execute(Commands.EDIT_FIND_NEXT);
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 31}, end: {line: LINE_FIRST_REQUIRE, ch: 34}});
+ CommandManager.execute(Commands.EDIT_FIND_NEXT);
+ expectSelection({start: {line: 6, ch: 17}, end: {line: 6, ch: 20}});
+ CommandManager.execute(Commands.EDIT_FIND_NEXT);
+ expectSelection({start: {line: 8, ch: 8}, end: {line: 8, ch: 11}});
+
+ // Wrap around to first result
+ CommandManager.execute(Commands.EDIT_FIND_NEXT);
+ expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
+ });
+
+ it("should Find Previous after search bar closed, including wraparound", function () {
+ myEditor.setCursorPos(0, 0);
+
+ CommandManager.execute(Commands.EDIT_FIND);
+
+ enterSearchText("foo");
+ pressEnter();
+ expectSearchBarClosed();
+
+ expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
+
+ // Wrap around to last result
+ CommandManager.execute(Commands.EDIT_FIND_PREVIOUS);
+ expectSelection({start: {line: 8, ch: 8}, end: {line: 8, ch: 11}});
+
+ // Simple linear Find Previous
+ CommandManager.execute(Commands.EDIT_FIND_PREVIOUS);
+ expectSelection({start: {line: 6, ch: 17}, end: {line: 6, ch: 20}});
+ CommandManager.execute(Commands.EDIT_FIND_PREVIOUS);
+ expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 31}, end: {line: LINE_FIRST_REQUIRE, ch: 34}});
+ CommandManager.execute(Commands.EDIT_FIND_PREVIOUS);
+ expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
});
it("shouldn't Find Next after search bar reopened", function () {
@@ -203,6 +236,7 @@ define(function (require, exports, module) {
expectSearchBarOpen();
expectCursorAt({line: 0, ch: 0});
});
+
});
View
3 test/spec/InlineEditorProviders-test.js
@@ -36,6 +36,7 @@ define(function (require, exports, module) {
FileViewController, // loaded from brackets.test
Dialogs = require("widgets/Dialogs"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
+ KeyEvent = require("utils/KeyEvent"),
FileUtils = require("file/FileUtils"),
SpecRunnerUtils = require("spec/SpecRunnerUtils");
@@ -337,7 +338,7 @@ define(function (require, exports, module) {
expect(hostEditor.getInlineWidgets().length).toBe(1);
// close the editor by simulating Esc key
- var key = 27, // Esc key
+ var key = KeyEvent.DOM_VK_ESCAPE,
doc = testWindow.document,
element = doc.getElementsByClassName("inline-widget")[0];
SpecRunnerUtils.simulateKeyEvent(key, "keydown", element);
View
5 test/spec/Menu-test.js
@@ -32,8 +32,7 @@ define(function (require, exports, module) {
KeyBindingManager,
Menus,
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
- StringsUtils = require("utils/StringUtils"),
- Strings = require("strings");
+ KeyEvent = require("utils/KeyEvent");
@@ -696,7 +695,7 @@ define(function (require, exports, module) {
expect($menus.length).toBe(1);
// close the context menu by simulating Esc key
- var key = 27, // Esc key
+ var key = KeyEvent.DOM_VK_ESCAPE,
element = $menus[0];
SpecRunnerUtils.simulateKeyEvent(key, "keydown", element);

0 comments on commit 1328419

Please sign in to comment.