@@ -33,12 +33,6 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
3333 ] ;
3434
3535 const mockMetadataTemplateFields : MetadataTemplateField [ ] = [
36- {
37- id : 'field1' ,
38- key : 'item.name' ,
39- displayName : 'Name' ,
40- type : 'string' ,
41- } ,
4236 {
4337 id : 'field2' ,
4438 key : 'industry' ,
@@ -101,6 +95,30 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
10195 minWidth : 250 ,
10296 maxWidth : 250 ,
10397 } ,
98+ {
99+ textValue : 'Contact Role' ,
100+ id : 'role' ,
101+ type : 'string' ,
102+ allowsSorting : true ,
103+ minWidth : 250 ,
104+ maxWidth : 250 ,
105+ } ,
106+ {
107+ textValue : 'Status' ,
108+ id : 'status' ,
109+ type : 'string' ,
110+ allowsSorting : true ,
111+ minWidth : 250 ,
112+ maxWidth : 250 ,
113+ } ,
114+ {
115+ textValue : 'Price' ,
116+ id : 'price' ,
117+ type : 'string' ,
118+ allowsSorting : true ,
119+ minWidth : 250 ,
120+ maxWidth : 250 ,
121+ } ,
104122 ] ,
105123 metadataTemplate : mockMetadataTemplate ,
106124 onMetadataFilter : jest . fn ( ) ,
@@ -264,9 +282,10 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
264282 actionBarProps : { initialFilterValues } ,
265283 } ) ;
266284
267- expect ( screen . getByRole ( 'button' , { name : 'All Filters 3 ' } ) ) . toBeInTheDocument ( ) ;
285+ expect ( screen . getByRole ( 'button' , { name : 'All Filters 2 ' } ) ) . toBeInTheDocument ( ) ;
268286 expect ( screen . getByRole ( 'button' , { name : / I n d u s t r y / i } ) ) . toHaveTextContent ( / \( 1 \) / ) ;
269- expect ( screen . getByRole ( 'button' , { name : / C a t e g o r y / i } ) ) . toHaveTextContent ( / \( 2 \) / ) ;
287+ // Category filter should not be present since there's no corresponding column
288+ expect ( screen . queryByRole ( 'button' , { name : / C a t e g o r y / i } ) ) . not . toBeInTheDocument ( ) ;
270289 } ) ;
271290
272291 test ( 'should handle empty metadata template fields' , ( ) => {
@@ -334,12 +353,6 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
334353 const templateWithoutOptions : MetadataTemplate = {
335354 ...mockMetadataTemplate ,
336355 fields : [
337- {
338- id : 'field1' ,
339- key : 'name' ,
340- displayName : 'File Name' ,
341- type : 'string' ,
342- } ,
343356 {
344357 id : 'field2' ,
345358 key : 'industry' ,
@@ -350,11 +363,11 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
350363 ] ,
351364 } ;
352365
353- renderComponent ( { metadataTemplate : templateWithoutOptions } ) ;
366+ renderComponent ( {
367+ metadataTemplate : templateWithoutOptions ,
368+ } ) ;
354369
355370 expect ( screen . getByRole ( 'button' , { name : 'All Filters' } ) ) . toBeInTheDocument ( ) ;
356- expect ( screen . getAllByRole ( 'button' , { name : 'Name' } ) ) . toHaveLength ( 1 ) ; // Only the one added by component
357- expect ( screen . getByRole ( 'button' , { name : 'File Name' } ) ) . toBeInTheDocument ( ) ;
358371 expect ( screen . getByRole ( 'button' , { name : 'Industry' } ) ) . toBeInTheDocument ( ) ;
359372 } ) ;
360373
@@ -546,4 +559,53 @@ describe('elements/content-explorer/MetadataViewContainer', () => {
546559 ) . not . toBeInTheDocument ( ) ;
547560 } ) ;
548561 } ) ;
562+
563+ test ( 'should filter fields based on columns provided' , ( ) => {
564+ const template : MetadataTemplate = {
565+ ...mockMetadataTemplate ,
566+ fields : [
567+ {
568+ id : 'field1' ,
569+ key : 'status' ,
570+ displayName : 'Status' ,
571+ type : 'enum' ,
572+ options : [
573+ { id : 's1' , key : 'Active' } ,
574+ { id : 's2' , key : 'Inactive' } ,
575+ ] ,
576+ } ,
577+ {
578+ id : 'field2' ,
579+ key : 'price' ,
580+ displayName : 'Price' ,
581+ type : 'float' ,
582+ } ,
583+ {
584+ id : 'field3' ,
585+ key : 'category' ,
586+ displayName : 'Category' ,
587+ type : 'multiSelect' ,
588+ options : [
589+ { id : 'c1' , key : 'tech' } ,
590+ { id : 'c2' , key : 'finance' } ,
591+ ] ,
592+ } ,
593+ ] ,
594+ } ;
595+
596+ // Only provide columns for 'status' and 'price', not 'category'
597+ renderComponent ( {
598+ metadataTemplate : template ,
599+ } ) ;
600+
601+ // Should show filters for fields that have corresponding columns
602+ expect ( screen . getByRole ( 'button' , { name : 'All Filters' } ) ) . toBeInTheDocument ( ) ;
603+ expect ( screen . getByRole ( 'button' , { name : 'Status' } ) ) . toBeInTheDocument ( ) ;
604+ expect ( screen . getByRole ( 'button' , { name : 'Price' } ) ) . toBeInTheDocument ( ) ;
605+
606+ // Should NOT show filter for 'category' since there's no corresponding column
607+ expect ( screen . queryByRole ( 'button' , { name : 'Category' } ) ) . not . toBeInTheDocument ( ) ;
608+ // Should NOT show filter for 'industry' since it's not in the provided columns
609+ expect ( screen . queryByRole ( 'button' , { name : 'Industry' } ) ) . not . toBeInTheDocument ( ) ;
610+ } ) ;
549611} ) ;
0 commit comments