forked from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#184 - Sort notes in Mmm-dd-yyyy format
- Loading branch information
1 parent
008f6c0
commit a0bd47b
Showing
6 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
TAbstractFile, | ||
TFolder, | ||
Vault | ||
} from "obsidian"; | ||
import { | ||
DEFAULT_FOLDER_CTIME, | ||
determineFolderDatesIfNeeded, | ||
determineSortingGroup, | ||
FolderItemForSorting, OS_alphabetical, OS_byCreatedTime, ProcessingContext, sortFolderItems | ||
} from "../../custom-sort/custom-sort"; | ||
import { | ||
CustomSortGroupType, | ||
CustomSortOrder, | ||
CustomSortSpec | ||
} from "../../custom-sort/custom-sort-types"; | ||
import { | ||
TIMESTAMP_OLDEST, | ||
TIMESTAMP_NEWEST, | ||
mockTFolderWithChildren, | ||
mockTFolderWithDateNamedChildren, | ||
TIMESTAMP_DEEP_NEWEST, | ||
TIMESTAMP_DEEP_OLDEST, | ||
} from "../mocks"; | ||
import { | ||
SortingSpecProcessor | ||
} from "../../custom-sort/sorting-spec-processor"; | ||
|
||
describe('sortFolderItems', () => { | ||
it('should correctly handle Mmm-dd-yyyy pattern in file names', () => { | ||
// given | ||
const processor: SortingSpecProcessor = new SortingSpecProcessor() | ||
const sortSpecTxt = | ||
` ... \\[Mmm-dd-yyyy] | ||
> a-z | ||
` | ||
const PARENT_PATH = 'parent/folder/path' | ||
const sortSpecsCollection = processor.parseSortSpecFromText( | ||
sortSpecTxt.split('\n'), | ||
PARENT_PATH, | ||
'file name with the sorting, irrelevant here' | ||
) | ||
|
||
const folder: TFolder = mockTFolderWithDateNamedChildren(PARENT_PATH) | ||
const sortSpec: CustomSortSpec = sortSpecsCollection?.sortSpecByPath![PARENT_PATH]! | ||
|
||
const ctx: ProcessingContext = {} | ||
|
||
// when | ||
const result: Array<TAbstractFile> = sortFolderItems(folder, folder.children, sortSpec, ctx, OS_alphabetical) | ||
|
||
// then | ||
const orderedNames = result.map(f => f.name) | ||
expect(orderedNames).toEqual([ | ||
'CCC Feb-28-2025', | ||
'BBB Dec-23-2024.md', | ||
'DDD Jul-15-2024.md', | ||
'AAA Jan-01-2012' | ||
]) | ||
}) | ||
}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters