@@ -80,11 +80,12 @@ define(function (require, exports, module) {
8080 }
8181
8282 // Ask provider for hints at current cursor position; expect it to return some
83- function expectHints ( provider , implicitChar ) {
83+ function expectHints ( provider , implicitChar , returnWholeObj ) {
8484 expect ( provider . hasHints ( testEditor , implicitChar ) ) . toBe ( true ) ;
8585 var hintsObj = provider . getHints ( ) ;
8686 expect ( hintsObj ) . toBeTruthy ( ) ;
87- return extractHintList ( hintsObj . hints ) ; // return just the array of hints
87+ // return just the array of hints if returnWholeObj is falsy
88+ return returnWholeObj ? hintsObj : extractHintList ( hintsObj . hints ) ;
8889 }
8990
9091 // Ask provider for hints at current cursor position; expect it NOT to return any
@@ -664,6 +665,77 @@ define(function (require, exports, module) {
664665 } ) ;
665666 } ) ;
666667
668+ describe ( "Color names and swatches in a CSS file" , function ( ) {
669+ beforeEach ( function ( ) {
670+ setupTest ( testContentCSS , "css" ) ;
671+ } ) ;
672+
673+ afterEach ( function ( ) {
674+ tearDownTest ( ) ;
675+ } ) ;
676+
677+ it ( "should list color names for color" , function ( ) {
678+ testEditor . setCursorPos ( { line : 98 , ch : 11 } ) ; // after color
679+ var hintList = expectHints ( CSSCodeHints . cssPropHintProvider ) ;
680+ verifyAttrHints ( hintList , "aliceblue" ) ; // first hint should be aliceblue
681+ } ) ;
682+
683+ it ( "should show color swatches for background-color" , function ( ) {
684+ testEditor . setCursorPos ( { line : 99 , ch : 22 } ) ; // after background-color
685+ var hints = expectHints ( CSSCodeHints . cssPropHintProvider , undefined , true ) . hints ;
686+ expect ( hints [ 0 ] . text ( ) ) . toBe ( "aliceblue" ) ; // first hint should be aliceblue
687+ expect ( hints [ 0 ] . find ( ".color-swatch" ) . length ) . toBe ( 1 ) ;
688+ expect ( hints [ 0 ] . find ( ".color-swatch" ) . css ( "backgroundColor" ) ) . toBe ( "rgb(240, 248, 255)" ) ;
689+ } ) ;
690+
691+ it ( "should filter out color names appropriately" , function ( ) {
692+ testEditor . setCursorPos ( { line : 100 , ch : 27 } ) ; // after border-left-color
693+ var hintList = expectHints ( CSSCodeHints . cssPropHintProvider ) ;
694+ verifyAttrHints ( hintList , "deeppink" ) ; // first hint should be deeppink
695+ verifyAllValues ( hintList , [ "deeppink" , "deepskyblue" ] ) ;
696+ } ) ;
697+
698+ it ( "should always include transparent and currentColor and they should not have a swatch, but class no-swatch-margin" , function ( ) {
699+ testEditor . setCursorPos ( { line : 101 , ch : 22 } ) ; // after border-color
700+ var hints = expectHints ( CSSCodeHints . cssPropHintProvider , undefined , true ) . hints ,
701+ hintList = extractHintList ( hints ) ;
702+ verifyAttrHints ( hintList , "currentColor" ) ; // first hint should be currentColor
703+ verifyAllValues ( hintList , [ "currentColor" , "darkmagenta" , "transparent" ] ) ;
704+ expect ( hints [ 0 ] . find ( ".color-swatch" ) . length ) . toBe ( 0 ) ; // no swatch for currentColor
705+ expect ( hints [ 2 ] . find ( ".color-swatch" ) . length ) . toBe ( 0 ) ; // no swatch for transparent
706+ expect ( hints [ 0 ] . hasClass ( "no-swatch-margin" ) ) . toBeTruthy ( ) ; // no-swatch-margin applied to currentColor
707+ expect ( hints [ 2 ] . hasClass ( "no-swatch-margin" ) ) . toBeTruthy ( ) ; // no-swatch-margin applied to transparent
708+ } ) ;
709+
710+ it ( "should remove class no-swatch-margin from transparent if it's the only one in the list" , function ( ) {
711+ testEditor . setCursorPos ( { line : 103 , ch : 22 } ) ; // after color
712+ var hints = expectHints ( CSSCodeHints . cssPropHintProvider , undefined , true ) . hints ,
713+ hintList = extractHintList ( hints ) ;
714+ verifyAllValues ( hintList , [ "transparent" ] ) ;
715+ expect ( hints [ 0 ] . find ( ".color-swatch" ) . length ) . toBe ( 0 ) ; // no swatch for transparent
716+ expect ( hints [ 0 ] . hasClass ( "no-swatch-margin" ) ) . toBeFalsy ( ) ; // no-swatch-margin not applied to transparent
717+ } ) ;
718+
719+ it ( "should insert color names correctly" , function ( ) {
720+ var expectedString = " border-left-color: deeppink;" ,
721+ line = 100 ;
722+
723+ testEditor . setCursorPos ( { line : line , ch : 27 } ) ; // after border-left-color
724+ expectHints ( CSSCodeHints . cssPropHintProvider ) ;
725+ selectHint ( CSSCodeHints . cssPropHintProvider , "deeppink" ) ;
726+ expect ( testDocument . getLine ( line ) . length ) . toBe ( expectedString . length ) ;
727+ expect ( testDocument . getLine ( line ) ) . toBe ( expectedString ) ;
728+ expectCursorAt ( { line : line , ch : expectedString . length - 1 } ) ;
729+ } ) ;
730+
731+
732+ it ( "should not display color names for unrelated properties" , function ( ) {
733+ testEditor . setCursorPos ( { line : 102 , ch : 12 } ) ; // after height
734+ var hintList = expectHints ( CSSCodeHints . cssPropHintProvider ) ;
735+ expect ( hintList . indexOf ( "aliceblue" ) ) . toBe ( - 1 ) ;
736+ } ) ;
737+ } ) ;
738+
667739 describe ( "Should not invoke CSS hints on space key" , function ( ) {
668740 beforeEach ( function ( ) {
669741 setupTest ( testContentHTML , "html" ) ;
0 commit comments