@@ -78,6 +78,29 @@ define(function (require, exports, module) {
7878 $gitIcon = $ ( "#git-toolbar-icon" ) ;
7979 } ) ;
8080
81+ it ( "should git username and email be valid" , async function ( ) {
82+ const tempUser = "phcodeTestGitUser" ;
83+ const tempEmail = "[email protected] " ; 84+ // username validate
85+ let currentVal = await testWindow . phoenixGitEvents . Git . getConfig ( "user.name" ) ;
86+ if ( ! currentVal ) {
87+ await testWindow . phoenixGitEvents . Git . setConfig ( "user.name" , tempUser , true ) ;
88+ currentVal = await testWindow . phoenixGitEvents . Git . getConfig ( "user.name" ) ;
89+ expect ( currentVal ) . toBe ( tempUser ) ;
90+ } else {
91+ expect ( currentVal ) . toBeDefined ( ) ;
92+ }
93+ // email validate
94+ currentVal = await testWindow . phoenixGitEvents . Git . getConfig ( "user.email" ) ;
95+ if ( ! currentVal ) {
96+ await testWindow . phoenixGitEvents . Git . setConfig ( "user.email" , tempEmail , true ) ;
97+ currentVal = await testWindow . phoenixGitEvents . Git . getConfig ( "user.email" ) ;
98+ expect ( currentVal ) . toBe ( tempEmail ) ;
99+ } else {
100+ expect ( currentVal ) . toBeDefined ( ) ;
101+ }
102+ } ) ;
103+
81104 it ( "should only git settings, init and clone commands be enabled in non-git repos" , async function ( ) {
82105 await forCommandEnabled ( Commands . CMD_GIT_INIT ) ;
83106 await forCommandEnabled ( Commands . CMD_GIT_CLONE ) ;
@@ -255,6 +278,76 @@ define(function (require, exports, module) {
255278 return $ ( ".git-edited-list tr" ) . length === 0 ;
256279 } , "no files to be commited" , 10000 ) ;
257280 } ) ;
281+
282+ async function waitForHistoryVisible ( visible ) {
283+ await awaitsFor ( ( ) => {
284+ return $gitPanel . find ( "#git-history-list" ) . is ( ":visible" ) === visible ;
285+ } , `History list to be visible: ${ visible } ` ) ;
286+ }
287+
288+ async function testHistoryToggle ( whichHistory ) {
289+ const $historyToggleButton = $gitPanel . find ( whichHistory ) ;
290+
291+ $historyToggleButton . trigger ( "click" ) ;
292+ await waitForHistoryVisible ( true ) ;
293+
294+ const $historyList = $gitPanel . find ( "#git-history-list" ) ;
295+
296+ // Check if the first and second commits are displayed
297+ const $historyCommits = $historyList . find ( ".commit-subject" ) ;
298+ expect ( $historyCommits . length ) . toBeGreaterThanOrEqual ( 2 ) ;
299+
300+ // Verify the content of the first and second commits
301+ expect ( $historyCommits . eq ( 0 ) . text ( ) . trim ( ) ) . toBe ( "second commit" ) ;
302+ expect ( $historyCommits . eq ( 1 ) . text ( ) . trim ( ) ) . toBe ( "first commit" ) ;
303+
304+ $historyToggleButton . trigger ( "click" ) ;
305+ await waitForHistoryVisible ( false ) ;
306+ }
307+
308+ it ( "should show history with first and second commit on clicking global history" , async ( ) => {
309+ await testHistoryToggle ( ".git-history-toggle" ) ;
310+ } ) ;
311+
312+ it ( "should show history with first and second commit on clicking global history" , async ( ) => {
313+ await testHistoryToggle ( ".git-file-history" ) ;
314+ } ) ;
315+
316+ async function waitForHistoryViewerVisible ( visible ) {
317+ await awaitsFor ( ( ) => {
318+ return $ ( "#history-viewer" ) . is ( ":visible" ) === visible ;
319+ } , `History viewer to be visible: ${ visible } ` ) ;
320+ }
321+
322+ async function testHistoryViewerToggle ( commitIndex ) {
323+ const $historyList = $gitPanel . find ( "#git-history-list" ) ;
324+ const $commitRow = $historyList . find ( ".history-commit" ) . eq ( commitIndex ) ;
325+
326+ // Ensure the commit row exists
327+ expect ( $commitRow . length ) . toBe ( 1 ) ;
328+
329+ // Click the row to show the history viewer
330+ $commitRow . trigger ( "click" ) ;
331+ await waitForHistoryViewerVisible ( true ) ;
332+
333+ // Verify that the history viewer shows the correct commit
334+ const $historyViewer = $ ( "#editor-holder .git" ) ;
335+ await awaitsFor ( ( ) => {
336+ return $historyViewer . find ( ".commit-title" ) . text ( ) . trim ( ) . includes ( "first commit" ) ;
337+ } , `History viewer to have commit detail` ) ;
338+
339+ // Click the row again to dismiss the history viewer
340+ $commitRow . trigger ( "click" ) ;
341+ await waitForHistoryViewerVisible ( false ) ;
342+ }
343+
344+ it ( "should show the history viewer when clicking the first commit row and dismiss it on clicking again" , async ( ) => {
345+ const $historyToggleButton = $gitPanel . find ( ".git-history-toggle" ) ;
346+ $historyToggleButton . trigger ( "click" ) ;
347+ await waitForHistoryVisible ( true ) ; // Ensure the history list is visible
348+ await testHistoryViewerToggle ( 1 ) ; // Test for the first commit row
349+ } ) ;
350+
258351 } ) ;
259352
260353 } ) ;
0 commit comments