1919 *
2020 */
2121
22- /*global describe, it, expect, beforeAll, afterAll, awaitsForDone, awaits, awaitsFor, path, jsPromise */
22+ /*global describe, it, expect, beforeAll, afterAll, beforeEach, awaitsForDone, awaits, awaitsFor, path, jsPromise */
2323
2424define ( function ( require , exports , module ) {
2525
@@ -33,6 +33,9 @@ define(function (require, exports, module) {
3333 testWindow ,
3434 $ ,
3535 CodeInspection ,
36+ CommandManager ,
37+ Commands ,
38+ EditorManager ,
3639 NodeUtils ,
3740 FileSystem ;
3841
@@ -42,7 +45,10 @@ define(function (require, exports, module) {
4245 $ = testWindow . $ ;
4346 CodeInspection = testWindow . brackets . test . CodeInspection ;
4447 NodeUtils = testWindow . brackets . test . NodeUtils ;
48+ EditorManager = testWindow . brackets . test . EditorManager ;
4549 FileSystem = testWindow . brackets . test . FileSystem ;
50+ CommandManager = testWindow . brackets . test . CommandManager ;
51+ Commands = testWindow . brackets . test . Commands ;
4652 CodeInspection . toggleEnabled ( true ) ;
4753 await awaitsFor ( ( ) => testWindow . _JsHintExtensionReadyToIntegTest ,
4854 "JsHint extension to be loaded" , 10000 ) ;
@@ -54,6 +60,9 @@ define(function (require, exports, module) {
5460 NodeUtils = null ;
5561 CodeInspection = null ;
5662 FileSystem = null ;
63+ EditorManager = null ;
64+ CommandManager = null ;
65+ Commands = null ;
5766 await SpecRunnerUtils . closeTestWindow ( ) ;
5867 } , 30000 ) ;
5968
@@ -310,5 +319,89 @@ define(function (require, exports, module) {
310319 } , "eslint new eq rule added to be honored in lint" ) ;
311320 } , 5000 ) ;
312321 } ) ;
322+
323+ describe ( "ESLint v9 with fixes project" , function ( ) {
324+ let esLatestProjectPath , originalErrorFile ;
325+
326+ beforeAll ( async function ( ) {
327+ esLatestProjectPath = await _createTempProject ( "es9_with_fixes" ) ;
328+ await _npmInstallInFolder ( esLatestProjectPath ) ;
329+ await SpecRunnerUtils . loadProjectInTestWindow ( esLatestProjectPath ) ;
330+ await _openProjectFile ( "error.js" ) ;
331+ const editor = EditorManager . getCurrentFullEditor ( ) ;
332+ originalErrorFile = editor . document . getText ( ) ;
333+ } , 30000 ) ;
334+
335+ beforeEach ( async function ( ) {
336+ await jsPromise ( SpecRunnerUtils . createTextFile ( path . join ( esLatestProjectPath , "error.js" ) ,
337+ originalErrorFile , FileSystem ) ) ;
338+ await testWindow . closeAllFiles ( ) ;
339+ } ) ;
340+
341+ async function _openAndVerifyInitial ( ) {
342+ await _openProjectFile ( "error.js" ) ;
343+ await _waitForProblemsPanelVisible ( true ) ;
344+ await awaitsFor ( ( ) => {
345+ return $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) . length === 2 ;
346+ } , "There should be 2 fix problem button in the panel" ) ;
347+ }
348+
349+ async function _triggerLint ( ) {
350+ await _openProjectFile ( "package.json" ) ;
351+ await _openProjectFile ( "error.js" ) ;
352+ }
353+
354+ it ( "should ESLint v9 show fix buttons" , async function ( ) {
355+ await _openAndVerifyInitial ( ) ;
356+ } , 5000 ) ;
357+
358+ it ( "should be able to fix 1 error" , async function ( ) {
359+ await _openAndVerifyInitial ( ) ;
360+ // click on fix : Expected indentation of 4 spaces but found 9. ESLint (indent)
361+ $ ( $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) [ 0 ] ) . click ( ) ;
362+ await awaitsFor ( ( ) => {
363+ return $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) . length === 1 ;
364+ } , "only 1 problem should remain" ) ;
365+
366+ // it should select the edited text
367+ const editor = EditorManager . getCurrentFullEditor ( ) ;
368+ expect ( editor . getSelectedText ( ) ) . toBe ( " " ) ;
369+ const selection = editor . getSelection ( ) ;
370+ expect ( selection . start ) . toEql ( { line : 3 , ch : 0 , sticky : null } ) ;
371+ expect ( selection . end ) . toEql ( { line : 3 , ch : 4 , sticky : null } ) ;
372+
373+ // undo should work
374+ await awaitsForDone ( CommandManager . execute ( Commands . EDIT_UNDO ) , "undo" ) ;
375+ expect ( editor . getSelectedText ( ) ) . toBe ( " " ) ;
376+ await _triggerLint ( ) ;
377+ await awaitsFor ( ( ) => {
378+ return $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) . length === 2 ;
379+ } , "2 problem should be there" ) ;
380+ } , 5000 ) ;
381+
382+ it ( "should be able to fix all errors" , async function ( ) {
383+ await _openAndVerifyInitial ( ) ;
384+ const editor = EditorManager . getCurrentFullEditor ( ) ;
385+ editor . setCursorPos ( 0 , 0 ) ; // resent any saved selections from previous run
386+ // click on fix : Expected indentation of 4 spaces but found 9. ESLint (indent)
387+ $ ( $ ( "#problems-panel" ) . find ( ".problems-fix-all-btn" ) ) . click ( ) ;
388+ await awaitsFor ( ( ) => {
389+ return $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) . length === 0 ;
390+ } , "no problems should remain as all is now fixed" ) ;
391+
392+ // fixing multiple should place the cursor on first fix
393+ expect ( editor . hasSelection ( ) ) . toBeFalse ( ) ;
394+ expect ( editor . getCursorPos ( ) ) . toEql ( { line : 3 , ch : 0 , sticky : null } ) ;
395+
396+ await awaitsForDone ( CommandManager . execute ( Commands . EDIT_UNDO ) , "undo" ) ;
397+ expect ( editor . hasSelection ( ) ) . toBeFalse ( ) ;
398+ expect ( editor . getSelections ( ) . length ) . toBe ( 1 ) ; // no multi cursor on undo
399+
400+ await _triggerLint ( ) ;
401+ await awaitsFor ( ( ) => {
402+ return $ ( "#problems-panel" ) . find ( ".ph-fix-problem" ) . length === 2 ;
403+ } , "2 problem should be there" ) ;
404+ } , 5000 ) ;
405+ } ) ;
313406 } ) ;
314407} ) ;
0 commit comments