@@ -540,3 +540,95 @@ describe('helpers/folders', () => {
540540 } )
541541 } )
542542} )
543+
544+ describe ( 'Folder View Helper Functions' , ( ) => {
545+ const mockFolderYaml = {
546+ views : [
547+ '{"dataLevel":"tasks","folderPath":"@Searches","group_by":"note path","group_sort":"ASC","layout":"cards","name":"Search Cards","sort":{"direction":"ASC","field":"line number"}}' ,
548+ '{"dataLevel":"tasks","folderPath":"@Searches","group_by":"note path","group_sort":"ASC","isSelected":true,"layout":"list","name":"Search List","sort":{"direction":"ASC","field":"line number"}}' ,
549+ '{"dataLevel":"notes","fields":["date"],"folderPath":"@Saved Searches","group_by":"note path","group_sort":"ASC","isSelected":true,"layout":"list","name":"View","sort":{"direction":"ASC","field":"line number"}}' ,
550+ '{"dataLevel":"notes","fields":["dateEdited"],"fixedGroups":{},"folderPath":"CTI","group_by":"folder","group_sort":"ASC","isSelected":true,"layout":"cards","name":"View"}' ,
551+ '{"dataLevel":"notes","fields":["dateEdited"],"folderPath":"Work","group_by":"folder","group_sort":"ASC","isSelected":true,"layout":"list","name":"Work View"}' ,
552+ '{"dataLevel":"notes","fields":["dateEdited"],"folderPath":"Daily","group_by":"folder","group_sort":"ASC","isSelected":true,"layout":"list","name":"Daily View"}'
553+ ]
554+ }
555+
556+ describe ( 'organizeFolderViews' , ( ) => {
557+ it ( 'should organize folder views correctly' , ( ) => {
558+ const result = f . organizeFolderViews ( mockFolderYaml )
559+
560+ expect ( result ) . toHaveProperty ( '@Searches' )
561+ expect ( result ) . toHaveProperty ( 'Work' )
562+ expect ( result ) . toHaveProperty ( 'Daily' )
563+
564+ // Should not include folders with only default "View" names
565+ expect ( result ) . not . toHaveProperty ( '@Saved Searches' )
566+ expect ( result ) . not . toHaveProperty ( 'CTI' )
567+
568+ // Check that named views are properly parsed
569+ expect ( result [ '@Searches' ] ) . toHaveLength ( 2 )
570+ expect ( result [ '@Searches' ] [ 0 ] . name ) . toBe ( 'Search Cards' )
571+ expect ( result [ '@Searches' ] [ 1 ] . name ) . toBe ( 'Search List' )
572+
573+ expect ( result [ 'Work' ] ) . toHaveLength ( 1 )
574+ expect ( result [ 'Work' ] [ 0 ] . name ) . toBe ( 'Work View' )
575+ } )
576+ } )
577+
578+ describe ( 'getFoldersWithNamedViews' , ( ) => {
579+ it ( 'should return list of folders with named views' , ( ) => {
580+ const result = f . getFoldersWithNamedViews ( mockFolderYaml )
581+
582+ expect ( result ) . toContain ( '@Searches' )
583+ expect ( result ) . toContain ( 'Work' )
584+ expect ( result ) . toContain ( 'Daily' )
585+ expect ( result ) . not . toContain ( '@Saved Searches' )
586+ expect ( result ) . not . toContain ( 'CTI' )
587+ } )
588+ } )
589+
590+ describe ( 'getNamedViewsForFolder' , ( ) => {
591+ it ( 'should return named views for a specific folder' , ( ) => {
592+ const result = f . getNamedViewsForFolder ( mockFolderYaml , '@Searches' )
593+
594+ expect ( result ) . toHaveLength ( 2 )
595+ expect ( result [ 0 ] . name ) . toBe ( 'Search Cards' )
596+ expect ( result [ 0 ] . layout ) . toBe ( 'cards' )
597+ expect ( result [ 1 ] . name ) . toBe ( 'Search List' )
598+ expect ( result [ 1 ] . layout ) . toBe ( 'list' )
599+ } )
600+
601+ it ( 'should return empty array for folder with no named views' , ( ) => {
602+ const result = f . getNamedViewsForFolder ( mockFolderYaml , 'CTI' )
603+ expect ( result ) . toHaveLength ( 0 )
604+ } )
605+ } )
606+
607+ describe ( 'getNamedView' , ( ) => {
608+ it ( 'should return specific named view' , ( ) => {
609+ const result = f . getNamedView ( mockFolderYaml , '@Searches' , 'Search Cards' )
610+
611+ expect ( result ) . toBeTruthy ( )
612+ expect ( result . name ) . toBe ( 'Search Cards' )
613+ expect ( result . layout ) . toBe ( 'cards' )
614+ expect ( result . dataLevel ) . toBe ( 'tasks' )
615+ } )
616+
617+ it ( 'should return null for non-existent view' , ( ) => {
618+ const result = f . getNamedView ( mockFolderYaml , '@Searches' , 'Non Existent' )
619+ expect ( result ) . toBeNull ( )
620+ } )
621+ } )
622+
623+ describe ( 'getNamedViewsByDataLevel' , ( ) => {
624+ it ( 'should organize views by data level' , ( ) => {
625+ const result = f . getNamedViewsByDataLevel ( mockFolderYaml )
626+
627+ expect ( result ) . toHaveProperty ( 'tasks' )
628+ expect ( result ) . toHaveProperty ( 'notes' )
629+
630+ expect ( result . tasks ) . toHaveLength ( 2 ) // Search Cards and Search List
631+ expect ( result . notes ) . toHaveLength ( 2 ) // Work View and Daily View
632+ } )
633+ } )
634+ } )
0 commit comments