@@ -63,6 +63,38 @@ define(function (require, exports, module) {
6363 await __PR . closeFile ( ) ;
6464 } ) ;
6565
66+ function parseColorToRGB ( color ) {
67+ // Create a temporary element to leverage the browser’s color parsing
68+ const temp = document . createElement ( "div" ) ;
69+ temp . style . color = color ;
70+ document . body . appendChild ( temp ) ;
71+
72+ // Compute the color set by the browser
73+ const parsedColor = window . getComputedStyle ( temp ) . color ; // returns in rgb(...) format
74+ document . body . removeChild ( temp ) ;
75+
76+ return parsedColor ;
77+ }
78+
79+ function areColorsEqual ( $element , color ) {
80+ const elem = $element instanceof $ ? $element [ 0 ] : $element ;
81+ const computedStyle = window . getComputedStyle ( elem ) ;
82+
83+ const elementColor = computedStyle . backgroundColor ; // typically returns "rgb(r, g, b)"
84+ const normalizedGivenColor = parseColorToRGB ( color ) ; // convert given color to "rgb(r, g, b)"
85+
86+ return elementColor === normalizedGivenColor ;
87+ }
88+
89+ function validateMultipleColors ( editor , lineNumber , colors ) {
90+ const gutterMarker = $ ( editor . getGutterMarker ( lineNumber , GUTTER_NAME ) ) . find ( ".color-box" ) ;
91+ let numColors = gutterMarker . length ;
92+ __PR . validateEqual ( numColors , colors . length ) ;
93+ for ( let i = 0 ; i < numColors ; i ++ ) {
94+ __PR . validateEqual ( areColorsEqual ( $ ( gutterMarker [ i ] ) , colors [ i ] ) , true ) ;
95+ }
96+ }
97+
6698 function testHTMLFile ( fileName ) {
6799 it ( `should color gutter appear as expected ${ fileName } ` , async function ( ) {
68100 const htmlText = await __PR . readTextFile ( "base.html" ) ;
@@ -94,10 +126,34 @@ define(function (require, exports, module) {
94126 await __PR . closeFile ( ) ;
95127
96128 } ) ;
129+
130+ it ( `should color gutter show correct colors in box ${ fileName } ` , async function ( ) {
131+ const htmlText = await __PR . readTextFile ( "base.html" ) ;
132+ await __PR . writeTextFile ( fileName , htmlText , true ) ;
133+ await __PR . openFile ( fileName ) ;
134+ const editor = EditorManager . getActiveEditor ( ) ;
135+ __PR . validateEqual ( editor . isGutterActive ( GUTTER_NAME ) , true ) ;
136+
137+ // the line with cursor if there is no color should have a dummy color gutter
138+ __PR . setCursors ( [ "1:1" ] ) ;
139+ let gutterMarker = editor . getGutterMarker ( 8 , GUTTER_NAME ) ;
140+ __PR . validateEqual ( areColorsEqual ( $ ( gutterMarker ) , "blue" ) , true ) ;
141+ gutterMarker = editor . getGutterMarker ( 11 , GUTTER_NAME ) ;
142+ __PR . validateEqual ( areColorsEqual ( $ ( gutterMarker ) , "#00ff8c" ) , true ) ;
143+
144+ // multiple colors
145+ validateMultipleColors ( editor , 12 , [ "#00ff8c" , "red" ] ) ;
146+ validateMultipleColors ( editor , 13 , [ "#b7ff00" , "green" , "#3e4395" ] ) ;
147+ validateMultipleColors ( editor , 14 , [ "#ff0090" , "#802095" , "#954e3e" , "#454e3e" ] ) ;
148+ validateMultipleColors ( editor , 15 , [ "#ff0090" , "#802095" , "#954e3e" , "#454e3e" ] ) ;
149+ await __PR . closeFile ( ) ;
150+ } ) ;
151+
152+ // todo test beautify, block comment, line comment, comment at end of file, code changes, toggle color edit
97153 }
98154
99155 const htmlFiles = [ "a.html" , "a.htm" , "a.xhtml" , "a.php" , "a.jsp" ] ;
100- for ( let htmlFile of htmlFiles ) {
156+ for ( let htmlFile of htmlFiles ) {
101157 testHTMLFile ( htmlFile ) ;
102158 }
103159 } ) ;
0 commit comments