@@ -93,83 +93,103 @@ define(function (require, exports, module) {
93
93
// on the QuickOpen input.
94
94
SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_RETURN , "keyup" , getSearchField ( ) [ 0 ] ) ;
95
95
}
96
-
97
- // TODO: fix me!
98
- // This test is currently turned off due to failures on Windows 7
99
- // See https://github.com/adobe/brackets/issues/2696
100
- it ( "can open a file and jump to a line, centering that line on the screen" , function ( ) {
101
- var err = false ,
102
- editor ,
103
- $scroller ;
104
-
105
- SpecRunnerUtils . loadProjectInTestWindow ( testPath ) ;
106
-
107
- runs ( function ( ) {
108
- var promise = SpecRunnerUtils . openProjectFiles ( [ ] ) ;
109
- waitsForDone ( promise , "open project files" ) ;
110
- } ) ;
111
-
112
- runs ( function ( ) {
113
- // Test quick open using a partial file name
114
- executeCommand ( Commands . NAVIGATE_QUICK_OPEN ) ;
96
+
97
+ /**
98
+ * Creates a parameterized quick open test.
99
+ * @param {string } quickOpenQuery The search query to execute after the NAVIGATE_QUICK_OPEN command.
100
+ * @param {?string } gotoLineQuery The search query to execute after the NAVIGATE_GOTO_LINE command.
101
+ * @param {string } file The name of the file that should be opened.
102
+ * @param {number } line The line (1-based) where the cursor should be at the end of the operations.
103
+ * @param {number } col The column (1-based) where the cursor should be at the end of the operations.
104
+ * @return {function() } The configured test function.
105
+ */
106
+ function getQuickOpenTest ( quickOpenQuery , gotoLineQuery , file , line , col ) {
107
+ return function ( ) {
108
+ var err = false ,
109
+ editor ,
110
+ $scroller ;
115
111
116
- // need to set the timeout length here to ensure that it has a chance to load the file
117
- // list.
118
- enterSearchText ( "lines" , 100 ) ;
119
- } ) ;
120
-
121
- waitsFor ( function ( ) {
122
- return getSearchField ( ) . val ( ) === "lines" ;
123
- } , "filename entry timeout" , 1000 ) ;
124
-
125
- runs ( function ( ) {
126
- pressEnter ( ) ;
127
- } ) ;
128
-
129
- waitsFor ( function ( ) {
130
- editor = EditorManager . getCurrentFullEditor ( ) ;
131
- return editor !== null && getSearchBar ( ) . length === 0 ;
132
- } , "file opening timeout" , 3000 ) ;
133
-
134
- runs ( function ( ) {
135
- $scroller = test$ ( editor . getScrollerElement ( ) ) ;
136
-
137
- // Make sure we've opened the right file. It should open the longer one, because
138
- // of the scoring in the StringMatch algorithm.
139
- expect ( DocumentManager . getCurrentDocument ( ) . file . name ) . toEqual ( "lotsOfLines.html" ) ;
140
-
141
- // Test go to line
142
- executeCommand ( Commands . NAVIGATE_GOTO_LINE ) ;
143
- enterSearchText ( ":50" ) ;
144
- } ) ;
145
-
146
- waitsFor ( function ( ) {
147
- return getSearchField ( ) . val ( ) === ":50" ;
148
- } , "goto line entry timeout" , 1000 ) ;
149
-
150
- runs ( function ( ) {
151
- pressEnter ( ) ;
152
- } ) ;
153
-
154
- // wait for ModalBar to close
155
- waitsFor ( function ( ) {
156
- return getSearchBar ( ) . length === 0 ;
157
- } , "ModalBar close" , 1000 ) ;
158
-
159
- runs ( function ( ) {
160
- // The user enters a 1-based number, but the reported position
161
- // is 0 based, so we check for 49.
162
- expect ( editor ) . toHaveCursorPosition ( 49 , 0 ) ;
112
+ SpecRunnerUtils . loadProjectInTestWindow ( testPath ) ;
163
113
164
- // We expect the result to be scrolled roughly to the middle of the window.
165
- var offset = $scroller . offset ( ) . top ;
166
- var editorHeight = $scroller . height ( ) ;
167
- var cursorPos = editor . _codeMirror . cursorCoords ( null , "page" ) . bottom ;
114
+ runs ( function ( ) {
115
+ var promise = SpecRunnerUtils . openProjectFiles ( [ ] ) ;
116
+ waitsForDone ( promise , "open project files" ) ;
117
+ } ) ;
168
118
169
- expect ( cursorPos ) . toBeGreaterThan ( editorHeight * 0.4 - offset ) ;
170
- expect ( cursorPos ) . toBeLessThan ( editorHeight * 0.6 - offset ) ;
171
- } ) ;
172
- } ) ;
173
-
119
+ runs ( function ( ) {
120
+ // Test quick open using a partial file name
121
+ executeCommand ( Commands . NAVIGATE_QUICK_OPEN ) ;
122
+
123
+ // need to set the timeout length here to ensure that it has a chance to load the file
124
+ // list.
125
+ enterSearchText ( quickOpenQuery , 100 ) ;
126
+ } ) ;
127
+
128
+ waitsFor ( function ( ) {
129
+ return getSearchField ( ) . val ( ) === quickOpenQuery ;
130
+ } , "filename entry timeout" , 1000 ) ;
131
+
132
+ runs ( function ( ) {
133
+ pressEnter ( ) ;
134
+ } ) ;
135
+
136
+ waitsFor ( function ( ) {
137
+ editor = EditorManager . getCurrentFullEditor ( ) ;
138
+ return editor !== null && getSearchBar ( ) . length === 0 ;
139
+ } , "file opening timeout" , 3000 ) ;
140
+
141
+ runs ( function ( ) {
142
+ $scroller = test$ ( editor . getScrollerElement ( ) ) ;
143
+
144
+ // Make sure we've opened the right file. It should open the longer one, because
145
+ // of the scoring in the StringMatch algorithm.
146
+ expect ( DocumentManager . getCurrentDocument ( ) . file . name ) . toEqual ( file ) ;
147
+
148
+ if ( gotoLineQuery ) {
149
+ // Test go to line
150
+ executeCommand ( Commands . NAVIGATE_GOTO_LINE ) ;
151
+ enterSearchText ( gotoLineQuery ) ;
152
+ }
153
+ } ) ;
154
+
155
+ if ( gotoLineQuery ) {
156
+ waitsFor ( function ( ) {
157
+ return getSearchField ( ) . val ( ) === gotoLineQuery ;
158
+ } , "goto line entry timeout" , 1000 ) ;
159
+
160
+ runs ( function ( ) {
161
+ pressEnter ( ) ;
162
+ } ) ;
163
+
164
+ // wait for ModalBar to close
165
+ waitsFor ( function ( ) {
166
+ return getSearchBar ( ) . length === 0 ;
167
+ } , "ModalBar close" , 1000 ) ;
168
+ }
169
+
170
+ runs ( function ( ) {
171
+ // The user enters a 1-based number, but the reported position
172
+ // is 0 based, so we check for line-1, col-1.
173
+ expect ( editor ) . toHaveCursorPosition ( line - 1 , col - 1 ) ;
174
+
175
+ // We expect the result to be scrolled roughly to the middle of the window.
176
+ var offset = $scroller . offset ( ) . top ;
177
+ var editorHeight = $scroller . height ( ) ;
178
+ var cursorPos = editor . _codeMirror . cursorCoords ( null , "page" ) . bottom ;
179
+
180
+ expect ( cursorPos ) . toBeGreaterThan ( editorHeight * 0.4 - offset ) ;
181
+ expect ( cursorPos ) . toBeLessThan ( editorHeight * 0.6 - offset ) ;
182
+ } ) ;
183
+ } ;
184
+ }
185
+
186
+ it ( "can open a file and jump to a line, centering that line on the screen" ,
187
+ getQuickOpenTest ( "lines" , ":50" , "lotsOfLines.html" , 50 , 1 ) ) ;
188
+
189
+ it ( "can open a file and jump to a line and column, centering that line on the screen" ,
190
+ getQuickOpenTest ( "lines" , ":50,20" , "lotsOfLines.html" , 50 , 20 ) ) ;
191
+
192
+ it ( "can directly open a file in a given line and column, centering that line on the screen" ,
193
+ getQuickOpenTest ( "lines:150,20" , null , "lotsOfLines.html" , 150 , 20 ) ) ;
174
194
} ) ;
175
195
} ) ;
0 commit comments