Skip to content

Commit

Permalink
changes to move to new branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Kafieh committed Oct 14, 2024
1 parent 5f3db7c commit 14195ad
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 63 deletions.
16 changes: 15 additions & 1 deletion src/logic/log_note/getFill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Settings } from "../../interfaces/Settings";
import { Context } from "../../interfaces/context/Context";
import { TrackedFile } from "../../types";

export function getFill(context: Context) {
const settings = context.settings;
Expand All @@ -10,7 +12,7 @@ export function getFill(context: Context) {
const created = [];
const modified = [];
const deleted = [];
const trackedFiles = settings.trackedFiles;
const trackedFiles = getSortedTrackedFiles(settings.trackedFiles, settings);
for (const trackedFile of trackedFiles) {
if (!trackedFile.matchesCriteria || !trackedFile.path) {
continue;
Expand Down Expand Up @@ -50,3 +52,15 @@ export function getFill(context: Context) {
}
return { created, modified, deleted };
}

// todo
function getSortedTrackedFiles(
nonSorted: TrackedFile[],
settings: Settings
): TrackedFile[] {
if (!settings.sortPlaceholder) {
return nonSorted;
}

return nonSorted.sort((a, b) => a.path - b);
}
86 changes: 25 additions & 61 deletions tests/logic/log_note/getFill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,103 +282,67 @@ describe("getFill should respect sort settings", () => {
});
});

// todo way to inject mock ctime for test?
const ctimePaths = [
{
path: "a.md",
path: "ctime-10.md",
matchesCriteria: true,
supposedList: "modified",
},
{
path: "c.md",
path: "ctime-1000000000.md",
matchesCriteria: true,
supposedList: "modified",
},
{
path: "d.md",
path: "ctime-5.md",
matchesCriteria: true,
supposedList: "modified",
},
{
path: "b.md",
path: "ctime-1.md",
matchesCriteria: true,
supposedList: "modified",
},
];

it("should sort numerically for ascending ctime built-in placeholder", () => {
const settings = builder.setTrackedFiles().build();
const settings = builder
.setTrackedFiles(ctimePaths as TrackedFile[])
.setSortPlaceholder("[[ctime]]")
.build();

const context = createTestContextWithSettings(settings);

expect(getFill(context)).toEqual({

Check failure on line 316 in tests/logic/log_note/getFill.test.ts

View workflow job for this annotation

GitHub Actions / build

error: expect(received).toEqual(expected)

{ created: [], deleted: [], modified: [ + "ctime-10.md", + "ctime-1000000000.md", - "ctime-1.md", "ctime-5.md", + "ctime-1.md" - "ctime-10.md", - "ctime-1000000000.md" ], } - Expected - 3 + Received + 3 at /home/runner/work/obsidian-list-modified/obsidian-list-modified/tests/logic/log_note/getFill.test.ts:316:28
created: [],
modified: ["a.md", "b.md", "c.md", "d.md"],
modified: [
"ctime-1.md",
"ctime-5.md",
"ctime-10.md",
"ctime-1000000000.md",
],
deleted: [],
});
});

it("should sort reverse-numerically for descending ctime built-in placeholder", () => {
const settings = builder.setTrackedFiles().build();
const settings = builder
.setTrackedFiles(ctimePaths as TrackedFile[])
.setSortPlaceholder("[[ctime]]")
.setSortOrder("desc")
.build();

const context = createTestContextWithSettings(settings);

expect(getFill(context)).toEqual({

Check failure on line 337 in tests/logic/log_note/getFill.test.ts

View workflow job for this annotation

GitHub Actions / build

error: expect(received).toEqual(expected)

{ created: [], deleted: [], modified: [ + "ctime-10.md", "ctime-1000000000.md", - "ctime-10.md", "ctime-5.md", "ctime-1.md" ], } - Expected - 1 + Received + 1 at /home/runner/work/obsidian-list-modified/obsidian-list-modified/tests/logic/log_note/getFill.test.ts:337:28
created: [],
modified: ["a.md", "b.md", "c.md", "d.md"],
modified: [
"ctime-1000000000.md",
"ctime-10.md",
"ctime-5.md",
"ctime-1.md",
],
deleted: [],
});
});

it("should work with alpha frontmatter", () => {
// const settings = builder
// .setTrackedFiles(alphaPaths as TrackedFile[])
// .setSortOrder("desc")
// .build();
// const context = createTestContextWithSettings(settings);
// expect(getFill(context)).toEqual({
// created: [],
// modified: ["d.md", "c.md", "b.md", "a.md"],
// deleted: [],
// });
});

it("should work with numerical frontmatter", () => {
// const settings = builder
// .setTrackedFiles(alphaPaths as TrackedFile[])
// .setSortOrder("desc")
// .build();
// const context = createTestContextWithSettings(settings);
// expect(getFill(context)).toEqual({
// created: [],
// modified: ["d.md", "c.md", "b.md", "a.md"],
// deleted: [],
// });
});

it("should not work with boolean frontmatter", () => {
// const settings = builder
// .setTrackedFiles(alphaPaths as TrackedFile[])
// .setSortOrder("desc")
// .build();
// const context = createTestContextWithSettings(settings);
// expect(getFill(context)).toEqual({
// created: [],
// modified: ["d.md", "c.md", "b.md", "a.md"],
// deleted: [],
// });
});

it("should not work with any sort of array (tags or frontmatter)", () => {
// const settings = builder
// .setTrackedFiles(alphaPaths as TrackedFile[])
// .setSortOrder("desc")
// .build();
// const context = createTestContextWithSettings(settings);
// expect(getFill(context)).toEqual({
// created: [],
// modified: ["d.md", "c.md", "b.md", "a.md"],
// deleted: [],
// });
});
});
2 changes: 1 addition & 1 deletion tests/stubs/context/fileConverterStub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("file converter should work as expected", () => {
);
});

// improve this maybe? be able to inject this into file converter without having to re-write all the tests
// improve this maybe? need a way to inject this into file converter without having to re-write all the tests
it("should return file with ctime if special name", () => {
expect(fileConverter.fromPath("ctime-10.md")?.stat.ctime).toBe(10);
});
Expand Down

0 comments on commit 14195ad

Please sign in to comment.