@@ -27,7 +27,7 @@ define(function (require, exports, module) {
2727 return ;
2828 }
2929
30- let $ , __PR , testWindow , ExtensionLoader , Menus , Commands , CommandManager ,
30+ let $ , __PR , testWindow , ExtensionLoader , Menus , Commands , CommandManager , EditorManager ,
3131 SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ,
3232 anotherTestFolder = SpecRunnerUtils . getTestPath ( "/spec/LowLevelFileIO-test-files" ) ;
3333
@@ -60,6 +60,7 @@ define(function (require, exports, module) {
6060 ExtensionLoader = testWindow . brackets . test . ExtensionLoader ;
6161 Commands = testWindow . brackets . test . Commands ;
6262 CommandManager = testWindow . brackets . test . CommandManager ;
63+ EditorManager = testWindow . brackets . test . EditorManager ;
6364 testPathGit = await SpecRunnerUtils . getTempTestDirectory ( "/spec/EditorCommandHandlers-test-files" ) ;
6465
6566 await SpecRunnerUtils . loadProjectInTestWindow ( testPathGit ) ;
@@ -69,7 +70,8 @@ define(function (require, exports, module) {
6970 } , "Git menus to be present" , 10000 ) ;
7071 } , 30000 ) ;
7172
72- describe ( "Init repo and do all tests" , function ( ) {
73+ describe ( "Init repo and do all tests in order" , function ( ) {
74+ // ordering of tests in this matters and it may not run as individual tests.
7375 let $gitPanel , $gitIcon ;
7476 beforeAll ( async function ( ) {
7577 $gitPanel = $ ( "#git-panel" ) ;
@@ -116,15 +118,80 @@ define(function (require, exports, module) {
116118 expect ( $ ( ".check-all" ) . prop ( "checked" ) ) . toBeFalse ( ) ;
117119 } ) ;
118120
119- it ( "Should be able to stage and commit initialized git repo" , async function ( ) {
121+ function clickOpenFile ( elementNumber ) {
122+ const $elements = $gitPanel . find ( ".modified-file" ) ; // Get all .modified-file elements
123+ if ( elementNumber >= 0 && elementNumber < $elements . length ) {
124+ $ ( $elements [ elementNumber ] ) . trigger ( "mousedown" ) ; // Trigger mousedown on the specified element
125+ } else {
126+ console . error ( "Invalid element number:" , elementNumber ) ; // Handle invalid index
127+ }
128+ }
129+
130+
131+ it ( "Should clicking on file in git panel should open it" , async function ( ) {
120132 await showGitPanel ( ) ;
121- expect ( $ ( ".check-all" ) . prop ( "checked" ) ) . toBeFalse ( ) ;
122- $ ( ".check-all" ) . click ( ) ;
133+ clickOpenFile ( 0 ) ;
123134 await awaitsFor ( ( ) => {
124- const checkboxes = document . querySelectorAll ( ".check-one" ) ;
125- return Array . from ( checkboxes ) . every ( checkbox => checkbox . checked ) ;
126- } , "All files to be staged for commit" , 10000 ) ;
135+ const editor = EditorManager . getActiveEditor ( ) ;
136+ if ( ! editor ) {
137+ return false ;
138+ }
139+ return editor . document . file . fullPath . endsWith ( ".gitignore" ) ;
140+ } , "first file to open" ) ;
141+ } ) ;
142+
143+ async function commitAllBtnClick ( ) {
144+ await showGitPanel ( ) ;
145+ if ( ! $ ( ".check-all" ) . prop ( "checked" ) ) {
146+ $ ( ".check-all" ) . click ( ) ;
147+ await awaitsFor ( ( ) => {
148+ const checkboxes = document . querySelectorAll ( ".check-one" ) ;
149+ return Array . from ( checkboxes ) . every ( checkbox => checkbox . checked ) ;
150+ } , "All files to be staged for commit" , 10000 ) ;
151+ }
127152 $ ( ".git-commit" ) . click ( ) ;
153+ await __PR . waitForModalDialog ( "#git-commit-dialog" ) ;
154+ }
155+
156+ function expectTextToContain ( srcText , list ) {
157+ const nonEmptyLines = srcText
158+ . split ( "\n" ) // Split the text into lines
159+ . map ( line => line . trim ( ) ) // Trim each line
160+ . filter ( line => line !== "" ) . join ( "\n" ) ; // Remove empty lines
161+ for ( const text of list ) {
162+ expect ( nonEmptyLines ) . toContain ( text ) ;
163+ }
164+ }
165+
166+ it ( "Should be able to stage, show commit dialog and cancel dialog on initialized git repo" , async function ( ) {
167+ await commitAllBtnClick ( ) ;
168+ __PR . clickDialogButtonID ( __PR . Dialogs . DIALOG_BTN_CANCEL ) ;
169+ await __PR . waitForModalDialogClosed ( "#git-commit-dialog" ) ;
170+ } ) ;
171+
172+ it ( "Should git dialog show commit diff and lint errors" , async function ( ) {
173+ await commitAllBtnClick ( ) ;
174+
175+ // check lint errors
176+ await awaitsFor ( ( ) => {
177+ return $ ( ".lint-errors" ) . text ( ) . includes ( "test.html" ) ;
178+ } , "lint errors to be shown" , 10000 ) ;
179+ expect ( $ ( ".lint-errors" ) . text ( ) ) . toContain ( "<html> is missing required \"lang\" attribute" ) ;
180+ expect ( $ ( ".lint-errors" ) . is ( ":visible" ) ) . toBeTrue ( ) ;
181+
182+ // check commit diff
183+ await awaitsFor ( ( ) => {
184+ return $ ( ".commit-diff" ) . text ( ) . includes ( "test.html" ) ;
185+ } , "commit-diff to be shown" , 10000 ) ;
186+ expectTextToContain ( $ ( ".commit-diff" ) . text ( ) , [
187+ ".gitignore" , "test.css" , "test.html" , "test.js" ,
188+ "/node_modules/" , "color:" , `<head>` ,
189+ `console.log`
190+ ] ) ;
191+
192+ // dismiss dialog
193+ __PR . clickDialogButtonID ( __PR . Dialogs . DIALOG_BTN_CANCEL ) ;
194+ await __PR . waitForModalDialogClosed ( "#git-commit-dialog" ) ;
128195 } ) ;
129196 } ) ;
130197
0 commit comments