@@ -450,6 +450,66 @@ describe('Helpers Unit Tests', () => {
450450 } ) ;
451451 } ) ;
452452
453+ describe ( 'toLabel()' , ( ) => {
454+ let settings ;
455+
456+ beforeEach ( ( ) => {
457+ settings = {
458+ unit : 'btc' ,
459+ fiat : 'usd' ,
460+ exchangeRate : { usd : 0.00014503 } ,
461+ displayFiat : true ,
462+ } ;
463+ } ) ;
464+
465+ it ( 'should throw error if amount is undefined' , ( ) => {
466+ expect (
467+ helpers . toLabel . bind ( null , undefined , settings ) ,
468+ 'to throw' ,
469+ / M i s s i n g /
470+ ) ;
471+ } ) ;
472+
473+ it ( 'should throw error if amount is null' , ( ) => {
474+ expect ( helpers . toLabel . bind ( null , null , settings ) , 'to throw' , / M i s s i n g / ) ;
475+ } ) ;
476+
477+ it ( 'should throw error if amount is number' , ( ) => {
478+ expect ( helpers . toLabel . bind ( null , 0.1 , settings ) , 'to throw' , / M i s s i n g / ) ;
479+ } ) ;
480+
481+ it ( 'should throw error if amount is separated with a comma' , ( ) => {
482+ expect (
483+ helpers . toLabel . bind ( null , '0,1' , settings ) ,
484+ 'to throw' ,
485+ / M i s s i n g /
486+ ) ;
487+ } ) ;
488+
489+ it ( 'should throw error if unit is undefined' , ( ) => {
490+ expect (
491+ helpers . toLabel . bind ( null , '100' , undefined ) ,
492+ 'to throw' ,
493+ / M i s s i n g /
494+ ) ;
495+ } ) ;
496+
497+ it ( 'should be 0 for empty amount' , ( ) => {
498+ const num = helpers . toLabel ( '' , settings ) ;
499+ expect ( num , 'to match' , / 0 { 1 } [ , . ] 0 { 2 } / ) ;
500+ } ) ;
501+
502+ it ( 'should work for string input' , ( ) => {
503+ const num = helpers . toLabel ( '0.10' , settings ) ;
504+ expect ( num , 'to match' , / 6 8 9 [ , . ] 5 1 / ) ;
505+ } ) ;
506+ it ( 'should format a number value' , ( ) => {
507+ settings . displayFiat = false ;
508+ const lbl = helpers . toLabel ( '0.10' , settings ) ;
509+ expect ( lbl , 'to match' , / 0 [ , . ] 1 / ) ;
510+ } ) ;
511+ } ) ;
512+
453513 describe ( 'toCaps()' , ( ) => {
454514 it ( 'should work for undefined' , ( ) => {
455515 const caps = helpers . toCaps ( undefined ) ;
0 commit comments