@@ -3,7 +3,7 @@ import { List, Map } from 'immutable';
33import { QueryInfo } from '../../../public/QueryInfo' ;
44import { QueryColumn , QueryLookup } from '../../../public/QueryColumn' ;
55
6- import { DATE_RANGE_URI , NON_NEGATIVE_NUMBER_CONCEPT_URI } from '../domainproperties/constants' ;
6+ import { DATE_RANGE_URI , MULTI_CHOICE_RANGE_URI , NON_NEGATIVE_NUMBER_CONCEPT_URI } from '../domainproperties/constants' ;
77
88import sampleSetQueryInfoJSON from '../../../test/data/sampleSetAllFieldTypes-getQueryDetails.json' ;
99
@@ -390,6 +390,77 @@ describe('getValidatedEditableGridValue', () => {
390390 } ) ;
391391 } ) ;
392392
393+ test ( 'multi-choice column with valid values' , ( ) => {
394+ const multiChoiceCol = new QueryColumn ( {
395+ jsonType : 'string' ,
396+ rangeURI : MULTI_CHOICE_RANGE_URI ,
397+ validValues : [ 'alpha' , 'beta' , 'gamma' ] ,
398+ } ) ;
399+
400+ const validArray = [ { display : 'alpha' } , { display : 'beta' } ] ;
401+ expect ( getValidatedEditableGridValue ( validArray , multiChoiceCol ) ) . toStrictEqual ( {
402+ message : undefined ,
403+ value : validArray ,
404+ } ) ;
405+ } ) ;
406+
407+ test ( 'multi-choice column with invalid choice' , ( ) => {
408+ const multiChoiceCol = new QueryColumn ( {
409+ jsonType : 'string' ,
410+ rangeURI : MULTI_CHOICE_RANGE_URI ,
411+ validValues : [ 'alpha' , 'beta' , 'gamma' ] ,
412+ } ) ;
413+
414+ const invalidArray = [ { display : 'alpha' } , { display : 'invalid' } ] ;
415+ expect ( getValidatedEditableGridValue ( invalidArray , multiChoiceCol ) ) . toStrictEqual ( {
416+ message : { message : "'invalid' is not a valid choice" } ,
417+ value : invalidArray ,
418+ } ) ;
419+ } ) ;
420+
421+ test ( 'multi-choice column with duplicate choice' , ( ) => {
422+ const multiChoiceCol = new QueryColumn ( {
423+ jsonType : 'string' ,
424+ rangeURI : MULTI_CHOICE_RANGE_URI ,
425+ validValues : [ 'alpha' , 'beta' , 'gamma' ] ,
426+ } ) ;
427+
428+ const invalidArray = [ { display : 'alpha' } , { display : 'alpha' } ] ;
429+ expect ( getValidatedEditableGridValue ( invalidArray , multiChoiceCol ) ) . toStrictEqual ( {
430+ message : { message : "Duplicate values not allowed: alpha." } ,
431+ value : invalidArray ,
432+ } ) ;
433+ } ) ;
434+
435+ test ( 'multi-choice column exceeding 10 items' , ( ) => {
436+ const multiChoiceCol = new QueryColumn ( {
437+ jsonType : 'string' ,
438+ rangeURI : MULTI_CHOICE_RANGE_URI ,
439+ validValues : [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' ] ,
440+ } ) ;
441+
442+ const tooMany = Array . from ( { length : 11 } , ( _ , i ) => ( { display : String . fromCharCode ( 97 + i ) } ) ) ;
443+ expect ( getValidatedEditableGridValue ( tooMany , multiChoiceCol ) ) . toStrictEqual ( {
444+ message : { message : 'Too many values. Maximum allowed is 10.' } ,
445+ value : tooMany ,
446+ } ) ;
447+ } ) ;
448+
449+ test ( 'multi-choice column with exactly 10 items is valid' , ( ) => {
450+ const values = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' ] ;
451+ const multiChoiceCol = new QueryColumn ( {
452+ jsonType : 'string' ,
453+ rangeURI : MULTI_CHOICE_RANGE_URI ,
454+ validValues : values ,
455+ } ) ;
456+
457+ const tenItems = values . map ( v => ( { display : v } ) ) ;
458+ expect ( getValidatedEditableGridValue ( tenItems , multiChoiceCol ) ) . toStrictEqual ( {
459+ message : undefined ,
460+ value : tenItems ,
461+ } ) ;
462+ } ) ;
463+
393464 test ( 'required column' , ( ) => {
394465 const requiredCol = new QueryColumn ( { jsonType : 'string' , required : true , caption : 'ReqCol' } ) ;
395466
0 commit comments