@@ -36,7 +36,7 @@ import {
3636 createTestSimpleContentField ,
3737 createTestStructPropertiesContentField ,
3838} from "../_helpers/Content.js" ;
39- import { createTestECInstanceKey } from "../_helpers/EC.js" ;
39+ import { createTestECInstanceKey , createTestPropertyInfo } from "../_helpers/EC.js" ;
4040
4141describe ( "ContentTraverser" , ( ) => {
4242 class TestContentVisitor implements IContentVisitor {
@@ -543,7 +543,7 @@ describe("ContentTraverser", () => {
543543 expect ( startArraySpy . firstCall . firstArg ) . to . containSubset ( {
544544 hierarchy : {
545545 field : {
546- name : primitiveField . name ,
546+ name : "" ,
547547 } ,
548548 } ,
549549 valueType : {
@@ -575,6 +575,102 @@ describe("ContentTraverser", () => {
575575 expect ( finishArraySpy ) . to . be . calledOnce ;
576576 } ) ;
577577
578+ it ( "processes array value nested under nested content item as array-of-arrays value" , ( ) => {
579+ const startArraySpy = sinon . spy ( visitor , "startArray" ) ;
580+ const finishArraySpy = sinon . spy ( visitor , "finishArray" ) ;
581+ const processPrimitiveValueSpy = sinon . spy ( visitor , "processPrimitiveValue" ) ;
582+ const nestedContentCategory = createTestCategoryDescription ( { name : "nested-content" , label : "Nested content" } ) ;
583+ const arrayItemField = createTestPropertiesContentField ( {
584+ name : "ArrayItemField" ,
585+ category : nestedContentCategory ,
586+ properties : [ { property : createTestPropertyInfo ( { name : "ArrayProperty" , type : "string" } ) } ] ,
587+ type : { valueFormat : PropertyValueFormat . Primitive , typeName : "string" } ,
588+ } ) ;
589+ const arrayField = createTestArrayPropertiesContentField ( {
590+ name : "ArrayField" ,
591+ category : nestedContentCategory ,
592+ properties : [ { property : createTestPropertyInfo ( { name : "ArrayProperty" , type : "string" } ) } ] ,
593+ type : {
594+ valueFormat : PropertyValueFormat . Array ,
595+ typeName : `${ arrayItemField . type . typeName } []` ,
596+ memberType : arrayItemField . type ,
597+ } ,
598+ itemsField : arrayItemField ,
599+ } ) ;
600+ const rootField = createTestNestedContentField ( {
601+ name : "RootField" ,
602+ category : createTestCategoryDescription ( { name : "root" , label : "Root category" } ) ,
603+ nestedFields : [ arrayField ] ,
604+ } ) ;
605+ const descriptor = createTestContentDescriptor ( { fields : [ rootField ] } ) ;
606+ const item = createTestContentItem ( {
607+ values : {
608+ [ rootField . name ] : [
609+ {
610+ primaryKeys : [ createTestECInstanceKey ( ) ] ,
611+ values : {
612+ [ arrayField . name ] : [ "value1" ] ,
613+ } ,
614+ displayValues : {
615+ [ arrayField . name ] : [ "display value 1" ] ,
616+ } ,
617+ mergedFieldNames : [ ] ,
618+ } ,
619+ ] ,
620+ } ,
621+ displayValues : {
622+ [ rootField . name ] : undefined ,
623+ } ,
624+ } ) ;
625+ const traverser = createContentTraverser ( visitor , descriptor ) ;
626+ traverser ( [ item ] ) ;
627+
628+ expect ( startArraySpy ) . to . be . calledTwice ;
629+ expect ( startArraySpy . firstCall . firstArg ) . to . containSubset ( {
630+ hierarchy : {
631+ field : {
632+ name : "" ,
633+ itemsField : {
634+ name : arrayField . name ,
635+ type : arrayField . type ,
636+ } ,
637+ type : {
638+ valueFormat : PropertyValueFormat . Array ,
639+ typeName : `${ arrayField . type . typeName } []` ,
640+ memberType : arrayField . type ,
641+ } ,
642+ } ,
643+ } ,
644+ valueType : {
645+ valueFormat : PropertyValueFormat . Array ,
646+ typeName : `${ arrayField . type . typeName } []` ,
647+ memberType : arrayField . type ,
648+ } ,
649+ parentFieldName : rootField . name ,
650+ } ) ;
651+ expect ( startArraySpy . secondCall . firstArg ) . to . containSubset ( {
652+ hierarchy : {
653+ field : {
654+ name : arrayField . name ,
655+ type : arrayField . type ,
656+ } ,
657+ } ,
658+ valueType : arrayField . type ,
659+ parentFieldName : `${ rootField . name } ` ,
660+ } ) ;
661+ expect ( processPrimitiveValueSpy ) . to . be . calledOnce ;
662+ expect ( processPrimitiveValueSpy . firstCall . firstArg ) . to . containSubset ( {
663+ field : {
664+ name : arrayItemField . name ,
665+ } ,
666+ valueType : arrayItemField . type ,
667+ parentFieldName : `${ rootField . name } ${ FIELD_NAMES_SEPARATOR } ${ arrayField . name } ` ,
668+ rawValue : "value1" ,
669+ displayValue : "display value 1" ,
670+ } ) ;
671+ expect ( finishArraySpy ) . to . be . calledTwice ;
672+ } ) ;
673+
578674 it ( "processes nested content item as struct array value" , ( ) => {
579675 const startArraySpy = sinon . spy ( visitor , "startArray" ) ;
580676 const finishArraySpy = sinon . spy ( visitor , "finishArray" ) ;
@@ -794,7 +890,7 @@ describe("ContentTraverser", () => {
794890 expect ( startArraySpy ) . to . be . calledOnce ;
795891 expect ( startArraySpy . firstCall . firstArg ) . to . containSubset ( {
796892 hierarchy : {
797- field : { name : primitiveField . name } ,
893+ field : { name : "" } ,
798894 childFields : [ ] ,
799895 } ,
800896 valueType : {
@@ -1524,15 +1620,15 @@ describe("ContentTraverser", () => {
15241620 [ childPrimitiveField . name ] : "ChildPrimitiveValue" ,
15251621 } ,
15261622 displayValues : {
1527- [ childNestedContentField . name ] : "ChildPrimitiveDisplayValue" ,
1623+ [ childPrimitiveField . name ] : "ChildPrimitiveDisplayValue" ,
15281624 } ,
15291625 mergedFieldNames : [ ] ,
15301626 } satisfies NestedContentValue ,
15311627 ] ,
15321628 } ,
15331629 displayValues : {
15341630 [ parentPrimitiveField . name ] : "ChildPrimitiveDisplayValue" ,
1535- [ childNestedContentField . name ] : "ChildNestedContentDisplayValue" ,
1631+ [ childNestedContentField . name ] : undefined ,
15361632 } ,
15371633 mergedFieldNames : [ ] ,
15381634 } satisfies NestedContentValue ,
0 commit comments