@@ -652,6 +652,89 @@ define(function (require, exports, module) {
652652 await endPreviewSession ( ) ;
653653 } , 30000 ) ;
654654
655+ async function _waitForLivePreviewElementClass ( elementID , classExpected ) {
656+ let result ;
657+ await awaitsFor (
658+ async function isColorChanged ( ) {
659+ const response = await LiveDevProtocol . evaluate (
660+ `document.getElementById('${ elementID } ').classList.contains('${ classExpected } ')` ) ;
661+ result = JSON . parse ( response . result || "" ) ;
662+ return result === true ;
663+ } ,
664+ `element #${ elementID } to have class ${ classExpected } ` ,
665+ 5000 ,
666+ 50
667+ ) ;
668+ }
669+
670+ async function _livePreviewCodeHintsHTMLCSSClass ( onlyOnce ) {
671+ await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "inline-style.html" ] ) ,
672+ "SpecRunnerUtils.openProjectFiles inline-style.html" ) ;
673+
674+ await waitsForLiveDevelopmentToOpen ( ) ;
675+
676+ await awaitsFor ( ( ) => LiveDevMultiBrowser . status === LiveDevMultiBrowser . STATUS_ACTIVE ,
677+ "status active" ) ;
678+
679+ await _openCodeHints ( { line : 15 , ch : 24 } , [ "testClass2" , "testClass" ] ) ;
680+
681+ let editor = EditorManager . getActiveEditor ( ) ;
682+ const initialHistoryLength = editor . getHistory ( ) . done . length ;
683+ SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_DOWN , "keydown" , testWindow . document . body ) ;
684+ await awaitsFor ( function ( ) {
685+ return editor . getSelectedText ( ) === "testClass2" ;
686+ } , "expected live hints to update selection to testClass2" ) ;
687+ await _waitForLivePreviewElementClass ( "testId" , "testClass2" ) ;
688+ if ( onlyOnce ) {
689+ return initialHistoryLength ;
690+ }
691+ SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_DOWN , "keydown" , testWindow . document . body ) ;
692+ await awaitsFor ( function ( ) {
693+ return editor . getSelectedText ( ) === "testClass" ;
694+ } , "expected live hints to update selection to testClass" ) ;
695+ await _waitForLivePreviewElementClass ( "testId" , "testClass" ) ;
696+ return initialHistoryLength ;
697+ }
698+
699+ it ( "should Live preview push html css class code hints selection changes to browser" , async function ( ) {
700+ const expectedHistoryLength = await _livePreviewCodeHintsHTMLCSSClass ( ) ;
701+ let editor = EditorManager . getActiveEditor ( ) ;
702+
703+ // now dismiss with escape
704+ SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_ESCAPE , "keydown" , testWindow . document . body ) ;
705+ await awaitsFor ( function ( ) {
706+ return ! testWindow . $ ( ".codehint-menu" ) . is ( ":visible" ) ;
707+ } , "codehints to be hidden" ) ;
708+ await awaitsFor ( function ( ) {
709+ return editor . getSelectedText ( ) === "" ;
710+ } , "to restore the text to old state" ) ;
711+ expect ( editor . getToken ( ) . string ) . toBe ( '"testClass"' ) ;
712+
713+ // the undo history should be same as when we started
714+ expect ( editor . getHistory ( ) . done . length ) . toBe ( expectedHistoryLength ) ;
715+ await endPreviewSession ( ) ;
716+ } , 30000 ) ;
717+
718+ it ( "should Live preview push html css class code hints selection changes to browser and commit" , async function ( ) {
719+ const expectedHistoryLength = await _livePreviewCodeHintsHTMLCSSClass ( true ) ;
720+ let editor = EditorManager . getActiveEditor ( ) ;
721+
722+ // now dismiss with escape
723+ SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_RETURN , "keydown" , testWindow . document . body ) ;
724+ await awaitsFor ( function ( ) {
725+ return ! testWindow . $ ( ".codehint-menu" ) . is ( ":visible" ) ;
726+ } , "codehints to be hidden" ) ;
727+ await awaitsFor ( function ( ) {
728+ return editor . getSelectedText ( ) === "" ;
729+ } , "to restore the text to old state" ) ;
730+ // check if we have the new value
731+ expect ( editor . getToken ( ) . string ) . toBe ( '"testClass2"' ) ;
732+
733+ // the undo history should be just one above
734+ expect ( editor . getHistory ( ) . done . length ) . toBe ( expectedHistoryLength + 3 ) ;
735+ await endPreviewSession ( ) ;
736+ } , 30000 ) ;
737+
655738 it ( "should Live preview work even if we switch html files" , async function ( ) {
656739 await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "simple1.html" ] ) ,
657740 "SpecRunnerUtils.openProjectFiles simple1.html" ) ;
0 commit comments