@@ -667,7 +667,7 @@ define(function (require, exports, module) {
667667 ) ;
668668 }
669669
670- async function _livePreviewCodeHintsHTMLCSSClass ( onlyOnce ) {
670+ async function _livePreviewCodeHintsHTMLCSSClass ( onlyOnce , position = { line : 15 , ch : 24 } ) {
671671 await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "inline-style.html" ] ) ,
672672 "SpecRunnerUtils.openProjectFiles inline-style.html" ) ;
673673
@@ -676,62 +676,85 @@ define(function (require, exports, module) {
676676 await awaitsFor ( ( ) => LiveDevMultiBrowser . status === LiveDevMultiBrowser . STATUS_ACTIVE ,
677677 "status active" ) ;
678678
679- await _openCodeHints ( { line : 15 , ch : 24 } , [ "testClass2" , "testClass" ] ) ;
679+ await _openCodeHints ( position , [ "testClass2" , "testClass" ] ) ;
680680
681681 let editor = EditorManager . getActiveEditor ( ) ;
682682 const initialHistoryLength = editor . getHistory ( ) . done . length ;
683+ const $ = testWindow . $ ;
684+ let initialSelectedCodeHint = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
683685 SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_DOWN , "keydown" , testWindow . document . body ) ;
684686 await awaitsFor ( function ( ) {
685- return editor . getSelectedText ( ) === "testClass2" ;
686- } , "expected live hints to update selection to testClass2" ) ;
687- await _waitForLivePreviewElementClass ( "testId" , "testClass2" ) ;
687+ let newSelectedCodeHint = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
688+ return newSelectedCodeHint !== initialSelectedCodeHint &&
689+ editor . getSelectedText ( ) === newSelectedCodeHint ;
690+ } , "expected live hints to update selection to next code hint" ) ;
691+ let newSelectedCodeHint = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
692+ await _waitForLivePreviewElementClass ( "testId" , newSelectedCodeHint ) ;
688693 if ( onlyOnce ) {
689694 return initialHistoryLength ;
690695 }
691696 SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_DOWN , "keydown" , testWindow . document . body ) ;
692697 await awaitsFor ( function ( ) {
693- return editor . getSelectedText ( ) === "testClass" ;
694- } , "expected live hints to update selection to testClass" ) ;
695- await _waitForLivePreviewElementClass ( "testId" , "testClass" ) ;
698+ let newSelectedCodeHint2 = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
699+ return newSelectedCodeHint !== newSelectedCodeHint2 &&
700+ editor . getSelectedText ( ) === newSelectedCodeHint2 ;
701+ } , "expected live hints to update selection" ) ;
702+ let newSelectedCodeHint2 = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
703+ await _waitForLivePreviewElementClass ( "testId" , newSelectedCodeHint2 ) ;
696704 return initialHistoryLength ;
697705 }
698706
699- it ( "should Live preview push html css class code hints selection changes to browser" , async function ( ) {
700- const expectedHistoryLength = await _livePreviewCodeHintsHTMLCSSClass ( ) ;
707+ async function _testAtPos ( pos , endKey = KeyEvent . DOM_VK_ESCAPE , onlyOnce = false ,
708+ additionalHistoryLengthExpected = 0 ) {
709+ const expectedHistoryLength = await _livePreviewCodeHintsHTMLCSSClass ( onlyOnce , pos ) ;
701710 let editor = EditorManager . getActiveEditor ( ) ;
702711
703712 // now dismiss with escape
704- SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_ESCAPE , "keydown" , testWindow . document . body ) ;
713+ const $ = testWindow . $ ;
714+ let selectedCodeHint = $ ( $ ( ".code-hints-list-item .highlight .brackets-html-hints" ) ) . text ( ) ;
715+ expect ( selectedCodeHint ) . toBeDefined ( ) ;
716+ SpecRunnerUtils . simulateKeyEvent ( endKey , "keydown" , testWindow . document . body ) ;
705717 await awaitsFor ( function ( ) {
706718 return ! testWindow . $ ( ".codehint-menu" ) . is ( ":visible" ) ;
707719 } , "codehints to be hidden" ) ;
708720 await awaitsFor ( function ( ) {
709721 return editor . getSelectedText ( ) === "" ;
710722 } , "to restore the text to old state" ) ;
711- expect ( editor . getToken ( ) . string ) . toBe ( '"testClass"' ) ;
712723
713- // the undo history should be same as when we started
714- expect ( editor . getHistory ( ) . done . length ) . toBe ( expectedHistoryLength ) ;
724+ // the undo history should be what we expect
725+ expect ( editor . getHistory ( ) . done . length ) . toBe ( expectedHistoryLength + additionalHistoryLengthExpected ) ;
726+ return selectedCodeHint ;
727+ }
728+
729+ it ( "should Live preview push html css class code hints selection changes to browser" , async function ( ) {
730+ //<p id="testId" class="t<cursor>estClass ">Brackets is awesome!</p>
731+ await _testAtPos ( { line : 15 , ch : 24 } ) ;
732+ let editor = EditorManager . getActiveEditor ( ) ;
733+ expect ( editor . getToken ( ) . string ) . toBe ( '"testClass "' ) ;
715734 await endPreviewSession ( ) ;
716735 } , 30000 ) ;
717736
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 ) ;
737+ it ( "should Live preview push html css class code hints on empty input selection changes to browser" , async function ( ) {
738+ //<p id="testId" class="testClass <cursor>">Brackets is awesome!</p>
739+ await _testAtPos ( { line : 15 , ch : 32 } ) ;
720740 let editor = EditorManager . getActiveEditor ( ) ;
741+ expect ( editor . getToken ( ) . string ) . toBe ( '"testClass "' ) ;
742+ await endPreviewSession ( ) ;
743+ } , 30000 ) ;
721744
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"' ) ;
745+ it ( "should Live preview push html css class code hints selection changes to browser and commit" , async function ( ) {
746+ //<p id="testId" class="t<cursor>estClass ">Brackets is awesome!</p>
747+ await _testAtPos ( { line : 15 , ch : 24 } , KeyEvent . DOM_VK_RETURN , true , 3 ) ;
748+ let editor = EditorManager . getActiveEditor ( ) ;
749+ expect ( editor . getToken ( ) . string ) . toBe ( '"testClass2 "' ) ;
750+ await endPreviewSession ( ) ;
751+ } , 30000 ) ;
732752
733- // the undo history should be just one above
734- expect ( editor . getHistory ( ) . done . length ) . toBe ( expectedHistoryLength + 3 ) ;
753+ it ( "should Live preview push html css class code hints on empty input selection changes to browser and commit" , async function ( ) {
754+ //<p id="testId" class="testClass <cursor>">Brackets is awesome!</p>
755+ const selectedHint = await _testAtPos ( { line : 15 , ch : 32 } , KeyEvent . DOM_VK_RETURN , true , 2 ) ;
756+ let editor = EditorManager . getActiveEditor ( ) ;
757+ expect ( editor . getToken ( ) . string ) . toBe ( `"testClass ${ selectedHint } "` ) ;
735758 await endPreviewSession ( ) ;
736759 } , 30000 ) ;
737760
0 commit comments