@@ -34,13 +34,15 @@ import {
3434 getUpdatedData ,
3535 getValueFromRow ,
3636 getValuesSummary ,
37+ hasAmountOrUnitChanged ,
3738 isBoolean ,
3839 isImage ,
3940 isInteger ,
4041 isIntegerInRange ,
4142 isNonNegativeFloat ,
4243 isNonNegativeInteger ,
4344 isQuotedWithDelimiters ,
45+ isSameWithStringCompare ,
4446 isSetEqual ,
4547 makeCommaSeparatedString ,
4648 parseCsvString ,
@@ -474,6 +476,12 @@ describe('getUpdatedData', () => {
474476 Other : {
475477 value : null ,
476478 } ,
479+ StoredAmount : {
480+ value : 1 ,
481+ } ,
482+ Units : {
483+ value : 'mL' ,
484+ } ,
477485 } ,
478486 } ) ;
479487
@@ -512,6 +520,14 @@ describe('getUpdatedData', () => {
512520 name : 'IntValue' ,
513521 fieldKey : 'IntValue' ,
514522 } ) ,
523+ storedamount : new QueryColumn ( {
524+ name : 'StoredAmount' ,
525+ fieldKey : 'StoredAmount' ,
526+ } ) ,
527+ units : new QueryColumn ( {
528+ name : 'Units' ,
529+ fieldKey : 'Units' ,
530+ } ) ,
515531 } ) ,
516532 } ) ;
517533
@@ -560,6 +576,40 @@ describe('getUpdatedData', () => {
560576 } ) ;
561577 } ) ;
562578
579+ test ( 'changed value for amount but not units' , ( ) => {
580+ const updatedData = getUpdatedData (
581+ originalData ,
582+ {
583+ StoredAmount : 2 ,
584+ Units : 'mL' ,
585+ } ,
586+ queryInfo
587+ ) ;
588+ expect ( updatedData ) . toHaveLength ( 1 ) ;
589+ expect ( updatedData [ 0 ] ) . toStrictEqual ( {
590+ RowId : 445 ,
591+ StoredAmount : 2 ,
592+ Units : 'mL' ,
593+ } ) ;
594+ } ) ;
595+
596+ test ( 'changed value for units but not amount' , ( ) => {
597+ const updatedData = getUpdatedData (
598+ originalData ,
599+ {
600+ StoredAmount : 1 ,
601+ Units : 'uL' ,
602+ } ,
603+ queryInfo
604+ ) ;
605+ expect ( updatedData ) . toHaveLength ( 1 ) ;
606+ expect ( updatedData [ 0 ] ) . toStrictEqual ( {
607+ RowId : 445 ,
608+ StoredAmount : 1 ,
609+ Units : 'uL' ,
610+ } ) ;
611+ } ) ;
612+
563613 test ( 'changed values for all' , ( ) => {
564614 const updatedData = getUpdatedData (
565615 originalData ,
@@ -1565,3 +1615,59 @@ describe('isSetEqual', () => {
15651615 expect ( isSetEqual ( [ getDomainDetailsJSON , 1 ] , [ getDomainDetailsJSON , 1 , 2 ] ) ) . toBe ( false ) ;
15661616 } ) ;
15671617} ) ;
1618+
1619+ describe ( 'hasAmountOrUnitChanged' , ( ) => {
1620+ test ( 'updated amount' , ( ) => {
1621+ const originalRowMap = fromJS ( { StoredAmount : { value : 5 } , Units : { value : 'mg' } } ) ;
1622+ expect ( hasAmountOrUnitChanged ( Map ( { Amount : 10 , Units : 'mg' } ) , originalRowMap ) ) . toBe ( false ) ;
1623+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , Units : 'mg' } ) , originalRowMap ) ) . toBe ( false ) ;
1624+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5.1 , Units : 'mg' } ) , originalRowMap ) ) . toBe ( true ) ;
1625+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 10 , Units : 'mg' } ) , originalRowMap ) ) . toBe ( true ) ;
1626+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : null , Units : 'mg' } ) , originalRowMap ) ) . toBe ( true ) ;
1627+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : undefined , Units : 'mg' } ) , originalRowMap ) ) . toBe ( true ) ;
1628+ } ) ;
1629+
1630+ test ( 'updated unit' , ( ) => {
1631+ const originalRowMap = fromJS ( { StoredAmount : { value : 5 } , Units : { value : 'mg' } } ) ;
1632+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , RawUnits : 'mg' } ) , originalRowMap ) ) . toBe ( false ) ;
1633+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , Units : 'mg' } ) , originalRowMap ) ) . toBe ( false ) ;
1634+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , Units : 'g' } ) , originalRowMap ) ) . toBe ( true ) ;
1635+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , Units : null } ) , originalRowMap ) ) . toBe ( true ) ;
1636+ expect ( hasAmountOrUnitChanged ( Map ( { StoredAmount : 5 , Units : undefined } ) , originalRowMap ) ) . toBe ( true ) ;
1637+ } ) ;
1638+ } ) ;
1639+
1640+ describe ( 'isSameWithStringCompare' , ( ) => {
1641+ test ( 'both empty' , ( ) => {
1642+ expect ( isSameWithStringCompare ( undefined , undefined ) ) . toBe ( true ) ;
1643+ expect ( isSameWithStringCompare ( null , null ) ) . toBe ( true ) ;
1644+ expect ( isSameWithStringCompare ( '' , '' ) ) . toBe ( true ) ;
1645+ } ) ;
1646+
1647+ test ( 'one empty' , ( ) => {
1648+ expect ( isSameWithStringCompare ( undefined , 'abc' ) ) . toBe ( false ) ;
1649+ expect ( isSameWithStringCompare ( null , 123 ) ) . toBe ( false ) ;
1650+ expect ( isSameWithStringCompare ( '' , true ) ) . toBe ( false ) ;
1651+ expect ( isSameWithStringCompare ( 'abc' , undefined ) ) . toBe ( false ) ;
1652+ expect ( isSameWithStringCompare ( 123 , null ) ) . toBe ( false ) ;
1653+ expect ( isSameWithStringCompare ( true , '' ) ) . toBe ( false ) ;
1654+ } ) ;
1655+
1656+ test ( 'non-empty values' , ( ) => {
1657+ expect ( isSameWithStringCompare ( 'abc' , 'abc' ) ) . toBe ( true ) ;
1658+ expect ( isSameWithStringCompare ( 'abc ' , 'abc' ) ) . toBe ( false ) ;
1659+ expect ( isSameWithStringCompare ( 'abc' , 'ABC' ) ) . toBe ( false ) ;
1660+ expect ( isSameWithStringCompare ( ' abc' , 'abc' ) ) . toBe ( false ) ;
1661+ expect ( isSameWithStringCompare ( 'abc' , 'abcd' ) ) . toBe ( false ) ;
1662+ expect ( isSameWithStringCompare ( 'abc' , 'ab' ) ) . toBe ( false ) ;
1663+ } ) ;
1664+
1665+ test ( 'numeric values' , ( ) => {
1666+ expect ( isSameWithStringCompare ( 123 , 123 ) ) . toBe ( true ) ;
1667+ expect ( isSameWithStringCompare ( 123 , '123' ) ) . toBe ( true ) ;
1668+ expect ( isSameWithStringCompare ( 123 , ' 123' ) ) . toBe ( false ) ;
1669+ expect ( isSameWithStringCompare ( 123 , '123 ' ) ) . toBe ( false ) ;
1670+ expect ( isSameWithStringCompare ( 123 , 123.0 ) ) . toBe ( true ) ;
1671+ expect ( isSameWithStringCompare ( 123 , 123.1 ) ) . toBe ( false ) ;
1672+ } ) ;
1673+ } ) ;
0 commit comments