forked from humphd/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickOpen-test.js
More file actions
197 lines (161 loc) · 8.4 KB
/
Copy pathQuickOpen-test.js
File metadata and controls
197 lines (161 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, waitsForDone, runs */
/*unittests: QuickOpen*/
define(function (require, exports, module) {
'use strict';
var Commands = require("command/Commands"),
KeyEvent = require("utils/KeyEvent"),
SpecRunnerUtils = require("spec/SpecRunnerUtils");
describe("QuickOpen", function () {
this.category = "integration";
var testPath = SpecRunnerUtils.getTestPath("/spec/QuickOpen-test-files");
var brackets, testWindow, test$, executeCommand, EditorManager, DocumentManager;
beforeEach(function () {
runs(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (other) {
testWindow = other;
brackets = testWindow.brackets;
test$ = testWindow.$;
executeCommand = testWindow.executeCommand;
EditorManager = brackets.test.EditorManager;
DocumentManager = brackets.test.DocumentManager;
});
});
});
afterEach(function () {
testWindow = null;
brackets = null;
test$ = null;
executeCommand = null;
EditorManager = null;
DocumentManager = null;
SpecRunnerUtils.closeTestWindow();
});
function getSearchBar() {
return test$(".modal-bar");
}
function getSearchField() {
return test$(".modal-bar input[type='text']");
}
function expectSearchBarOpen() {
expect(getSearchBar()[0]).toBeDefined();
}
function enterSearchText(str, timeoutLength) {
timeoutLength = timeoutLength || 10;
expectSearchBarOpen();
testWindow.setTimeout(function () {
getSearchField().val(str);
getSearchField().trigger("input");
}, timeoutLength);
}
function pressEnter() {
expectSearchBarOpen();
// Using keyup here because of inside knowledge of how the events are processed
// on the QuickOpen input.
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_RETURN, "keydown", getSearchField()[0]);
}
/**
* Creates a parameterized quick open test.
* @param {string} quickOpenQuery The search query to execute after the NAVIGATE_QUICK_OPEN command.
* @param {?string} gotoLineQuery The search query to execute after the NAVIGATE_GOTO_LINE command.
* @param {string} file The name of the file that should be opened.
* @param {number} line The line (1-based) where the cursor should be at the end of the operations.
* @param {number} col The column (1-based) where the cursor should be at the end of the operations.
* @return {function()} The configured test function.
*/
function getQuickOpenTest(quickOpenQuery, gotoLineQuery, file, line, col) {
return function () {
var editor,
$scroller;
SpecRunnerUtils.loadProjectInTestWindow(testPath);
runs(function () {
var promise = SpecRunnerUtils.openProjectFiles([]);
waitsForDone(promise, "open project files");
});
runs(function () {
// Test quick open using a partial file name
executeCommand(Commands.NAVIGATE_QUICK_OPEN);
// need to set the timeout length here to ensure that it has a chance to load the file
// list.
enterSearchText(quickOpenQuery, 100);
});
waitsFor(function () {
return getSearchField().val() === quickOpenQuery;
}, "filename entry timeout", 1000);
runs(function () {
pressEnter();
});
waitsFor(function () {
editor = EditorManager.getCurrentFullEditor();
return editor !== null && getSearchBar().length === 0;
}, "file opening timeout", 3000);
runs(function () {
$scroller = test$(editor.getScrollerElement());
// Make sure we've opened the right file. It should open the longer one, because
// of the scoring in the StringMatch algorithm.
expect(DocumentManager.getCurrentDocument().file.name).toEqual(file);
if (gotoLineQuery) {
// Test go to line
executeCommand(Commands.NAVIGATE_GOTO_LINE);
enterSearchText(gotoLineQuery);
}
});
runs(function () {
if (gotoLineQuery) {
var editor = EditorManager.getCurrentFullEditor();
SpecRunnerUtils.resizeEditor(editor, 0, 600);
waitsFor(function () {
return getSearchField().val() === gotoLineQuery;
}, "goto line entry timeout", 1000);
runs(function () {
pressEnter();
});
// wait for ModalBar to close
waitsFor(function () {
return getSearchBar().length === 0;
}, "ModalBar close", 1000);
}
});
runs(function () {
// The user enters a 1-based number, but the reported position
// is 0 based, so we check for line-1, col-1.
expect(editor).toHaveCursorPosition(line - 1, col - 1);
// We expect the result to be scrolled roughly to the middle of the window.
var offset = $scroller.offset().top;
var editorHeight = $scroller.height();
var cursorPos = editor._codeMirror.cursorCoords(null, "page").bottom;
expect(cursorPos).toBeGreaterThan(editorHeight * 0.4 + offset);
expect(cursorPos).toBeLessThan(editorHeight * 0.6 + offset);
});
};
}
it("can open a file and jump to a line, centering that line on the screen",
getQuickOpenTest("lines", ":50", "lotsOfLines.html", 50, 1));
it("can open a file and jump to a line and column, centering that line on the screen",
getQuickOpenTest("lines", ":50,20", "lotsOfLines.html", 50, 20));
it("can directly open a file in a given line and column, centering that line on the screen",
getQuickOpenTest("lines:150,20", null, "lotsOfLines.html", 150, 20));
});
});