@@ -25,9 +25,10 @@ define(function (require, exports, module) {
2525 // Recommended to avoid reloading the integration test window Phoenix instance for each test.
2626
2727 const SpecRunnerUtils = brackets . getModule ( "spec/SpecRunnerUtils" ) ,
28+ StringUtils = brackets . getModule ( "utils/StringUtils" ) ,
2829 KeyEvent = brackets . getModule ( "utils/KeyEvent" ) ;
2930
30- describe ( "LegacyInteg :HTML Code Hints integration tests" , function ( ) {
31+ describe ( "integration :HTML Code Hints integration tests" , function ( ) {
3132
3233 const testPath = SpecRunnerUtils . getTestPath ( "/spec/LiveDevelopment-MultiBrowser-test-files" ) ;
3334
@@ -40,11 +41,12 @@ define(function (require, exports, module) {
4041 MainViewManager ,
4142 brackets ,
4243 FileSystem ,
44+ CSSUtils ,
4345 $ ;
4446
4547
4648 beforeAll ( async function ( ) {
47- testWindow = await SpecRunnerUtils . createTestWindowAndRun ( { forceReload : true } ) ;
49+ testWindow = await SpecRunnerUtils . createTestWindowAndRun ( ) ;
4850 brackets = testWindow . brackets ;
4951 $ = testWindow . $ ;
5052 FileViewController = brackets . test . FileViewController ;
@@ -54,6 +56,7 @@ define(function (require, exports, module) {
5456 EditorManager = brackets . test . EditorManager ;
5557 MainViewManager = brackets . test . MainViewManager ;
5658 FileSystem = brackets . test . FileSystem ;
59+ CSSUtils = brackets . test . CSSUtils ;
5760
5861 await SpecRunnerUtils . loadProjectInTestWindow ( testPath ) ;
5962 } , 30000 ) ;
@@ -62,6 +65,7 @@ define(function (require, exports, module) {
6265 FileViewController = null ;
6366 ProjectManager = null ;
6467 testWindow = null ;
68+ CSSUtils = null ;
6569 brackets = null ;
6670 await SpecRunnerUtils . closeTestWindow ( ) ;
6771 } , 30000 ) ;
@@ -71,12 +75,16 @@ define(function (require, exports, module) {
7175 "closing all file" ) ;
7276 }
7377
74- it ( "Should jump to definition on div tag" , async function ( ) {
78+ async function openFile ( fileNameInProject , workingSet ) {
7579 await awaitsForDone (
7680 FileViewController . openAndSelectDocument (
77- testPath + "/jumpToDef.html" ,
78- FileViewController . PROJECT_MANAGER
81+ testPath + "/" + fileNameInProject ,
82+ workingSet ? FileViewController . WORKING_SET_VIEW : FileViewController . PROJECT_MANAGER
7983 ) ) ;
84+ }
85+
86+ it ( "Should jump to definition on div tag" , async function ( ) {
87+ await openFile ( "jumpToDef.html" ) ;
8088 const selected = ProjectManager . getSelectedItem ( ) ;
8189 expect ( selected . fullPath ) . toBe ( testPath + "/jumpToDef.html" ) ;
8290
@@ -93,11 +101,7 @@ define(function (require, exports, module) {
93101 } ) ;
94102
95103 it ( "Should jump to definition on css class" , async function ( ) {
96- await awaitsForDone (
97- FileViewController . openAndSelectDocument (
98- testPath + "/jumpToDef.html" ,
99- FileViewController . PROJECT_MANAGER
100- ) ) ;
104+ await openFile ( "jumpToDef.html" ) ;
101105 const selected = ProjectManager . getSelectedItem ( ) ;
102106 expect ( selected . fullPath ) . toBe ( testPath + "/jumpToDef.html" ) ;
103107
@@ -114,11 +118,7 @@ define(function (require, exports, module) {
114118 } ) ;
115119
116120 async function verifySrcJumpToDef ( location , targetFileName , jumpShouldFail ) {
117- await awaitsForDone (
118- FileViewController . openAndSelectDocument (
119- testPath + "/jumpToDef.html" ,
120- FileViewController . PROJECT_MANAGER
121- ) ) ;
121+ await openFile ( "jumpToDef.html" ) ;
122122 const selected = ProjectManager . getSelectedItem ( ) ;
123123 expect ( selected . fullPath ) . toBe ( testPath + "/jumpToDef.html" ) ;
124124
@@ -198,5 +198,105 @@ define(function (require, exports, module) {
198198 await createAndVerifyFileContents ( "test1.txt" , "" ) ;
199199 } ) ;
200200
201+ async function _validateCodeHints ( cursor , expectedSomeHintsArray , selectItemNumber ) {
202+ let editor = EditorManager . getActiveEditor ( ) ;
203+ editor . setCursorPos ( cursor ) ;
204+
205+ await awaitsForDone ( CommandManager . execute ( Commands . SHOW_CODE_HINTS ) ,
206+ "show code hints" ) ;
207+
208+ await awaitsFor ( async function ( ) {
209+ for ( let hint of expectedSomeHintsArray ) {
210+ const allSelectors = await CSSUtils . getAllCssSelectorsInProject ( ) ;
211+ if ( ! allSelectors . includes ( "." + hint ) ) {
212+ return false ;
213+ }
214+ }
215+ return true ;
216+ } , "CSSUtils project selectors to be updated" ) ;
217+
218+ await awaitsFor ( function ( ) {
219+ return $ ( ".codehint-menu" ) . is ( ":visible" ) ;
220+ } , "codehints to be shown" ) ;
221+
222+ await awaitsFor ( function ( ) {
223+ for ( let hint of expectedSomeHintsArray ) {
224+ if ( ! $ ( ".codehint-menu" ) . text ( ) . includes ( hint ) ) {
225+ return false ;
226+ }
227+ }
228+ return true ;
229+ } , "expected hints to be there" ) ;
230+
231+ if ( selectItemNumber >= 0 ) {
232+ $ ( ".code-hints-list-item" ) [ selectItemNumber ] . click ( ) ;
233+ return ;
234+ }
235+
236+ SpecRunnerUtils . simulateKeyEvent ( KeyEvent . DOM_VK_ESCAPE , "keydown" , testWindow . document . body ) ;
237+ await awaitsFor ( function ( ) {
238+ return ! $ ( ".codehint-menu" ) . is ( ":visible" ) ;
239+ } , "codehints to be hidden" ) ;
240+ }
241+
242+ it ( "Should show css class hints in html file" , async function ( ) {
243+ await openFile ( "jumpToDef.html" , true ) ;
244+ await _validateCodeHints ( { line : 9 , ch : 21 } , [ "testClass" ] ) ;
245+ await closeSession ( ) ;
246+ } ) ;
247+
248+ it ( "should show inline styles in html document" , async function ( ) {
249+ await openFile ( "inlineStyle.html" , true ) ;
250+ await _validateCodeHints ( { line : 12 , ch : 19 } , [ "integratedStyle" ] ) ;
251+ await closeSession ( ) ;
252+ } ) ;
253+
254+ function setText ( cursor , text ) {
255+ let editor = EditorManager . getActiveEditor ( ) ;
256+ editor . replaceRange ( text , cursor ) ;
257+ }
258+
259+ it ( "should inline css class hint in unsaved html inline styles" , async function ( ) {
260+ await openFile ( "inlineStyle.html" , true ) ;
261+ setText ( { line : 8 , ch : 11 } , ".newInlineStyleYo{}" ) ;
262+ await _validateCodeHints ( { line : 12 , ch : 19 } , [ "newInlineStyleYo" ] ) ;
263+ await closeSession ( ) ;
264+ } ) ;
265+
266+ async function _validateCssEdit ( cssFileName ) {
267+ await openFile ( "inlineStyle.html" , true ) ;
268+ await openFile ( cssFileName , true ) ;
269+ const cssClassName = StringUtils . randomString ( 5 , "cls" ) ;
270+ setText ( { line : 0 , ch : 0 } , `.${ cssClassName } {}\n` ) ;
271+
272+ await openFile ( "inlineStyle.html" , true ) ;
273+ await _validateCodeHints ( { line : 12 , ch : 16 } , [ cssClassName ] ) ;
274+ await closeSession ( ) ;
275+ }
276+
277+ it ( "should CSS file edits show up in class list without saving" , async function ( ) {
278+ await _validateCssEdit ( "cssLive.css" ) ;
279+ } ) ;
280+
281+ it ( "should LESS file edits show up in class list without saving" , async function ( ) {
282+ await _validateCssEdit ( "cssLive1.less" ) ;
283+ } ) ;
284+
285+ it ( "should SCSS file edits show up in class list without saving" , async function ( ) {
286+ await _validateCssEdit ( "cssLive1.scss" ) ;
287+ } ) ;
288+
289+ it ( "should be able to add the class name by selecting the code hint" , async function ( ) {
290+ await openFile ( "inlineStyle.html" , true ) ;
291+ await openFile ( "cssLive.css" , true ) ;
292+ const cssClassName = StringUtils . randomString ( 5 , "cls" ) ;
293+ setText ( { line : 0 , ch : 0 } , `.${ cssClassName } {}\n` ) ;
294+
295+ await openFile ( "inlineStyle.html" , true ) ;
296+ setText ( { line : 12 , ch : 31 } , ` ` ) ;
297+ await _validateCodeHints ( { line : 12 , ch : 32 } , [ cssClassName ] , 0 ) ;
298+ expect ( EditorManager . getActiveEditor ( ) . getToken ( ) . string ) . toBe ( `"integratedStyle ${ cssClassName } "` ) ;
299+ await closeSession ( ) ;
300+ } ) ;
201301 } ) ;
202302} ) ;
0 commit comments