11import {
22 CachedMetadata ,
33 MetadataCache ,
4- Pos ,
4+ Pos , TAbstractFile ,
55 TFile ,
66 TFolder ,
77 Vault
@@ -36,9 +36,8 @@ import {
3636 CompoundDotRomanNumberNormalizerFn
3737} from "../../custom-sort/sorting-spec-processor" ;
3838import {
39- findStarredFile_pathParam ,
40- Starred_PluginInstance
41- } from "../../utils/StarredPluginSignature" ;
39+ BookmarksPluginInterface
40+ } from "../../utils/BookmarksCorePluginSignature" ;
4241import {
4342 ObsidianIconFolder_PluginInstance ,
4443 ObsidianIconFolderPlugin_Data
@@ -937,25 +936,25 @@ describe('determineSortingGroup', () => {
937936 } as FolderItemForSorting ) ;
938937 } )
939938 } )
940- describe ( 'CustomSortGroupType.StarredOnly ' , ( ) => {
941- it ( 'should not match not starred file' , ( ) => {
939+ describe ( 'CustomSortGroupType.BookmarkedOnly ' , ( ) => {
940+ it ( 'should not match not bookmarked file' , ( ) => {
942941 // given
943942 const file : TFile = mockTFile ( 'References' , 'md' , 111 , MOCK_TIMESTAMP + 222 , MOCK_TIMESTAMP + 333 ) ;
944943 const sortSpec : CustomSortSpec = {
945944 targetFoldersPaths : [ '/' ] ,
946945 groups : [ {
947- type : CustomSortGroupType . StarredOnly
946+ type : CustomSortGroupType . BookmarkedOnly
948947 } ]
949948 }
950- const starredPluginInstance : Partial < Starred_PluginInstance > = {
951- findStarredFile : jest . fn ( function ( filePath : findStarredFile_pathParam ) : TFile | null {
952- return null
949+ const bookmarksPluginInstance : Partial < BookmarksPluginInterface > = {
950+ determineBookmarkOrder : jest . fn ( function ( path : string ) : number | undefined {
951+ return undefined
953952 } )
954953 }
955954
956955 // when
957956 const result = determineSortingGroup ( file , sortSpec , {
958- starredPluginInstance : starredPluginInstance as Starred_PluginInstance
957+ bookmarksPluginInstance : bookmarksPluginInstance as BookmarksPluginInterface
959958 } as ProcessingContext )
960959
961960 // then
@@ -968,30 +967,32 @@ describe('determineSortingGroup', () => {
968967 mtime : MOCK_TIMESTAMP + 333 ,
969968 path : 'Some parent folder/References.md'
970969 } ) ;
971- expect ( starredPluginInstance . findStarredFile ) . toHaveBeenCalledTimes ( 1 )
970+ expect ( bookmarksPluginInstance . determineBookmarkOrder ) . toHaveBeenCalledTimes ( 1 )
972971 } )
973- it ( 'should match starred file' , ( ) => {
972+ it ( 'should match bookmarked file' , ( ) => {
974973 // given
975974 const file : TFile = mockTFile ( 'References' , 'md' , 111 , MOCK_TIMESTAMP + 222 , MOCK_TIMESTAMP + 333 ) ;
976975 const sortSpec : CustomSortSpec = {
977976 targetFoldersPaths : [ '/' ] ,
978977 groups : [ {
979- type : CustomSortGroupType . StarredOnly
978+ type : CustomSortGroupType . BookmarkedOnly
980979 } ]
981980 }
982- const starredPluginInstance : Partial < Starred_PluginInstance > = {
983- findStarredFile : jest . fn ( function ( filePath : findStarredFile_pathParam ) : TFile | null {
984- return filePath . path === 'Some parent folder/References.md' ? file : null
981+ const BOOKMARK_ORDER = 123
982+ const bookmarksPluginInstance : Partial < BookmarksPluginInterface > = {
983+ determineBookmarkOrder : jest . fn ( function ( path : string ) : number | undefined {
984+ return path === 'Some parent folder/References.md' ? BOOKMARK_ORDER : undefined
985985 } )
986986 }
987987
988988 // when
989989 const result = determineSortingGroup ( file , sortSpec , {
990- starredPluginInstance : starredPluginInstance as Starred_PluginInstance
990+ bookmarksPluginInstance : bookmarksPluginInstance as BookmarksPluginInterface
991991 } as ProcessingContext )
992992
993993 // then
994994 expect ( result ) . toEqual ( {
995+ bookmarkedIdx : BOOKMARK_ORDER ,
995996 groupIdx : 0 ,
996997 isFolder : false ,
997998 sortString : "References" ,
@@ -1000,131 +1001,7 @@ describe('determineSortingGroup', () => {
10001001 mtime : MOCK_TIMESTAMP + 333 ,
10011002 path : 'Some parent folder/References.md'
10021003 } ) ;
1003- expect ( starredPluginInstance . findStarredFile ) . toHaveBeenCalledTimes ( 1 )
1004- } )
1005- it ( 'should not match empty folder' , ( ) => {
1006- // given
1007- const folder : TFolder = mockTFolder ( 'TestEmptyFolder' ) ;
1008- const sortSpec : CustomSortSpec = {
1009- targetFoldersPaths : [ '/' ] ,
1010- groups : [ {
1011- type : CustomSortGroupType . StarredOnly
1012- } ]
1013- }
1014- const starredPluginInstance : Partial < Starred_PluginInstance > = {
1015- findStarredFile : jest . fn ( function ( filePath : findStarredFile_pathParam ) : TFile | null {
1016- return filePath . path === 'Some parent folder/References.md' ? { } as TFile : null
1017- } )
1018- }
1019-
1020- // when
1021- const result = determineSortingGroup ( folder , sortSpec , {
1022- starredPluginInstance : starredPluginInstance as Starred_PluginInstance
1023- } as ProcessingContext )
1024-
1025- // then
1026- expect ( result ) . toEqual ( {
1027- groupIdx : 1 , // The lastIdx+1, group not determined
1028- isFolder : true ,
1029- sortString : "TestEmptyFolder" ,
1030- sortStringWithExt : "TestEmptyFolder" ,
1031-
1032- ctime : 0 ,
1033- mtime : 0 ,
1034- path : 'TestEmptyFolder' ,
1035- folder : {
1036- children : [ ] ,
1037- isRoot : expect . any ( Function ) ,
1038- name : "TestEmptyFolder" ,
1039- parent : { } ,
1040- path : "TestEmptyFolder" ,
1041- vault : { }
1042- }
1043- } ) ;
1044- expect ( starredPluginInstance . findStarredFile ) . not . toHaveBeenCalled ( )
1045- } )
1046- it ( 'should not match folder w/o starred items' , ( ) => {
1047- // given
1048- const folder : TFolder = mockTFolderWithChildren ( 'TestEmptyFolder' ) ;
1049- const sortSpec : CustomSortSpec = {
1050- targetFoldersPaths : [ '/' ] ,
1051- groups : [ {
1052- type : CustomSortGroupType . StarredOnly
1053- } ]
1054- }
1055- const starredPluginInstance : Partial < Starred_PluginInstance > = {
1056- findStarredFile : jest . fn ( function ( filePath : findStarredFile_pathParam ) : TFile | null {
1057- return filePath . path === 'Some parent folder/References.md' ? { } as TFile : null
1058- } )
1059- }
1060-
1061- // when
1062- const result = determineSortingGroup ( folder , sortSpec , {
1063- starredPluginInstance : starredPluginInstance as Starred_PluginInstance
1064- } as ProcessingContext )
1065-
1066- // then
1067- expect ( result ) . toEqual ( {
1068- groupIdx : 1 , // The lastIdx+1, group not determined
1069- isFolder : true ,
1070- sortString : "TestEmptyFolder" ,
1071- sortStringWithExt : "TestEmptyFolder" ,
1072-
1073- ctime : 0 ,
1074- mtime : 0 ,
1075- path : 'TestEmptyFolder' ,
1076- folder : {
1077- children : expect . any ( Array ) ,
1078- isRoot : expect . any ( Function ) ,
1079- name : "TestEmptyFolder" ,
1080- parent : { } ,
1081- path : "TestEmptyFolder" ,
1082- vault : { }
1083- }
1084- } ) ;
1085- expect ( starredPluginInstance . findStarredFile ) . toHaveBeenCalledTimes ( folder . children . filter ( f => ( f as any ) . isRoot === undefined ) . length )
1086- } )
1087- it ( 'should match folder with one starred item' , ( ) => {
1088- // given
1089- const folder : TFolder = mockTFolderWithChildren ( 'TestEmptyFolder' ) ;
1090- const sortSpec : CustomSortSpec = {
1091- targetFoldersPaths : [ '/' ] ,
1092- groups : [ {
1093- type : CustomSortGroupType . StarredOnly
1094- } ]
1095- }
1096- const starredPluginInstance : Partial < Starred_PluginInstance > = {
1097- findStarredFile : jest . fn ( function ( filePath : findStarredFile_pathParam ) : TFile | null {
1098- return filePath . path === 'Some parent folder/Child file 2 created as newest, not modified at all.md' ? { } as TFile : null
1099- } )
1100- }
1101-
1102- // when
1103- const result = determineSortingGroup ( folder , sortSpec , {
1104- starredPluginInstance : starredPluginInstance as Starred_PluginInstance
1105- } as ProcessingContext )
1106-
1107- // then
1108- expect ( result ) . toEqual ( {
1109- groupIdx : 0 ,
1110- isFolder : true ,
1111- sortString : "TestEmptyFolder" ,
1112- sortStringWithExt : "TestEmptyFolder" ,
1113-
1114- ctime : 0 ,
1115- mtime : 0 ,
1116- path : 'TestEmptyFolder' ,
1117- folder : {
1118- children : expect . any ( Array ) ,
1119- isRoot : expect . any ( Function ) ,
1120- name : "TestEmptyFolder" ,
1121- parent : { } ,
1122- path : "TestEmptyFolder" ,
1123- vault : { }
1124- }
1125- } ) ;
1126- // assume optimized checking of starred items -> first match ends the check
1127- expect ( starredPluginInstance . findStarredFile ) . toHaveBeenCalledTimes ( 2 )
1004+ expect ( bookmarksPluginInstance . determineBookmarkOrder ) . toHaveBeenCalledTimes ( 1 )
11281005 } )
11291006 } )
11301007 describe ( 'CustomSortGroupType.HasIcon' , ( ) => {
0 commit comments