@@ -352,6 +352,91 @@ describe('initialize', () => {
352352 expect ( hydrateAuthenticatedUser ) . not . toHaveBeenCalled ( ) ;
353353 expect ( logError ) . not . toHaveBeenCalled ( ) ;
354354 } ) ;
355+
356+ it ( 'should not set any color' , async ( ) => {
357+ const messages = { i_am : 'a message' } ;
358+ await initialize ( {
359+ messages,
360+ } ) ;
361+
362+ // eslint-disable-next-line no-underscore-dangle
363+ expect ( document . documentElement . style . _values ) . toEqual ( { } ) ;
364+ expect ( logError ) . not . toHaveBeenCalled ( ) ;
365+ } ) ;
366+
367+ it ( 'should set primary color and calculate its levels' , async ( ) => {
368+ config . CUSTOM_PRIMARY_COLORS = { 'pgn-color-primary-base' : '#A000000' } ;
369+ const messages = { i_am : 'a message' } ;
370+ const expectedKeys = [
371+ '--pgn-color-primary-base' ,
372+ '--pgn-color-primary-100' ,
373+ '--pgn-color-primary-200' ,
374+ '--pgn-color-primary-300' ,
375+ '--pgn-color-primary-400' ,
376+ '--pgn-color-primary-500' ,
377+ '--pgn-color-primary-600' ,
378+ '--pgn-color-primary-700' ,
379+ '--pgn-color-primary-800' ,
380+ '--pgn-color-primary-900' ,
381+ '--pgn-color-link-base' ,
382+ '--pgn-color-link-hover' ,
383+ ] ;
384+
385+ await initialize ( {
386+ messages,
387+ } ) ;
388+
389+ // eslint-disable-next-line no-underscore-dangle
390+ expect ( Object . keys ( document . documentElement . style . _values ) ) . toEqual ( expectedKeys ) ;
391+ expect ( logError ) . not . toHaveBeenCalled ( ) ;
392+ } ) ;
393+
394+ it ( 'should set primary color and its levels from config' , async ( ) => {
395+ config . CUSTOM_PRIMARY_COLORS = {
396+ 'pgn-color-primary-base' : '#A000000' ,
397+ 'pgn-color-primary-100' : '#A001000' ,
398+ 'pgn-color-primary-200' : '#A000000' ,
399+ 'pgn-color-primary-300' : '#A045000' ,
400+ 'pgn-color-primary-400' : '#A07AB00' ,
401+ 'pgn-color-primary-500' : '#A000B12' ,
402+ 'pgn-color-primary-600' : '#A087400' ,
403+ 'pgn-color-primary-700' : '#A0abc00' ,
404+ 'pgn-color-primary-800' : '#AABCFA0' ,
405+ 'pgn-color-primary-900' : '#A014200' ,
406+ 'pgn-color-link-base' : '#FF0056' ,
407+ 'pgn-color-link-hover' : '#AFFCDA' ,
408+ } ;
409+ const messages = { i_am : 'a message' } ;
410+
411+ await initialize ( {
412+ messages,
413+ } ) ;
414+
415+ // eslint-disable-next-line no-underscore-dangle
416+ expect ( Object . values ( document . documentElement . style . _values ) ) . toEqual ( Object . values ( config . CUSTOM_PRIMARY_COLORS ) ) ;
417+ expect ( logError ) . not . toHaveBeenCalled ( ) ;
418+ } ) ;
419+ it ( 'should log error when color is invalid' , async ( ) => {
420+ // eslint-disable-next-line no-console
421+ console . error = jest . fn ( ) ;
422+ configureCache . mockReturnValueOnce ( Promise . resolve ( {
423+ get : ( url ) => {
424+ const params = new URL ( url ) . search ;
425+ const mfe = new URLSearchParams ( params ) . get ( 'mfe' ) ;
426+ return ( { data : { ...newConfig . common , ...newConfig [ mfe ] } } ) ;
427+ } ,
428+ } ) ) ;
429+ config . CUSTOM_PRIMARY_COLORS = { 'pgn-color-primary-base' : '#AB' } ;
430+ const messages = { i_am : 'a message' } ;
431+
432+ await initialize ( {
433+ messages,
434+ } ) ;
435+
436+ // eslint-disable-next-line no-console
437+ expect ( console . error ) . toHaveBeenNthCalledWith ( 9 , 'Error setting custom colors' , 'Parameter color does not have format #RRGGBB' ) ;
438+ expect ( logError ) . not . toHaveBeenCalled ( ) ;
439+ } ) ;
355440} ) ;
356441
357442describe ( 'history' , ( ) => {
0 commit comments